Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the dummy core finder from the test to the source directory #51

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@

declare(strict_types=1);

namespace Fidry\CpuCoreCounter\Test\Finder;

use Fidry\CpuCoreCounter\Finder\CpuCoreFinder;
namespace Fidry\CpuCoreCounter\Finder;

/**
* This finder returns whatever value you gave to it. This is useful for testing
* or as a fallback to avoid to catch the NumberOfCpuCoreNotFound exception.
*/
final class DummyCpuCoreFinder implements CpuCoreFinder
{
/**
* @var int|null
* @var positive-int
*/
private $count;

public function __construct(?int $count)
/**
* @param positive-int $count
*/
public function __construct(int $count)
{
$this->count = $count;
}
Expand Down
25 changes: 25 additions & 0 deletions src/Finder/NullCpuCoreFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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;

/**
* This finder returns whatever value you gave to it. This is useful for testing.
*/
final class NullCpuCoreFinder implements CpuCoreFinder
{
public function find(): ?int
{
return null;
}
}
9 changes: 5 additions & 4 deletions tests/CpuCoreCounterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
use Exception;
use Fidry\CpuCoreCounter\CpuCoreCounter;
use Fidry\CpuCoreCounter\Finder\CpuCoreFinder;
use Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder;
use Fidry\CpuCoreCounter\Finder\NullCpuCoreFinder;
use Fidry\CpuCoreCounter\NumberOfCpuCoreNotFound;
use Fidry\CpuCoreCounter\Test\Finder\DummyCpuCoreFinder;
use PHPUnit\Framework\TestCase;
use function get_class;
use function is_array;
Expand Down Expand Up @@ -117,7 +118,7 @@ public static function cpuCoreFinderProvider(): iterable

yield 'single finder does not find a value' => [
[
new DummyCpuCoreFinder(null),
new NullCpuCoreFinder(),
],
$defaultException,
];
Expand All @@ -140,9 +141,9 @@ public static function cpuCoreFinderProvider(): iterable

return [
[
new DummyCpuCoreFinder(null),
new NullCpuCoreFinder(),
$finder,
new DummyCpuCoreFinder(null),
new NullCpuCoreFinder(),
new DummyCpuCoreFinder(11),
],
[$finder, 7],
Expand Down
32 changes: 32 additions & 0 deletions tests/Finder/DummyCpuCoreFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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\DummyCpuCoreFinder;
use PHPUnit\Framework\TestCase;

/**
* @covers \Fidry\CpuCoreCounter\Finder\DummyCpuCoreFinder
*
* @internal
*/
final class DummyCpuCoreFinderTest extends TestCase
{
public function test_it_returns_the_number_of_cores_given(): void
{
$finder = new DummyCpuCoreFinder(5);

self::assertSame(5, $finder->find());
}
}
32 changes: 32 additions & 0 deletions tests/Finder/NullCpuCoreFinderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?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\NullCpuCoreFinder;
use PHPUnit\Framework\TestCase;

/**
* @covers \Fidry\CpuCoreCounter\Finder\NullCpuCoreFinder
*
* @internal
*/
final class NullCpuCoreFinderTest extends TestCase
{
public function test_it_returns_null(): void
{
$finder = new NullCpuCoreFinder();

self::assertNull($finder->find());
}
}