|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace FlixTech\SchemaRegistryApi\Test\Schemas; |
| 6 | + |
| 7 | +use Error; |
| 8 | +use FlixTech\SchemaRegistryApi\Constants; |
| 9 | +use FlixTech\SchemaRegistryApi\Schemas\AvroSchemaType; |
| 10 | +use FlixTech\SchemaRegistryApi\Schemas\JsonSchemaType; |
| 11 | +use FlixTech\SchemaRegistryApi\Schemas\ProtobufSchemaType; |
| 12 | +use Generator; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +class SchemaTypeTest extends TestCase |
| 16 | +{ |
| 17 | + /** |
| 18 | + * @test |
| 19 | + * @dataProvider provideSchemaTypes |
| 20 | + * |
| 21 | + * @phpstan-template template T of SchemaType |
| 22 | + * @param string $className |
| 23 | + * @phpstan-param class-string<T> $className |
| 24 | + * @param string $expected |
| 25 | + */ |
| 26 | + public function type_should_match_the_value(string $className, string $expected): void |
| 27 | + { |
| 28 | + self::assertEquals($expected, $className::instance()->value()); |
| 29 | + self::assertEquals($expected, (string)$className::instance()); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @test |
| 34 | + * @dataProvider provideSchemaTypes |
| 35 | + * |
| 36 | + * @phpstan-template template T of SchemaType |
| 37 | + * @param string $className |
| 38 | + * @phpstan-param class-string<T> $className |
| 39 | + */ |
| 40 | + public function types_cannot_be_cloned(string $className): void |
| 41 | + { |
| 42 | + $this->expectException(Error::class); |
| 43 | + $result = clone $className::instance(); |
| 44 | + } |
| 45 | + |
| 46 | + public function provideSchemaTypes(): Generator |
| 47 | + { |
| 48 | + yield 'AvroSchemaType' => [ |
| 49 | + AvroSchemaType::class, |
| 50 | + Constants::AVRO_TYPE, |
| 51 | + ]; |
| 52 | + |
| 53 | + yield 'JsonSchemaType' => [ |
| 54 | + JsonSchemaType::class, |
| 55 | + Constants::JSON_TYPE, |
| 56 | + ]; |
| 57 | + |
| 58 | + yield 'ProtobufSchemaType' => [ |
| 59 | + ProtobufSchemaType::class, |
| 60 | + Constants::PROTOBUF_TYPE, |
| 61 | + ]; |
| 62 | + } |
| 63 | +} |
0 commit comments