|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * For the full copyright and license information, please view |
| 5 | + * the LICENSE file that was distributed with this source code. |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +namespace tests\loophp\TypedGenerators; |
| 11 | + |
| 12 | +use Faker\Generator; |
| 13 | +use loophp\TypedGenerators\TypedGen; |
| 14 | +use loophp\TypedGenerators\Types\Core\ArrayType; |
| 15 | +use loophp\TypedGenerators\Types\Core\BoolType; |
| 16 | +use loophp\TypedGenerators\Types\Core\ClosureType; |
| 17 | +use loophp\TypedGenerators\Types\Core\DateTimeType; |
| 18 | +use loophp\TypedGenerators\Types\Core\FloatType; |
| 19 | +use loophp\TypedGenerators\Types\Core\IntType; |
| 20 | +use loophp\TypedGenerators\Types\Core\IteratorType; |
| 21 | +use loophp\TypedGenerators\Types\Core\ListType; |
| 22 | +use loophp\TypedGenerators\Types\Core\NullType; |
| 23 | +use loophp\TypedGenerators\Types\Core\ObjectType; |
| 24 | +use loophp\TypedGenerators\Types\Core\StringType; |
| 25 | +use loophp\TypedGenerators\Types\Hybrid\Compound; |
| 26 | +use loophp\TypedGenerators\Types\Hybrid\Faker; |
| 27 | +use loophp\TypedGenerators\Types\Hybrid\Nullable; |
| 28 | +use PHPUnit\Framework\TestCase; |
| 29 | + |
| 30 | +/** |
| 31 | + * @internal |
| 32 | + * @coversDefaultClass \loophp\TypedGenerators |
| 33 | + */ |
| 34 | +final class TypeGenTest extends TestCase |
| 35 | +{ |
| 36 | + /** |
| 37 | + * @dataProvider typeProvider |
| 38 | + */ |
| 39 | + public function testStaticFactories(string $method, array $arguments, string $class) |
| 40 | + { |
| 41 | + self::assertInstanceOf($class, TypedGen::{$method}(...$arguments)); |
| 42 | + } |
| 43 | + |
| 44 | + public function typeProvider() |
| 45 | + { |
| 46 | + yield [ |
| 47 | + 'method' => 'array', |
| 48 | + 'arguments' => [ |
| 49 | + new StringType(), |
| 50 | + new StringType(), |
| 51 | + ], |
| 52 | + 'class' => ArrayType::class, |
| 53 | + ]; |
| 54 | + |
| 55 | + yield [ |
| 56 | + 'method' => 'bool', |
| 57 | + 'arguments' => [], |
| 58 | + 'class' => BoolType::class, |
| 59 | + ]; |
| 60 | + |
| 61 | + yield [ |
| 62 | + 'method' => 'closure', |
| 63 | + 'arguments' => [], |
| 64 | + 'class' => ClosureType::class, |
| 65 | + ]; |
| 66 | + |
| 67 | + yield [ |
| 68 | + 'method' => 'compound', |
| 69 | + 'arguments' => [ |
| 70 | + new StringType(), |
| 71 | + new IntType(), |
| 72 | + ], |
| 73 | + 'class' => Compound::class, |
| 74 | + ]; |
| 75 | + |
| 76 | + yield [ |
| 77 | + 'method' => 'datetime', |
| 78 | + 'arguments' => [], |
| 79 | + 'class' => DateTimeType::class, |
| 80 | + ]; |
| 81 | + |
| 82 | + yield [ |
| 83 | + 'method' => 'faker', |
| 84 | + 'arguments' => [ |
| 85 | + new StringType(), |
| 86 | + static fn (Generator $faker): string => $faker->city(), |
| 87 | + ], |
| 88 | + 'class' => Faker::class, |
| 89 | + ]; |
| 90 | + |
| 91 | + yield [ |
| 92 | + 'method' => 'float', |
| 93 | + 'arguments' => [], |
| 94 | + 'class' => FloatType::class, |
| 95 | + ]; |
| 96 | + |
| 97 | + yield [ |
| 98 | + 'method' => 'int', |
| 99 | + 'arguments' => [], |
| 100 | + 'class' => IntType::class, |
| 101 | + ]; |
| 102 | + |
| 103 | + yield [ |
| 104 | + 'method' => 'iterator', |
| 105 | + 'arguments' => [ |
| 106 | + new StringType(), |
| 107 | + new IntType(), |
| 108 | + ], |
| 109 | + 'class' => IteratorType::class, |
| 110 | + ]; |
| 111 | + |
| 112 | + yield [ |
| 113 | + 'method' => 'list', |
| 114 | + 'arguments' => [ |
| 115 | + new StringType(), |
| 116 | + ], |
| 117 | + 'class' => ListType::class, |
| 118 | + ]; |
| 119 | + |
| 120 | + yield [ |
| 121 | + 'method' => 'null', |
| 122 | + 'arguments' => [], |
| 123 | + 'class' => NullType::class, |
| 124 | + ]; |
| 125 | + |
| 126 | + yield [ |
| 127 | + 'method' => 'nullable', |
| 128 | + 'arguments' => [ |
| 129 | + new StringType(), |
| 130 | + ], |
| 131 | + 'class' => Nullable::class, |
| 132 | + ]; |
| 133 | + |
| 134 | + yield [ |
| 135 | + 'method' => 'object', |
| 136 | + 'arguments' => [], |
| 137 | + 'class' => ObjectType::class, |
| 138 | + ]; |
| 139 | + |
| 140 | + yield [ |
| 141 | + 'method' => 'string', |
| 142 | + 'arguments' => [], |
| 143 | + 'class' => StringType::class, |
| 144 | + ]; |
| 145 | + } |
| 146 | +} |
0 commit comments