Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| LimitedOptionsFaker | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| fakeFor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Faker\Fakers; |
| 3 | |
| 4 | use Apie\Core\ValueObjects\Interfaces\LimitedOptionsInterface; |
| 5 | use Apie\Faker\Interfaces\ApieClassFaker; |
| 6 | use Faker\Generator; |
| 7 | use ReflectionClass; |
| 8 | |
| 9 | /** @implements ApieClassFaker<LimitedOptionsInterface> */ |
| 10 | class LimitedOptionsFaker implements ApieClassFaker |
| 11 | { |
| 12 | public function supports(ReflectionClass $class): bool |
| 13 | { |
| 14 | if (in_array(LimitedOptionsInterface::class, $class->getInterfaceNames())) { |
| 15 | $options = $class->getMethod('getOptions')->invoke(null)->toArray(); |
| 16 | return !empty($options); |
| 17 | } |
| 18 | |
| 19 | return false; |
| 20 | } |
| 21 | |
| 22 | public function fakeFor(Generator $generator, ReflectionClass $class): object |
| 23 | { |
| 24 | $options = $class->getMethod('getOptions')->invoke(null)->toArray(); |
| 25 | return $class->getMethod('fromNative')->invoke(null, $generator->randomElement($options)); |
| 26 | } |
| 27 | } |