From 37fd0107c000c176164fa88fdae0a0204d1f7e9b Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Sat, 15 Jun 2024 11:13:51 -0400 Subject: [PATCH] Add explicit test for #12 (#21) --- fixture_src/AliasedAttribute/FooClass.php | 10 +++++ fixture_src/AliasedAttributeFixture.php | 17 ++++++++ fixture_src/Fixtures.php | 4 ++ src/PhpParserAnnotatedTargetParser.php | 2 +- tests/Unit/AliasedAttributeTest.php | 47 ++++++++++++++++++++++ tests/Unit/ClassOnlyAttributeGroupTest.php | 1 - 6 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 fixture_src/AliasedAttribute/FooClass.php create mode 100644 fixture_src/AliasedAttributeFixture.php create mode 100644 tests/Unit/AliasedAttributeTest.php diff --git a/fixture_src/AliasedAttribute/FooClass.php b/fixture_src/AliasedAttribute/FooClass.php new file mode 100644 index 0000000..e2f02ee --- /dev/null +++ b/fixture_src/AliasedAttribute/FooClass.php @@ -0,0 +1,10 @@ +targets = []; $nodeTraverser->addVisitor($this->getVisitor( - fn($target) => $data->targets[] = $target, + static fn($target) => $data->targets[] = $target, $options->getAttributeTypes() )); diff --git a/tests/Unit/AliasedAttributeTest.php b/tests/Unit/AliasedAttributeTest.php new file mode 100644 index 0000000..befb0f1 --- /dev/null +++ b/tests/Unit/AliasedAttributeTest.php @@ -0,0 +1,47 @@ +withFixtures(Fixtures::aliasedAttribute()); + +it('counts parsed targets for single class') + ->expect(fn() => $this->getTargets()) + ->toHaveCount(1); + +it('ensures all targets are correct type') + ->expect(fn() => $this->getTargets()) + ->toContainOnlyAnnotatedTargets(); + +it('ensures all targets share target reflection') + ->expect(fn() => $this->getTargets()) + ->toShareTargetReflection(); + +it('ensures all targets share attribute reflection') + ->expect(fn() => $this->getTargets()) + ->toShareAttributeReflection(); + +it('ensures all targets share attribute instance') + ->expect(fn() => $this->getTargets()) + ->toShareAttributeInstance(); + +it('includes target reflection class') + ->expect(fn() => $this->getTargets()) + ->toContainTargetClass(Fixtures::aliasedAttribute()->fooClass()); + +it('includes attribute reflection class') + ->expect(fn() => $this->getTargets()) + ->toContainTargetClassWithAttribute(Fixtures::aliasedAttribute()->fooClass(), objectType(ClassOnly::class)); + +it('includes attribute instance with correct value') + ->expect(fn() => $this->getTargets()) + ->toContainTargetClassWithAttributeInstance( + Fixtures::aliasedAttribute()->fooClass(), + objectType(ClassOnly::class), + fn(ClassOnly $classOnly) => $classOnly->value === 'my aliased value' + ); diff --git a/tests/Unit/ClassOnlyAttributeGroupTest.php b/tests/Unit/ClassOnlyAttributeGroupTest.php index 1d9a4a1..8bb1876 100644 --- a/tests/Unit/ClassOnlyAttributeGroupTest.php +++ b/tests/Unit/ClassOnlyAttributeGroupTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use Cspray\AnnotatedTargetFixture\ParameterOnly; use Cspray\AnnotatedTargetFixture\RepeatableClassOnly; use function Cspray\Typiphy\objectType;