generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a way to get the logical and physical number of cores for Windows (…
…#52)
- Loading branch information
Showing
5 changed files
with
81 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry CPUCounter Config package. | ||
* | ||
* (c) Théo FIDRY <[email protected]> | ||
* | ||
* 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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry CPUCounter Config package. | ||
* | ||
* (c) Théo FIDRY <[email protected]> | ||
* | ||
* 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(); | ||
} | ||
} |