Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* develop: only Set::values() needs to be declared internal expose a seeder fix typo
- Loading branch information
Showing
6 changed files
with
92 additions
and
4 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,31 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Innmind\BlackBox\PHPUnit; | ||
|
||
use Innmind\BlackBox\{ | ||
Set, | ||
Random, | ||
}; | ||
|
||
final class Seeder | ||
{ | ||
private Random $random; | ||
|
||
public function __construct(Random $random) | ||
{ | ||
$this->random = $random; | ||
} | ||
|
||
/** | ||
* @template T | ||
* | ||
* @param Set<T> $set | ||
* | ||
* @return T | ||
*/ | ||
public function __invoke(Set $set) | ||
{ | ||
return $set->values($this->random)->current()->unwrap(); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace Tests\Innmind\BlackBox\PHPUnit; | ||
|
||
use Innmind\BlackBox\{ | ||
PHPUnit\Seeder, | ||
Random\RandomInt, | ||
}; | ||
use PHPUnit\Framework\TestCase; | ||
use Innmind\BlackBox\{ | ||
PHPUnit\BlackBox, | ||
Set, | ||
}; | ||
|
||
class SeederTest extends TestCase | ||
{ | ||
use BlackBox; | ||
|
||
public function testAlwaysReturnADifferentValue() | ||
{ | ||
$this | ||
->forAll(Set\Elements::of( | ||
Set\Chars::any(), | ||
Set\Email::any(), | ||
Set\Strings::any(), | ||
Set\UnsafeStrings::any(), | ||
Set\Uuid::any(), | ||
)) | ||
->then(function($set) { | ||
$seeder = new Seeder(new RandomInt); | ||
|
||
$this->assertIsString($seeder($set)); | ||
$this->assertNotSame( | ||
$seeder($set), | ||
$seeder($set), | ||
); | ||
}); | ||
} | ||
} |