|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Steevanb\PhpCollection\Tests\Unit\ObjectCollection\DateTime\ContainsDateTimeValue; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use Steevanb\PhpCollection\ObjectCollection\DateTime\ContainsDateTimeNullableValueTrait; |
| 9 | +use Steevanb\PhpCollection\ObjectCollection\DateTime\ContainsDateTimeValueTrait; |
| 10 | +use Steevanb\PhpCollection\ObjectCollection\DateTimeCollection; |
| 11 | +use Steevanb\PhpCollection\ObjectCollection\DateTimeImmutableCollection; |
| 12 | +use Steevanb\PhpCollection\ObjectCollection\DateTimeImmutableNullableCollection; |
| 13 | +use Steevanb\PhpCollection\ObjectCollection\DateTimeInterfaceCollection; |
| 14 | +use Steevanb\PhpCollection\ObjectCollection\DateTimeInterfaceNullableCollection; |
| 15 | +use Steevanb\PhpCollection\ObjectCollection\DateTimeNullableCollection; |
| 16 | + |
| 17 | +/** |
| 18 | + * @covers \Steevanb\PhpCollection\ObjectCollection\DateTime\ContainsDateTimeValueTrait |
| 19 | + * @covers \Steevanb\PhpCollection\ObjectCollection\DateTime\ContainsDateTimeNullableValueTrait |
| 20 | + * @internal |
| 21 | + */ |
| 22 | +final class TraitUsageTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @dataProvider provideCollectionUsingTrait |
| 26 | + * @param class-string $class |
| 27 | + */ |
| 28 | + public function testUsingTrait(string $class): void |
| 29 | + { |
| 30 | + $reflectionCollection = new \ReflectionClass($class); |
| 31 | + static::assertContains( |
| 32 | + needle: ContainsDateTimeValueTrait::class, |
| 33 | + haystack: array_map( |
| 34 | + static fn (\ReflectionClass $reflectionTrait): string => $reflectionTrait->getName(), |
| 35 | + $reflectionCollection->getTraits() |
| 36 | + ) |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @dataProvider provideCollectionUsingNullableTrait |
| 42 | + * @param class-string $class |
| 43 | + */ |
| 44 | + public function testUsingNullableTrait(string $class): void |
| 45 | + { |
| 46 | + $reflectionCollection = new \ReflectionClass($class); |
| 47 | + static::assertContains( |
| 48 | + needle: ContainsDateTimeNullableValueTrait::class, |
| 49 | + haystack: array_map( |
| 50 | + static fn (\ReflectionClass $reflectionTrait): string => $reflectionTrait->getName(), |
| 51 | + $reflectionCollection->getTraits() |
| 52 | + ) |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + /** @return iterable<string, array{class: class-string}> */ |
| 57 | + public static function provideCollectionUsingTrait(): iterable |
| 58 | + { |
| 59 | + yield 'ContainsDateTimeValueTrait_is_used_by_DateTimeCollection' => [ |
| 60 | + 'class' => DateTimeCollection::class, |
| 61 | + ]; |
| 62 | + yield 'ContainsDateTimeValueTrait_is_used_by_DateTimeImmutableCollection' => [ |
| 63 | + 'class' => DateTimeImmutableCollection::class, |
| 64 | + ]; |
| 65 | + yield 'ContainsDateTimeValueTrait_is_used_by_DateTimeInterfaceCollection' => [ |
| 66 | + 'class' => DateTimeInterfaceCollection::class, |
| 67 | + ]; |
| 68 | + } |
| 69 | + |
| 70 | + /** @return iterable<string, array{class: class-string}> */ |
| 71 | + public static function provideCollectionUsingNullableTrait(): iterable |
| 72 | + { |
| 73 | + yield 'ContainsDateTimeNullableValueTrait_is_used_by_DateTimeNullableCollection' => [ |
| 74 | + 'class' => DateTimeNullableCollection::class, |
| 75 | + ]; |
| 76 | + yield 'ContainsDateTimeNullableValueTrait_is_used_by_DateTimeImmutableNullableCollection' => [ |
| 77 | + 'class' => DateTimeImmutableNullableCollection::class, |
| 78 | + ]; |
| 79 | + yield 'ContainsDateTimeNullableValueTrait_is_used_by_DateTimeInterfaceNullableCollection' => [ |
| 80 | + 'class' => DateTimeInterfaceNullableCollection::class, |
| 81 | + ]; |
| 82 | + } |
| 83 | +} |
0 commit comments