diff --git a/src/CpuCoreCounter.php b/src/CpuCoreCounter.php index e6fda98..e529919 100644 --- a/src/CpuCoreCounter.php +++ b/src/CpuCoreCounter.php @@ -17,7 +17,7 @@ use Fidry\CpuCoreCounter\Finder\CpuInfoFinder; use Fidry\CpuCoreCounter\Finder\HwLogicalFinder; use Fidry\CpuCoreCounter\Finder\NProcFinder; -use Fidry\CpuCoreCounter\Finder\WindowsWmicFinder; +use Fidry\CpuCoreCounter\Finder\WindowsWmicLogicalFinder; final class CpuCoreCounter { @@ -97,7 +97,7 @@ public static function getDefaultFinders(): array { return [ new NProcFinder(), - new WindowsWmicFinder(), + new WindowsWmicLogicalFinder(), new HwLogicalFinder(), new CpuInfoFinder(), ]; diff --git a/src/Finder/WindowsWmicFinder.php b/src/Finder/WindowsWmicLogicalFinder.php similarity index 89% rename from src/Finder/WindowsWmicFinder.php rename to src/Finder/WindowsWmicLogicalFinder.php index 916d075..5a56485 100644 --- a/src/Finder/WindowsWmicFinder.php +++ b/src/Finder/WindowsWmicLogicalFinder.php @@ -16,11 +16,11 @@ use function defined; /** - * Find the number of CPU cores for Windows. + * Find the number of logical CPU cores for Windows. * * @see https://github.com/paratestphp/paratest/blob/c163539818fd96308ca8dc60f46088461e366ed4/src/Runners/PHPUnit/Options.php#L912-L916 */ -final class WindowsWmicFinder extends PopenBasedFinder +final class WindowsWmicLogicalFinder extends PopenBasedFinder { /** * @return positive-int|null diff --git a/src/Finder/WindowsWmicPhysicalFinder.php b/src/Finder/WindowsWmicPhysicalFinder.php new file mode 100644 index 0000000..78c947b --- /dev/null +++ b/src/Finder/WindowsWmicPhysicalFinder.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Fidry\CpuCoreCounter\Finder; + +use function defined; + +/** + * Find the number of physical CPU cores for Windows. + * + * @see https://github.com/paratestphp/paratest/blob/c163539818fd96308ca8dc60f46088461e366ed4/src/Runners/PHPUnit/Options.php#L912-L916 + */ +final class WindowsWmicPhysicalFinder extends PopenBasedFinder +{ + /** + * @return positive-int|null + */ + public function find(): ?int + { + if (!defined('PHP_WINDOWS_VERSION_MAJOR')) { + // Skip if not on Windows. Rely on PHP to detect the platform + // rather than reading the platform name or others. + return null; + } + + return parent::find(); + } + + protected function getCommand(): string + { + return 'wmic cpu get NumberOfProcessors'; + } +} diff --git a/tests/Finder/WindowsWmicTest.php b/tests/Finder/WindowsWmicLogicalFinderTest.php similarity index 65% rename from tests/Finder/WindowsWmicTest.php rename to tests/Finder/WindowsWmicLogicalFinderTest.php index be5d832..8ef8235 100644 --- a/tests/Finder/WindowsWmicTest.php +++ b/tests/Finder/WindowsWmicLogicalFinderTest.php @@ -14,17 +14,17 @@ namespace Fidry\CpuCoreCounter\Test\Finder; use Fidry\CpuCoreCounter\Finder\PopenBasedFinder; -use Fidry\CpuCoreCounter\Finder\WindowsWmicFinder; +use Fidry\CpuCoreCounter\Finder\WindowsWmicLogicalFinder; /** - * @covers \Fidry\CpuCoreCounter\Finder\WindowsWmicFinder + * @covers \Fidry\CpuCoreCounter\Finder\WindowsWmicLogicalFinder * * @internal */ -final class WindowsWmicTest extends PopenBasedFinderTestCase +final class WindowsWmicLogicalFinderTest extends PopenBasedFinderTestCase { protected function getFinder(): PopenBasedFinder { - return new WindowsWmicFinder(); + return new WindowsWmicLogicalFinder(); } } diff --git a/tests/Finder/WindowsWmicPhysicalFinderTest.php b/tests/Finder/WindowsWmicPhysicalFinderTest.php new file mode 100644 index 0000000..dfa2f19 --- /dev/null +++ b/tests/Finder/WindowsWmicPhysicalFinderTest.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Fidry\CpuCoreCounter\Test\Finder; + +use Fidry\CpuCoreCounter\Finder\PopenBasedFinder; +use Fidry\CpuCoreCounter\Finder\WindowsWmicPhysicalFinder; + +/** + * @covers \Fidry\CpuCoreCounter\Finder\WindowsWmicPhysicalFinder + * + * @internal + */ +final class WindowsWmicPhysicalFinderTest extends PopenBasedFinderTestCase +{ + protected function getFinder(): PopenBasedFinder + { + return new WindowsWmicPhysicalFinder(); + } +}