Skip to content

Commit

Permalink
Add tests to ensure the decorators handle dynamic names (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Dec 10, 2022
1 parent 31903e8 commit b3d0bb5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 3 deletions.
2 changes: 1 addition & 1 deletion e2e/expected-output-osx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CpuInfoFinder: F
DummyCpuCoreFinder(value=1): .
HwLogicalFinder: .
HwPhysicalFinder: .
LinuxyNProcessorFinder: .
_NProcessorFinder: .
NProcessorFinder: .
NProcFinder(all=true): F
NProcFinder(all=false): F
Expand Down
2 changes: 1 addition & 1 deletion e2e/expected-output-ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CpuInfoFinder: .
DummyCpuCoreFinder(value=1): .
HwLogicalFinder: F
HwPhysicalFinder: F
LinuxyNProcessorFinder: .
_NProcessorFinder: .
NProcessorFinder: F
NProcFinder(all=true): .
NProcFinder(all=false): .
Expand Down
2 changes: 1 addition & 1 deletion e2e/expected-output-windows
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions tests/Finder/DynamicNameFinder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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 DomainException;
use Fidry\CpuCoreCounter\Finder\CpuCoreFinder;
use UnexpectedValueException;

final class DynamicNameFinder implements CpuCoreFinder
{
/**
* @var iterable<string>
*/
private $names;

/**
* @param iterable<string> $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.');
}
}
8 changes: 8 additions & 0 deletions tests/Finder/OnlyOnWindowsFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
8 changes: 8 additions & 0 deletions tests/Finder/SkipOnWindowsFinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit b3d0bb5

Please sign in to comment.