Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
64.29% |
9 / 14 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ValueObjectTestCase | |
64.29% |
9 / 14 |
|
50.00% |
2 / 4 |
6.14 | |
0.00% |
0 / 1 |
| className | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| provideFromNative | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getOpenApiSchemaForCreation | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| testCount | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| it_can_be_instantiated_with_fromNative | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| it_works_with_schema_generator | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| it_works_with_apie_faker | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Fixtures\TestHelpers; |
| 3 | |
| 4 | use Apie\Core\Attributes\FakeCount; |
| 5 | use Apie\Core\ValueObjects\ValueObjectInterface; |
| 6 | use PHPUnit\Framework\Attributes\DataProvider; |
| 7 | use PHPUnit\Framework\Attributes\Test; |
| 8 | use PHPUnit\Framework\TestCase; |
| 9 | |
| 10 | abstract class ValueObjectTestCase extends TestCase |
| 11 | { |
| 12 | use TestWithOpenapiSchema; |
| 13 | use TestWithFaker; |
| 14 | |
| 15 | /** |
| 16 | * @return class-string<ValueObjectInterface> |
| 17 | */ |
| 18 | abstract public static function className(): string; |
| 19 | |
| 20 | /** |
| 21 | * @return array<array-key, array{0: mixed, 1: mixed}> |
| 22 | */ |
| 23 | abstract public static function provideFromNative(): array; |
| 24 | |
| 25 | abstract public static function getOpenApiSchemaForCreation(): array; |
| 26 | |
| 27 | protected static function testCount(): int |
| 28 | { |
| 29 | $refl = new \ReflectionClass(static::className()); |
| 30 | foreach ($refl->getAttributes(FakeCount::class) as $attribute) { |
| 31 | return $attribute->newInstance()->count; |
| 32 | } |
| 33 | |
| 34 | return 1000; |
| 35 | } |
| 36 | |
| 37 | #[Test] |
| 38 | #[DataProvider('provideFromNative')] |
| 39 | public function it_can_be_instantiated_with_fromNative(mixed $expected, mixed $input): void |
| 40 | { |
| 41 | $className = static::className(); |
| 42 | $valueObject = $className::fromNative($input); |
| 43 | $this->assertInstanceOf($className, $valueObject); |
| 44 | $this->assertEquals($expected, $valueObject->toNative()); |
| 45 | } |
| 46 | |
| 47 | #[Test] |
| 48 | public function it_works_with_schema_generator() |
| 49 | { |
| 50 | $this->runOpenapiSchemaTestForCreation( |
| 51 | static::className(), |
| 52 | (new \ReflectionClass(static::className()))->getShortName() . '-post', |
| 53 | static::getOpenApiSchemaForCreation() |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | #[\PHPUnit\Framework\Attributes\Test] |
| 58 | public function it_works_with_apie_faker() |
| 59 | { |
| 60 | $this->runFakerTest(static::className(), interval: static::testCount()); |
| 61 | } |
| 62 | } |