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.
test: Introduce a value object to make it easier to write test cases (#…
…138)
- Loading branch information
Showing
2 changed files
with
245 additions
and
224 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?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; | ||
|
||
use Fidry\CpuCoreCounter\Finder\CpuCoreFinder; | ||
use Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder; | ||
|
||
/** | ||
* @internal | ||
* @readonly | ||
*/ | ||
final class AvailableCpuCoresScenario | ||
{ | ||
/** @var list<CpuCoreFinder> */ | ||
public $finders; | ||
/** @var array<string, string|null> */ | ||
public $environmentVariables; | ||
/** @var positive-int|0 */ | ||
public $reservedCpus; | ||
/** @var positive-int */ | ||
public $limit; | ||
/** @var float|null */ | ||
public $loadLimitPerCore; | ||
/** @var float|null */ | ||
public $systemLoadAverage; | ||
/** @var positive-int */ | ||
public $expected; | ||
|
||
/** | ||
* @param list<CpuCoreFinder> $finders | ||
* @param array<string, string|int|null> $environmentVariables | ||
* @param positive-int|0 $reservedCpus | ||
* @param positive-int $limit | ||
* @param positive-int $expected | ||
*/ | ||
public function __construct( | ||
array $finders, | ||
array $environmentVariables, | ||
int $reservedCpus, | ||
?int $limit, | ||
?float $loadLimitPerCore, | ||
?float $systemLoadAverage, | ||
int $expected | ||
) { | ||
$this->finders = $finders; | ||
$this->environmentVariables = $environmentVariables; | ||
$this->reservedCpus = $reservedCpus; | ||
$this->limit = $limit; | ||
$this->loadLimitPerCore = $loadLimitPerCore; | ||
$this->systemLoadAverage = $systemLoadAverage; | ||
$this->expected = $expected; | ||
} | ||
|
||
/** | ||
* @param positive-int|null $coresCountFound | ||
* @param array<string, string|int|null> $environmentVariables | ||
* @param positive-int|0 $reservedCpus | ||
* @param positive-int $limit | ||
* @param positive-int $expected | ||
* | ||
* @return array{self} | ||
*/ | ||
public static function create( | ||
?int $coresCountFound, | ||
array $environmentVariables, | ||
?int $reservedCpus, | ||
?int $limit, | ||
?float $loadLimitPerCore, | ||
?float $systemLoadAverage, | ||
int $expected | ||
): array { | ||
$finders = null === $coresCountFound | ||
? [] | ||
: [new DummyCpuCoreFinder($coresCountFound)]; | ||
|
||
return [ | ||
new self( | ||
$finders, | ||
$environmentVariables, | ||
$reservedCpus ?? 0, | ||
$limit, | ||
$loadLimitPerCore, | ||
$systemLoadAverage ?? 0., | ||
$expected | ||
), | ||
]; | ||
} | ||
} |
Oops, something went wrong.