From b3d0bb54b83e93b5faf679ba688837d55017ba95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sat, 10 Dec 2022 13:06:25 +0100 Subject: [PATCH] Add tests to ensure the decorators handle dynamic names (#80) --- e2e/expected-output-osx | 2 +- e2e/expected-output-ubuntu | 2 +- e2e/expected-output-windows | 2 +- tests/Finder/DynamicNameFinder.php | 53 ++++++++++++++++++++++++ tests/Finder/OnlyOnWindowsFinderTest.php | 8 ++++ tests/Finder/SkipOnWindowsFinderTest.php | 8 ++++ 6 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 tests/Finder/DynamicNameFinder.php diff --git a/e2e/expected-output-osx b/e2e/expected-output-osx index dcbd080..f33e466 100644 --- a/e2e/expected-output-osx +++ b/e2e/expected-output-osx @@ -2,7 +2,7 @@ CpuInfoFinder: F DummyCpuCoreFinder(value=1): . HwLogicalFinder: . HwPhysicalFinder: . -LinuxyNProcessorFinder: . +_NProcessorFinder: . NProcessorFinder: . NProcFinder(all=true): F NProcFinder(all=false): F diff --git a/e2e/expected-output-ubuntu b/e2e/expected-output-ubuntu index 20f4ec7..d4f6ce3 100644 --- a/e2e/expected-output-ubuntu +++ b/e2e/expected-output-ubuntu @@ -2,7 +2,7 @@ CpuInfoFinder: . DummyCpuCoreFinder(value=1): . HwLogicalFinder: F HwPhysicalFinder: F -LinuxyNProcessorFinder: . +_NProcessorFinder: . NProcessorFinder: F NProcFinder(all=true): . NProcFinder(all=false): . diff --git a/e2e/expected-output-windows b/e2e/expected-output-windows index 2d18714..6118f6a 100644 --- a/e2e/expected-output-windows +++ b/e2e/expected-output-windows @@ -2,7 +2,7 @@ CpuInfoFinder: F DummyCpuCoreFinder(value=1): . HwLogicalFinder: F HwPhysicalFinder: F -LinuxyNProcessorFinder: . +_NProcessorFinder: . NProcessorFinder: F NProcFinder(all=true): F NProcFinder(all=false): F diff --git a/tests/Finder/DynamicNameFinder.php b/tests/Finder/DynamicNameFinder.php new file mode 100644 index 0000000..bf7826a --- /dev/null +++ b/tests/Finder/DynamicNameFinder.php @@ -0,0 +1,53 @@ + + * + * 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 DomainException; +use Fidry\CpuCoreCounter\Finder\CpuCoreFinder; +use UnexpectedValueException; + +final class DynamicNameFinder implements CpuCoreFinder +{ + /** + * @var iterable + */ + private $names; + + /** + * @param iterable $names + */ + public function __construct(iterable $names) + { + $this->names = $names; + } + + public function diagnose(): string + { + throw new DomainException('Not implemented.'); + } + + public function find(): ?int + { + throw new DomainException('Not implemented.'); + } + + public function toString(): string + { + foreach ($this->names as $name) { + return $name; + } + + throw new UnexpectedValueException('No name found.'); + } +} diff --git a/tests/Finder/OnlyOnWindowsFinderTest.php b/tests/Finder/OnlyOnWindowsFinderTest.php index b8130fb..4b39bf1 100644 --- a/tests/Finder/OnlyOnWindowsFinderTest.php +++ b/tests/Finder/OnlyOnWindowsFinderTest.php @@ -94,4 +94,12 @@ public function test_it_does_not_skip_its_execution_when_not_on_windows(): void self::assertSame(1, $finder->find()); } + + public function it_handles_finders_with_dynamic_names(): void + { + $finder = new OnlyOnWindowsFinder(new DynamicNameFinder(['F1', 'F2'])); + + self::assertSame('OnlyOnWindowsFinder(F1)', $finder->toString()); + self::assertSame('OnlyOnWindowsFinder(F2)', $finder->toString()); + } } diff --git a/tests/Finder/SkipOnWindowsFinderTest.php b/tests/Finder/SkipOnWindowsFinderTest.php index f9053b3..0072e76 100644 --- a/tests/Finder/SkipOnWindowsFinderTest.php +++ b/tests/Finder/SkipOnWindowsFinderTest.php @@ -88,4 +88,12 @@ public function test_it_does_not_skip_its_execution_when_not_on_windows(): void self::assertSame(1, $finder->find()); } + + public function it_handles_finders_with_dynamic_names(): void + { + $finder = new SkipOnWindowsFinder(new DynamicNameFinder(['F1', 'F2'])); + + self::assertSame('SkipOnWindowsFinder(F1)', $finder->toString()); + self::assertSame('SkipOnWindowsFinder(F2)', $finder->toString()); + } }