From 588493741e297d3d9f67c2cd0151ecfc5031d530 Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Mon, 17 Jun 2024 08:40:35 -0400 Subject: [PATCH 1/6] Merge up 1.1 (#22) * Task/support php parser 5 (#20) * Support PHP-Parser 4.18 & 5 * Try testing both versions of php-parser * Support proper target branches * Add explicit test for #12 (#21) --- .github/workflows/php.yml | 17 +++++--- composer.json | 2 +- fixture_src/AliasedAttribute/FooClass.php | 10 +++++ fixture_src/AliasedAttributeFixture.php | 17 ++++++++ fixture_src/Fixtures.php | 4 ++ src/PhpParserAnnotatedTargetParser.php | 4 +- tests/Unit/AliasedAttributeTest.php | 47 ++++++++++++++++++++++ tests/Unit/ClassOnlyAttributeGroupTest.php | 1 - 8 files changed, 92 insertions(+), 10 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/.github/workflows/php.yml b/.github/workflows/php.yml index 2c8cc64..b5ad2da 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -2,25 +2,30 @@ name: 'Unit Tests' on: push: - branches: [ main ] + branches: [ release-1.x ] pull_request: - branches: [ main ] + branches: [ release-1.x ] jobs: build-test: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + composer: [lowest, highest] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP 8 uses: shivammathur/setup-php@v2 with: php-version: 8.1 - tools: composer:v2 + tools: none coverage: none - name: Composer Install - run: composer update --no-interaction --no-progress --ansi + uses: ramsey/composer-install@v2 + with: + dependency-versions: ${{ matrix.composer }} - name: Unit Tests run: ./vendor/bin/pest --colors=always \ No newline at end of file diff --git a/composer.json b/composer.json index aa70f39..a4a07d6 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^8.1", - "nikic/php-parser": "^v4.14", + "nikic/php-parser": "^v4.18 || ^5.0", "cspray/typiphy": "^0.3" }, "require-dev": { 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 @@ +parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); + $this->parser = (new ParserFactory())->createForNewestSupportedVersion(); } public function parse(AnnotatedTargetParserOptions $options) : Generator { @@ -39,7 +39,7 @@ public function parse(AnnotatedTargetParserOptions $options) : Generator { $data = new \stdClass(); $data->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; From ec7204aa06b57c03c5e70c62fc7e0d915802f6d7 Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Mon, 17 Jun 2024 08:51:35 -0400 Subject: [PATCH 2/6] Allow using typiphy 0.4 (#23) * Allow using typiphy 0.4 * Add release-2.x to CI --- .github/workflows/php.yml | 4 +- README.md | 10 +-- composer.json | 2 +- src/AnnotatedTarget.php | 6 +- src/AnnotatedTargetParser.php | 4 + src/AnnotatedTargetParserOptions.php | 12 ++- src/AnnotatedTargetParserOptionsBuilder.php | 4 +- src/PhpParserAnnotatedTargetParser.php | 16 ++-- src/functions.php | 5 +- tests/Pest.php | 88 +++++++++---------- ...nnotatedTargetParserOptionsBuilderTest.php | 8 +- 11 files changed, 86 insertions(+), 73 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b5ad2da..e8cbb1d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -2,9 +2,9 @@ name: 'Unit Tests' on: push: - branches: [ release-1.x ] + branches: [ release-1.x, release-2.x ] pull_request: - branches: [ release-1.x ] + branches: [ release-1.x, release-2.x ] jobs: build-test: diff --git a/README.md b/README.md index 262080d..f5722fd 100644 --- a/README.md +++ b/README.md @@ -50,14 +50,14 @@ use function Cspray\AnnotatedTarget\parseAttributes; foreach (parseAttributes(__DIR__ . '/src') as $annotatedTarget) { // $annotatedTarget is an instanceof AnnotatedTarget // This will be a ReflectionClass, ReflectionProperty, or ReflectionMethod depending on which iteration - $target = $annotatedTarget->getTargetReflection(); + $target = $annotatedTarget->targetReflection(); // This will be a ReflectionAttribute - $attributeReflection = $annotatedTarget->getAttributeReflection(); - // This will be an instance of the Attribute returned from $this->getAttributeReflection()->newInstance() - $attributeInstance = $annotatedTarget->getAttributeInstance(); + $attributeReflection = $annotatedTarget->attributeReflection(); + // This will be an instance of the Attribute returned from $this->attributeReflection()->newInstance() + $attributeInstance = $annotatedTarget->attributeInstance(); // All the methods above are shared - $isShared = $annotatedTarget->getTargetReflection() === $annotatedTarget->getTargetReflection(); // true + $isShared = $annotatedTarget->targetReflection() === $annotatedTarget->targetReflection(); // true } ``` diff --git a/composer.json b/composer.json index a4a07d6..4e7d125 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^8.1", "nikic/php-parser": "^v4.18 || ^5.0", - "cspray/typiphy": "^0.3" + "cspray/typiphy": "^0.4" }, "require-dev": { "pestphp/pest": "^v1.21" diff --git a/src/AnnotatedTarget.php b/src/AnnotatedTarget.php index 15f3329..d314dc1 100644 --- a/src/AnnotatedTarget.php +++ b/src/AnnotatedTarget.php @@ -12,10 +12,10 @@ interface AnnotatedTarget { - public function getTargetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction; + public function targetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction; - public function getAttributeReflection() : ReflectionAttribute; + public function attributeReflection() : ReflectionAttribute; - public function getAttributeInstance() : object; + public function attributeInstance() : object; } \ No newline at end of file diff --git a/src/AnnotatedTargetParser.php b/src/AnnotatedTargetParser.php index 4299a39..d776df7 100644 --- a/src/AnnotatedTargetParser.php +++ b/src/AnnotatedTargetParser.php @@ -6,6 +6,10 @@ interface AnnotatedTargetParser { + /** + * @param AnnotatedTargetParserOptions $options + * @return Generator + */ public function parse(AnnotatedTargetParserOptions $options) : Generator; } \ No newline at end of file diff --git a/src/AnnotatedTargetParserOptions.php b/src/AnnotatedTargetParserOptions.php index 7eede17..af6a1f0 100644 --- a/src/AnnotatedTargetParserOptions.php +++ b/src/AnnotatedTargetParserOptions.php @@ -2,10 +2,18 @@ namespace Cspray\AnnotatedTarget; +use Cspray\Typiphy\ObjectType; + interface AnnotatedTargetParserOptions { - public function getSourceDirectories() : array; + /** + * @return list + */ + public function sourceDirectories() : array; - public function getAttributeTypes() : array; + /** + * @return list + */ + public function attributeTypes() : array; } \ No newline at end of file diff --git a/src/AnnotatedTargetParserOptionsBuilder.php b/src/AnnotatedTargetParserOptionsBuilder.php index 49ba9ab..50dc277 100644 --- a/src/AnnotatedTargetParserOptionsBuilder.php +++ b/src/AnnotatedTargetParserOptionsBuilder.php @@ -40,11 +40,11 @@ public function build() : AnnotatedTargetParserOptions { public function __construct(private readonly array $directories, private readonly array $attributes) {} - public function getSourceDirectories() : array { + public function sourceDirectories() : array { return $this->directories; } - public function getAttributeTypes() : array { + public function attributeTypes() : array { return $this->attributes; } }; diff --git a/src/PhpParserAnnotatedTargetParser.php b/src/PhpParserAnnotatedTargetParser.php index 9975421..7ac2568 100644 --- a/src/PhpParserAnnotatedTargetParser.php +++ b/src/PhpParserAnnotatedTargetParser.php @@ -40,7 +40,7 @@ public function parse(AnnotatedTargetParserOptions $options) : Generator { $data->targets = []; $nodeTraverser->addVisitor($this->getVisitor( static fn($target) => $data->targets[] = $target, - $options->getAttributeTypes() + $options->attributeTypes() )); foreach ($this->getSourceIterator($options) as $sourceFile) { @@ -61,7 +61,7 @@ public function parse(AnnotatedTargetParserOptions $options) : Generator { } private function getSourceIterator(AnnotatedTargetParserOptions $options) : Iterator { - foreach ($options->getSourceDirectories() as $directory) { + foreach ($options->sourceDirectories() as $directory) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS) ); @@ -75,7 +75,7 @@ private function getSourceIterator(AnnotatedTargetParserOptions $options) : Iter } private function getVisitor(callable $consumer, array $filteredAttributes) : NodeVisitor { - $filteredAttributes = array_map(fn($attr) => $attr->getName(), $filteredAttributes); + $filteredAttributes = array_map(fn($attr) => $attr->name(), $filteredAttributes); return new class($consumer, $filteredAttributes) extends NodeVisitorAbstract { private $consumer; @@ -182,23 +182,23 @@ public function __construct( $this->reflectorSupplier = $reflectorSupplier; } - public function getTargetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction { + public function targetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction { if (!isset($this->reflection)) { $this->reflection = ($this->reflectorSupplier)(); } return $this->reflection; } - public function getAttributeReflection() : ReflectionAttribute { + public function attributeReflection() : ReflectionAttribute { if (!isset($this->reflectionAttribute)) { - $this->reflectionAttribute = $this->getTargetReflection()->getAttributes()[$this->index]; + $this->reflectionAttribute = $this->targetReflection()->getAttributes()[$this->index]; } return $this->reflectionAttribute; } - public function getAttributeInstance() : object { + public function attributeInstance() : object { if (!isset($this->attribute)) { - $this->attribute = $this->getAttributeReflection()->newInstance(); + $this->attribute = $this->attributeReflection()->newInstance(); } return $this->attribute; } diff --git a/src/functions.php b/src/functions.php index c32b1a8..2c2cf76 100644 --- a/src/functions.php +++ b/src/functions.php @@ -6,8 +6,8 @@ use function Cspray\Typiphy\objectType; /** - * @param array|string $directories - * @param array $filterAttributes + * @param list|non-empty-string $directories + * @param list $filterAttributes * @return Generator * @throws Exception\InvalidArgumentException */ @@ -20,5 +20,6 @@ function parseAttributes(array|string $directories, array $filterAttributes = [] $attributeTypes = array_map(fn($type) => objectType($type), $filterAttributes); $builder = $builder->filterAttributes(...$attributeTypes); } + return $parser->parse($builder->build()); } \ No newline at end of file diff --git a/tests/Pest.php b/tests/Pest.php index c0a50cb..18797d0 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -27,44 +27,44 @@ use PHPUnit\Framework\Assert; $checkTargetReflectionClass = function(AnnotatedTarget $target, ObjectType $expectedClass) : bool { - return $target->getTargetReflection() instanceof ReflectionClass && - $target->getTargetReflection()->getName() === $expectedClass->getName(); + return $target->targetReflection() instanceof ReflectionClass && + $target->targetReflection()->getName() === $expectedClass->name(); }; $checkTargetReflectionClassConstant = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedConst) : bool { - return $target->getTargetReflection() instanceof ReflectionClassConstant && - $target->getTargetReflection()->getDeclaringClass()->getName() === $expectedClass->getName() && - $target->getTargetReflection()->getName() === $expectedConst; + return $target->targetReflection() instanceof ReflectionClassConstant && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getName() === $expectedConst; }; $checkTargetReflectionFunction = function(AnnotatedTarget $target, string $expectedFunction) : bool { - return $target->getTargetReflection() instanceof ReflectionFunction && - $target->getTargetReflection()->getName() === $expectedFunction; + return $target->targetReflection() instanceof ReflectionFunction && + $target->targetReflection()->getName() === $expectedFunction; }; $checkTargetReflectionFunctionParameter = function(AnnotatedTarget $target, string $expectedFunction, string $expectedParam) : bool { - return $target->getTargetReflection() instanceof ReflectionParameter && - $target->getTargetReflection()->getDeclaringFunction()->getName() === $expectedFunction && - $target->getTargetReflection()->getName() === $expectedParam; + return $target->targetReflection() instanceof ReflectionParameter && + $target->targetReflection()->getDeclaringFunction()->getName() === $expectedFunction && + $target->targetReflection()->getName() === $expectedParam; }; $checkTargetReflectionMethod = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedMethod) : bool { - return $target->getTargetReflection() instanceof ReflectionMethod && - $target->getTargetReflection()->getDeclaringClass()->getName() === $expectedClass->getName() && - $target->getTargetReflection()->getName() === $expectedMethod; + return $target->targetReflection() instanceof ReflectionMethod && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getName() === $expectedMethod; }; $checkTargetReflectionProperty = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedProp) : bool { - return $target->getTargetReflection() instanceof ReflectionProperty && - $target->getTargetReflection()->getDeclaringClass()->getName() === $expectedClass->getName() && - $target->getTargetReflection()->getName() === $expectedProp; + return $target->targetReflection() instanceof ReflectionProperty && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getName() === $expectedProp; }; $checkTargetReflectionMethodParameter = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedMethod, string $expectedParam) : bool { - return $target->getTargetReflection() instanceof ReflectionParameter && - $target->getTargetReflection()->getDeclaringClass()->getName() === $expectedClass->getName() && - $target->getTargetReflection()->getDeclaringFunction()->getName() === $expectedMethod && - $target->getTargetReflection()->getName() === $expectedParam; + return $target->targetReflection() instanceof ReflectionParameter && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getDeclaringFunction()->getName() === $expectedMethod && + $target->targetReflection()->getName() === $expectedParam; }; expect()->extend('toBeOne', function () { @@ -77,19 +77,19 @@ expect()->extend('toShareTargetReflection', function() { return $this->each(function($expectation) { - expect($expectation->value->getTargetReflection())->toBe($expectation->value->getTargetReflection()); + expect($expectation->value->targetReflection())->toBe($expectation->value->targetReflection()); }); }); expect()->extend('toShareAttributeReflection', function() { return $this->each(function($expectation) { - expect($expectation->value->getAttributeReflection())->toBe($expectation->value->getAttributeReflection()); + expect($expectation->value->attributeReflection())->toBe($expectation->value->attributeReflection()); }); }); expect()->extend('toShareAttributeInstance', function() { return $this->each(function($expectation) { - expect($expectation->value->getAttributeInstance())->toBe($expectation->value->getAttributeInstance()); + expect($expectation->value->attributeInstance())->toBe($expectation->value->attributeInstance()); }); }); @@ -102,15 +102,15 @@ expect()->extend('toContainTargetClassWithAttribute', function(ObjectType $expectedClass, ObjectType $expectedAttribute) use($checkTargetReflectionClass) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClass($item, $expectedClass) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetClassWithAttributeInstance', function(ObjectType $expectedClass, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionClass) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClass($item, $expectedClass) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); @@ -123,15 +123,15 @@ expect()->extend('toContainTargetClassConstantWithAttribute', function(ObjectType $expectedClass, string $expectedConst, ObjectType $expectedAttribute) use($checkTargetReflectionClassConstant) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClassConstant($item, $expectedClass, $expectedConst) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetClassConstantWithAttributeInstance', function(ObjectType $expectedClass, string $expectedConst, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionClassConstant) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClassConstant($item, $expectedClass, $expectedConst) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); @@ -144,15 +144,15 @@ expect()->extend('toContainTargetFunctionWithAttribute', function(string $expectedFunction, ObjectType $expectedAttribute) use($checkTargetReflectionFunction) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunction($item, $expectedFunction) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetFunctionWithAttributeInstance', function(string $expectedFunction, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionFunction) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunction($item, $expectedFunction) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); @@ -165,15 +165,15 @@ expect()->extend('toContainTargetFunctionParameterWithAttribute', function(string $expectedFunction, string $expectedParam, ObjectType $expectedAttribute) use($checkTargetReflectionFunctionParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunctionParameter($item, $expectedFunction, $expectedParam) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetFunctionParameterWithAttributeInstance', function(string $expectedFunction, string $expectedParam, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionFunctionParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunctionParameter($item, $expectedFunction, $expectedParam) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); @@ -186,15 +186,15 @@ expect()->extend('toContainTargetMethodWithAttribute', function(ObjectType $expectedClass, string $expectedMethod, ObjectType $expectedAttribute) use($checkTargetReflectionMethod) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethod($item, $expectedClass, $expectedMethod) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetMethodWithAttributeInstance', function(ObjectType $expectedClass, string $expectedMethod, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionMethod) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethod($item, $expectedClass, $expectedMethod) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); @@ -207,15 +207,15 @@ expect()->extend('toContainTargetPropertyWithAttribute', function(ObjectType $expectedClass, string $expectedProp, ObjectType $expectedAttribute) use($checkTargetReflectionProperty) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionProperty($item, $expectedClass, $expectedProp) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetPropertyWithAttributeInstance', function(ObjectType $expectedClass, string $expectedProp, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionProperty) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionProperty($item, $expectedClass, $expectedProp) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); @@ -228,15 +228,15 @@ expect()->extend('toContainTargetMethodParameterWithAttribute', function(ObjectType $expectedClass, string $expectedMethod, string $expectedParam, ObjectType $expectedAttribute) use($checkTargetReflectionMethodParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethodParameter($item, $expectedClass, $expectedMethod, $expectedParam) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() + $item->attributeReflection()->getName() === $expectedAttribute->name() ); }); expect()->extend('toContainTargetMethodParameterWithAttributeInstance', function(ObjectType $expectedClass, string $expectedMethod, string $expectedParam, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionMethodParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethodParameter($item, $expectedClass, $expectedMethod, $expectedParam) && - $item->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute->name() && + $callable($item->attributeInstance()) ); }); diff --git a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php b/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php index 884df28..c884200 100644 --- a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php +++ b/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php @@ -24,7 +24,7 @@ it('has scan directories in options') ->expect(function() { $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath())->build(); - return $options->getSourceDirectories(); + return $options->sourceDirectories(); }) ->toBe([Fixtures::classOnlyAttributeSingleClass()->getPath()]); @@ -37,7 +37,7 @@ it('has empty filterAttributes in options') ->expect(function() { $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath())->build(); - return $options->getAttributeTypes(); + return $options->attributeTypes(); })->toBeEmpty(); it('has populated filterAttributes in options') @@ -45,7 +45,7 @@ $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath()) ->filterAttributes(objectType(ClassOnly::class)) ->build(); - return $options->getAttributeTypes(); + return $options->attributeTypes(); })->toBe([objectType(ClassOnly::class)]); it('has populated filterAttributes in options, when chained') @@ -54,5 +54,5 @@ ->filterAttributes(objectType(ClassOnly::class)) ->filterAttributes(objectType(MethodOnly::class)) ->build(); - return $options->getAttributeTypes(); + return $options->attributeTypes(); })->toBe([objectType(ClassOnly::class), objectType(MethodOnly::class)]); \ No newline at end of file From 8cdbcb40ff51674cd0ac20848e5914c7e144743d Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Thu, 27 Jun 2024 10:42:31 -0400 Subject: [PATCH 3/6] Remove need for cspray/typiphy --- composer.json | 3 +- fixture_src/AliasedAttributeFixture.php | 7 +- ...ssOnlyAttributeGroupSingleClassFixture.php | 7 +- .../ClassOnlyAttributeSingleClassFixture.php | 4 +- ...assOnlyAttributeSingleInterfaceFixture.php | 4 +- ...ntOnlyAttributeGroupSingleClassFixture.php | 4 +- .../MethodOnlyAttributeSingleClassFixture.php | 7 +- ...ntClassOnlyAttributeSingleClassFixture.php | 7 +- fixture_src/NonPhpFileFixture.php | 9 +- ...rameterOnlyAttributeSingleClassFixture.php | 7 +- ...ropertyOnlyAttributeSingleClassFixture.php | 7 +- ...eatableClassOnlyAttributeSingleFixture.php | 7 +- ...onstantOnlyAttributeSingleClassFixture.php | 7 +- ...eMethodOnlyAttributeSingleClassFixture.php | 7 +- ...rameterOnlyAttributeSingleClassFixture.php | 7 +- ...ropertyOnlyAttributeSingleClassFixture.php | 7 +- ...uteMultipleConstantsSingleClassFixture.php | 7 +- ...teMultiplePropertiesSingleClassFixture.php | 7 +- .../TargetAttributeInterfaceFixture.php | 6 +- src/AnnotatedTargetParserOptions.php | 6 +- src/AnnotatedTargetParserOptionsBuilder.php | 19 +-- src/PhpParserAnnotatedTargetParser.php | 2 - src/functions.php | 15 ++- tests/Pest.php | 120 +++++++----------- tests/Unit/AliasedAttributeTest.php | 5 +- ...nnotatedTargetParserOptionsBuilderTest.php | 33 ++--- tests/Unit/AnnotatedTargetParserTestCase.php | 11 +- tests/Unit/ClassOnlyAttributeGroupTest.php | 20 +-- tests/Unit/ClassOnlyAttributeTest.php | 7 +- .../Unit/ClassOnlyInterfaceAttributeTest.php | 7 +- tests/Unit/ConstantOnlyAttributeTest.php | 5 +- tests/Unit/FilterAttributeTest.php | 9 +- tests/Unit/FunctionOnlyAttributeTest.php | 7 +- .../FunctionParameterOnlyAttributeTest.php | 5 +- tests/Unit/MethodOnlyAttributeTest.php | 5 +- ...ultipleDifferentClassOnlyAttributeTest.php | 17 ++- tests/Unit/MultipleDirectoryTest.php | 11 +- tests/Unit/NonPhpFileTest.php | 6 +- tests/Unit/ParameterOnlyAttributeTest.php | 5 +- .../ParseAttributesMultipleDirectoryTest.php | 13 +- .../ParseAttributesSingleDirectoryTest.php | 7 +- .../ParserAttributesFilterAttributeTest.php | 7 +- tests/Unit/PropertyOnlyAttributeTest.php | 7 +- .../Unit/RepeatableClassOnlyAttributeTest.php | 15 +-- .../RepeatableConstantOnlyAttributeTest.php | 12 +- .../RepeatableFunctionOnlyAttributeTest.php | 12 +- .../RepeatableMethodOnlyAttributeTest.php | 13 +- .../RepeatableParameterOnlyAttributeTest.php | 11 +- .../RepeatablePropertyOnlyAttributeTest.php | 15 +-- ...AttributeMultipleConstantsPropertyTest.php | 13 +- .../SingleAttributeMultiplePropertyTest.php | 19 ++- tests/Unit/TargetAttributeInterfaceTest.php | 9 +- 52 files changed, 239 insertions(+), 350 deletions(-) diff --git a/composer.json b/composer.json index 4e7d125..d15c5f2 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,7 @@ ], "require": { "php": "^8.1", - "nikic/php-parser": "^v4.18 || ^5.0", - "cspray/typiphy": "^0.4" + "nikic/php-parser": "^v4.18 || ^5.0" }, "require-dev": { "pestphp/pest": "^v1.21" diff --git a/fixture_src/AliasedAttributeFixture.php b/fixture_src/AliasedAttributeFixture.php index 86d6972..ea56c7e 100644 --- a/fixture_src/AliasedAttributeFixture.php +++ b/fixture_src/AliasedAttributeFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class AliasedAttributeFixture implements Fixture { public function getPath() : string { return __DIR__ . '/AliasedAttribute'; } - public function fooClass() : ObjectType { - return objectType(AliasedAttribute\FooClass::class); + public function fooClass() : string { + return AliasedAttribute\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/ClassOnlyAttributeGroupSingleClassFixture.php b/fixture_src/ClassOnlyAttributeGroupSingleClassFixture.php index b684c39..847716f 100644 --- a/fixture_src/ClassOnlyAttributeGroupSingleClassFixture.php +++ b/fixture_src/ClassOnlyAttributeGroupSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class ClassOnlyAttributeGroupSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/ClassOnlyAttributeGroupSingleClass'; } - public function fooClass() : ObjectType { - return objectType(ClassOnlyAttributeGroupSingleClass\FooClass::class); + public function fooClass() : string { + return ClassOnlyAttributeGroupSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/ClassOnlyAttributeSingleClassFixture.php b/fixture_src/ClassOnlyAttributeSingleClassFixture.php index 1d05584..f0dd3f9 100644 --- a/fixture_src/ClassOnlyAttributeSingleClassFixture.php +++ b/fixture_src/ClassOnlyAttributeSingleClassFixture.php @@ -11,7 +11,7 @@ public function getPath() : string { return __DIR__ . '/ClassOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(ClassOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return ClassOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/ClassOnlyAttributeSingleInterfaceFixture.php b/fixture_src/ClassOnlyAttributeSingleInterfaceFixture.php index 00b16ab..feaebfa 100644 --- a/fixture_src/ClassOnlyAttributeSingleInterfaceFixture.php +++ b/fixture_src/ClassOnlyAttributeSingleInterfaceFixture.php @@ -11,7 +11,7 @@ public function getPath() : string { return __DIR__ .'/ClassOnlyAttributeSingleInterface'; } - public function fooInterface() : ObjectType { - return objectType(ClassOnlyAttributeSingleInterface\FooInterface::class); + public function fooInterface() : string { + return ClassOnlyAttributeSingleInterface\FooInterface::class; } } \ No newline at end of file diff --git a/fixture_src/ConstantOnlyAttributeGroupSingleClassFixture.php b/fixture_src/ConstantOnlyAttributeGroupSingleClassFixture.php index 537a572..c8944e2 100644 --- a/fixture_src/ConstantOnlyAttributeGroupSingleClassFixture.php +++ b/fixture_src/ConstantOnlyAttributeGroupSingleClassFixture.php @@ -11,8 +11,8 @@ public function getPath() : string { return __DIR__ . '/ConstantOnlyAttributeGroupSingleClass'; } - public function fooClass() : ObjectType { - return objectType(ConstantOnlyAttributeGroupSingleClass\FooClass::class); + public function fooClass() : string { + return ConstantOnlyAttributeGroupSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/MethodOnlyAttributeSingleClassFixture.php b/fixture_src/MethodOnlyAttributeSingleClassFixture.php index 31df438..39b1ba2 100644 --- a/fixture_src/MethodOnlyAttributeSingleClassFixture.php +++ b/fixture_src/MethodOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class MethodOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/MethodOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(MethodOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return MethodOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/MultipleDifferentClassOnlyAttributeSingleClassFixture.php b/fixture_src/MultipleDifferentClassOnlyAttributeSingleClassFixture.php index 38abebc..4e54933 100644 --- a/fixture_src/MultipleDifferentClassOnlyAttributeSingleClassFixture.php +++ b/fixture_src/MultipleDifferentClassOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class MultipleDifferentClassOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/MultipleDifferentClassOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(MultipleDifferentClassOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return MultipleDifferentClassOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/NonPhpFileFixture.php b/fixture_src/NonPhpFileFixture.php index 40c29cb..b98ac1c 100644 --- a/fixture_src/NonPhpFileFixture.php +++ b/fixture_src/NonPhpFileFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class NonPhpFileFixture implements Fixture { public function getPath() : string { return __DIR__ . '/NonPhpFile'; } - public function fooClass() : ObjectType { - return objectType(NonPhpFile\FooClass::class); + public function fooClass() : string { + return NonPhpFile\FooClass::class; } -} \ No newline at end of file +} diff --git a/fixture_src/ParameterOnlyAttributeSingleClassFixture.php b/fixture_src/ParameterOnlyAttributeSingleClassFixture.php index acf4322..9d9a962 100644 --- a/fixture_src/ParameterOnlyAttributeSingleClassFixture.php +++ b/fixture_src/ParameterOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class ParameterOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/ParameterOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(ParameterOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return ParameterOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/PropertyOnlyAttributeSingleClassFixture.php b/fixture_src/PropertyOnlyAttributeSingleClassFixture.php index d1281e8..594ebe1 100644 --- a/fixture_src/PropertyOnlyAttributeSingleClassFixture.php +++ b/fixture_src/PropertyOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class PropertyOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/PropertyOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(PropertyOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return PropertyOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/RepeatableClassOnlyAttributeSingleFixture.php b/fixture_src/RepeatableClassOnlyAttributeSingleFixture.php index 4bdd906..0d6c9da 100644 --- a/fixture_src/RepeatableClassOnlyAttributeSingleFixture.php +++ b/fixture_src/RepeatableClassOnlyAttributeSingleFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class RepeatableClassOnlyAttributeSingleFixture implements Fixture { public function getPath() : string { return __DIR__ . '/RepeatableClassOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(RepeatableClassOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return RepeatableClassOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/RepeatableConstantOnlyAttributeSingleClassFixture.php b/fixture_src/RepeatableConstantOnlyAttributeSingleClassFixture.php index f72d612..c4401ff 100644 --- a/fixture_src/RepeatableConstantOnlyAttributeSingleClassFixture.php +++ b/fixture_src/RepeatableConstantOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class RepeatableConstantOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/RepeatableConstantOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(RepeatableConstantOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return RepeatableConstantOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/RepeatableMethodOnlyAttributeSingleClassFixture.php b/fixture_src/RepeatableMethodOnlyAttributeSingleClassFixture.php index 76220e6..7126903 100644 --- a/fixture_src/RepeatableMethodOnlyAttributeSingleClassFixture.php +++ b/fixture_src/RepeatableMethodOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class RepeatableMethodOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ .'/RepeatableMethodOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(RepeatableMethodOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return RepeatableMethodOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/RepeatableParameterOnlyAttributeSingleClassFixture.php b/fixture_src/RepeatableParameterOnlyAttributeSingleClassFixture.php index 90fc768..995b59c 100644 --- a/fixture_src/RepeatableParameterOnlyAttributeSingleClassFixture.php +++ b/fixture_src/RepeatableParameterOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class RepeatableParameterOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/RepeatableParameterOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(RepeatableParameterOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return RepeatableParameterOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/RepeatablePropertyOnlyAttributeSingleClassFixture.php b/fixture_src/RepeatablePropertyOnlyAttributeSingleClassFixture.php index a39eaf0..8c63d88 100644 --- a/fixture_src/RepeatablePropertyOnlyAttributeSingleClassFixture.php +++ b/fixture_src/RepeatablePropertyOnlyAttributeSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class RepeatablePropertyOnlyAttributeSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/RepeatablePropertyOnlyAttributeSingleClass'; } - public function fooClass() : ObjectType { - return objectType(RepeatablePropertyOnlyAttributeSingleClass\FooClass::class); + public function fooClass() : string { + return RepeatablePropertyOnlyAttributeSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/SingleAttributeMultipleConstantsSingleClassFixture.php b/fixture_src/SingleAttributeMultipleConstantsSingleClassFixture.php index 9246abf..b6d9c75 100644 --- a/fixture_src/SingleAttributeMultipleConstantsSingleClassFixture.php +++ b/fixture_src/SingleAttributeMultipleConstantsSingleClassFixture.php @@ -2,16 +2,13 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - class SingleAttributeMultipleConstantsSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/SingleAttributeMultipleConstantsSingleClass'; } - public function fooClass() : ObjectType { - return objectType(SingleAttributeMultipleConstantsSingleClass\FooClass::class); + public function fooClass() : string { + return SingleAttributeMultipleConstantsSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/SingleAttributeMultiplePropertiesSingleClassFixture.php b/fixture_src/SingleAttributeMultiplePropertiesSingleClassFixture.php index 8bff306..fe30324 100644 --- a/fixture_src/SingleAttributeMultiplePropertiesSingleClassFixture.php +++ b/fixture_src/SingleAttributeMultiplePropertiesSingleClassFixture.php @@ -2,17 +2,14 @@ namespace Cspray\AnnotatedTargetFixture; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; - final class SingleAttributeMultiplePropertiesSingleClassFixture implements Fixture { public function getPath() : string { return __DIR__ . '/SingleAttributeMultiplePropertiesSingleClass'; } - public function fooClass() : ObjectType { - return objectType(SingleAttributeMultiplePropertiesSingleClass\FooClass::class); + public function fooClass() : string { + return SingleAttributeMultiplePropertiesSingleClass\FooClass::class; } } \ No newline at end of file diff --git a/fixture_src/TargetAttributeInterfaceFixture.php b/fixture_src/TargetAttributeInterfaceFixture.php index c8fc9e8..8c7ec98 100644 --- a/fixture_src/TargetAttributeInterfaceFixture.php +++ b/fixture_src/TargetAttributeInterfaceFixture.php @@ -3,8 +3,6 @@ namespace Cspray\AnnotatedTargetFixture; use Cspray\AnnotatedTargetFixture\TargetAttributeInterface\TargetClass; -use Cspray\Typiphy\ObjectType; -use function Cspray\Typiphy\objectType; final class TargetAttributeInterfaceFixture implements Fixture { @@ -12,7 +10,7 @@ public function getPath() : string { return __DIR__ . '/TargetAttributeInterface'; } - public function targetClass() : ObjectType { - return objectType(TargetClass::class); + public function targetClass() : string { + return TargetClass::class; } } \ No newline at end of file diff --git a/src/AnnotatedTargetParserOptions.php b/src/AnnotatedTargetParserOptions.php index af6a1f0..29439a0 100644 --- a/src/AnnotatedTargetParserOptions.php +++ b/src/AnnotatedTargetParserOptions.php @@ -2,17 +2,15 @@ namespace Cspray\AnnotatedTarget; -use Cspray\Typiphy\ObjectType; - interface AnnotatedTargetParserOptions { /** - * @return list + * @return non-empty-list */ public function sourceDirectories() : array; /** - * @return list + * @return non-empty-list */ public function attributeTypes() : array; diff --git a/src/AnnotatedTargetParserOptionsBuilder.php b/src/AnnotatedTargetParserOptionsBuilder.php index 50dc277..67ebb22 100644 --- a/src/AnnotatedTargetParserOptionsBuilder.php +++ b/src/AnnotatedTargetParserOptionsBuilder.php @@ -12,12 +12,15 @@ final class AnnotatedTargetParserOptionsBuilder { private function __construct() {} - public static function scanDirectories(string... $dirs) : self { + /** + * @param non-empty-list $dirs + * @return self + * @throws InvalidArgumentException + */ + public static function scanDirectories(array $dirs) : self { $instance = new self; foreach ($dirs as $dir) { - if (empty($dir)) { - throw new InvalidArgumentException('The directories to scan must not include an empty value.'); - } else if (!is_dir($dir)) { + if (!is_dir($dir)) { throw new InvalidArgumentException(sprintf("The value '%s' is not a directory.", $dir)); } @@ -26,10 +29,10 @@ public static function scanDirectories(string... $dirs) : self { return $instance; } - public function filterAttributes(ObjectType... $attributes) : self { - if (empty($attributes)) { - throw new InvalidArgumentException('The Attributes to filter by must not be empty.'); - } + /** + * @param non-empty-list $attributes + */ + public function filterAttributes(array $attributes) : self { $instance = clone $this; $instance->attributes = [...$this->attributes, ...$attributes]; return $instance; diff --git a/src/PhpParserAnnotatedTargetParser.php b/src/PhpParserAnnotatedTargetParser.php index 7ac2568..84bf011 100644 --- a/src/PhpParserAnnotatedTargetParser.php +++ b/src/PhpParserAnnotatedTargetParser.php @@ -75,9 +75,7 @@ private function getSourceIterator(AnnotatedTargetParserOptions $options) : Iter } private function getVisitor(callable $consumer, array $filteredAttributes) : NodeVisitor { - $filteredAttributes = array_map(fn($attr) => $attr->name(), $filteredAttributes); return new class($consumer, $filteredAttributes) extends NodeVisitorAbstract { - private $consumer; public function __construct(callable $consumer, private readonly array $filteredAttributes) { diff --git a/src/functions.php b/src/functions.php index 2c2cf76..05d63db 100644 --- a/src/functions.php +++ b/src/functions.php @@ -2,23 +2,24 @@ namespace Cspray\AnnotatedTarget; +use Cspray\AnnotatedTarget\Exception\InvalidArgumentException; +use Cspray\AnnotatedTarget\Exception\InvalidPhpSyntax; use Generator; -use function Cspray\Typiphy\objectType; /** - * @param list|non-empty-string $directories + * @param non-empty-list|non-empty-string $directories * @param list $filterAttributes * @return Generator - * @throws Exception\InvalidArgumentException + * @throws InvalidArgumentException + * @throws InvalidPhpSyntax */ function parseAttributes(array|string $directories, array $filterAttributes = []) : Generator { $parser = new PhpParserAnnotatedTargetParser(); $directories = is_string($directories) ? [$directories] : $directories; - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories(...$directories); - if (!empty($filterAttributes)) { - $attributeTypes = array_map(fn($type) => objectType($type), $filterAttributes); - $builder = $builder->filterAttributes(...$attributeTypes); + $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories($directories); + if ($filterAttributes !== []) { + $builder = $builder->filterAttributes($filterAttributes); } return $parser->parse($builder->build()); diff --git a/tests/Pest.php b/tests/Pest.php index 18797d0..5020d6c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,39 +1,16 @@ targetReflection() instanceof ReflectionClass && - $target->targetReflection()->getName() === $expectedClass->name(); + $target->targetReflection()->getName() === $expectedClass; }; -$checkTargetReflectionClassConstant = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedConst) : bool { +$checkTargetReflectionClassConstant = function(AnnotatedTarget $target, string $expectedClass, string $expectedConst) : bool { return $target->targetReflection() instanceof ReflectionClassConstant && - $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && $target->targetReflection()->getName() === $expectedConst; }; @@ -48,21 +25,21 @@ $target->targetReflection()->getName() === $expectedParam; }; -$checkTargetReflectionMethod = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedMethod) : bool { +$checkTargetReflectionMethod = function(AnnotatedTarget $target, string $expectedClass, string $expectedMethod) : bool { return $target->targetReflection() instanceof ReflectionMethod && - $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && $target->targetReflection()->getName() === $expectedMethod; }; -$checkTargetReflectionProperty = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedProp) : bool { +$checkTargetReflectionProperty = function(AnnotatedTarget $target, string $expectedClass, string $expectedProp) : bool { return $target->targetReflection() instanceof ReflectionProperty && - $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && $target->targetReflection()->getName() === $expectedProp; }; -$checkTargetReflectionMethodParameter = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedMethod, string $expectedParam) : bool { +$checkTargetReflectionMethodParameter = function(AnnotatedTarget $target, string $expectedClass, string $expectedMethod, string $expectedParam) : bool { return $target->targetReflection() instanceof ReflectionParameter && - $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass->name() && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && $target->targetReflection()->getDeclaringFunction()->getName() === $expectedMethod && $target->targetReflection()->getName() === $expectedParam; }; @@ -93,44 +70,44 @@ }); }); -expect()->extend('toContainTargetClass', function(ObjectType $expectedClass) use($checkTargetReflectionClass) { +expect()->extend('toContainTargetClass', function(string $expectedClass) use($checkTargetReflectionClass) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClass($item, $expectedClass) ); }); -expect()->extend('toContainTargetClassWithAttribute', function(ObjectType $expectedClass, ObjectType $expectedAttribute) use($checkTargetReflectionClass) { +expect()->extend('toContainTargetClassWithAttribute', function(string $expectedClass, string $expectedAttribute) use($checkTargetReflectionClass) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClass($item, $expectedClass) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetClassWithAttributeInstance', function(ObjectType $expectedClass, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionClass) { +expect()->extend('toContainTargetClassWithAttributeInstance', function(string $expectedClass, string $expectedAttribute, callable $callable) use($checkTargetReflectionClass) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClass($item, $expectedClass) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); -expect()->extend('toContainTargetClassConstant', function(ObjectType $expectedClass, string $expectedConst) use($checkTargetReflectionClassConstant) { +expect()->extend('toContainTargetClassConstant', function(string $expectedClass, string $expectedConst) use($checkTargetReflectionClassConstant) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClassConstant($item, $expectedClass, $expectedConst) ); }); -expect()->extend('toContainTargetClassConstantWithAttribute', function(ObjectType $expectedClass, string $expectedConst, ObjectType $expectedAttribute) use($checkTargetReflectionClassConstant) { +expect()->extend('toContainTargetClassConstantWithAttribute', function(string $expectedClass, string $expectedConst, string $expectedAttribute) use($checkTargetReflectionClassConstant) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClassConstant($item, $expectedClass, $expectedConst) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetClassConstantWithAttributeInstance', function(ObjectType $expectedClass, string $expectedConst, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionClassConstant) { +expect()->extend('toContainTargetClassConstantWithAttributeInstance', function(string $expectedClass, string $expectedConst, string $expectedAttribute, callable $callable) use($checkTargetReflectionClassConstant) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionClassConstant($item, $expectedClass, $expectedConst) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); @@ -141,17 +118,17 @@ ); }); -expect()->extend('toContainTargetFunctionWithAttribute', function(string $expectedFunction, ObjectType $expectedAttribute) use($checkTargetReflectionFunction) { +expect()->extend('toContainTargetFunctionWithAttribute', function(string $expectedFunction, string $expectedAttribute) use($checkTargetReflectionFunction) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunction($item, $expectedFunction) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetFunctionWithAttributeInstance', function(string $expectedFunction, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionFunction) { +expect()->extend('toContainTargetFunctionWithAttributeInstance', function(string $expectedFunction, string $expectedAttribute, callable $callable) use($checkTargetReflectionFunction) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunction($item, $expectedFunction) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); @@ -162,80 +139,80 @@ ); }); -expect()->extend('toContainTargetFunctionParameterWithAttribute', function(string $expectedFunction, string $expectedParam, ObjectType $expectedAttribute) use($checkTargetReflectionFunctionParameter) { +expect()->extend('toContainTargetFunctionParameterWithAttribute', function(string $expectedFunction, string $expectedParam, string $expectedAttribute) use($checkTargetReflectionFunctionParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunctionParameter($item, $expectedFunction, $expectedParam) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetFunctionParameterWithAttributeInstance', function(string $expectedFunction, string $expectedParam, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionFunctionParameter) { +expect()->extend('toContainTargetFunctionParameterWithAttributeInstance', function(string $expectedFunction, string $expectedParam, string $expectedAttribute, callable $callable) use($checkTargetReflectionFunctionParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionFunctionParameter($item, $expectedFunction, $expectedParam) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); -expect()->extend('toContainTargetMethod', function(ObjectType $expectedClass, string $expectedMethod) use($checkTargetReflectionMethod) { +expect()->extend('toContainTargetMethod', function(string $expectedClass, string $expectedMethod) use($checkTargetReflectionMethod) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethod($item, $expectedClass, $expectedMethod) ); }); -expect()->extend('toContainTargetMethodWithAttribute', function(ObjectType $expectedClass, string $expectedMethod, ObjectType $expectedAttribute) use($checkTargetReflectionMethod) { +expect()->extend('toContainTargetMethodWithAttribute', function(string $expectedClass, string $expectedMethod, string $expectedAttribute) use($checkTargetReflectionMethod) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethod($item, $expectedClass, $expectedMethod) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetMethodWithAttributeInstance', function(ObjectType $expectedClass, string $expectedMethod, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionMethod) { +expect()->extend('toContainTargetMethodWithAttributeInstance', function(string $expectedClass, string $expectedMethod, string $expectedAttribute, callable $callable) use($checkTargetReflectionMethod) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethod($item, $expectedClass, $expectedMethod) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); -expect()->extend('toContainTargetProperty', function(ObjectType $expectedClass, string $expectedProp) use($checkTargetReflectionProperty) { +expect()->extend('toContainTargetProperty', function(string $expectedClass, string $expectedProp) use($checkTargetReflectionProperty) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionProperty($item, $expectedClass, $expectedProp) ); }); -expect()->extend('toContainTargetPropertyWithAttribute', function(ObjectType $expectedClass, string $expectedProp, ObjectType $expectedAttribute) use($checkTargetReflectionProperty) { +expect()->extend('toContainTargetPropertyWithAttribute', function(string $expectedClass, string $expectedProp, string $expectedAttribute) use($checkTargetReflectionProperty) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionProperty($item, $expectedClass, $expectedProp) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetPropertyWithAttributeInstance', function(ObjectType $expectedClass, string $expectedProp, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionProperty) { +expect()->extend('toContainTargetPropertyWithAttributeInstance', function(string $expectedClass, string $expectedProp, string $expectedAttribute, callable $callable) use($checkTargetReflectionProperty) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionProperty($item, $expectedClass, $expectedProp) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); -expect()->extend('toContainTargetMethodParameter', function(ObjectType $expectedClass, string $expectedMethod, string $expectedParam) use($checkTargetReflectionMethodParameter) { +expect()->extend('toContainTargetMethodParameter', function(string $expectedClass, string $expectedMethod, string $expectedParam) use($checkTargetReflectionMethodParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethodParameter($item, $expectedClass, $expectedMethod, $expectedParam) ); }); -expect()->extend('toContainTargetMethodParameterWithAttribute', function(ObjectType $expectedClass, string $expectedMethod, string $expectedParam, ObjectType $expectedAttribute) use($checkTargetReflectionMethodParameter) { +expect()->extend('toContainTargetMethodParameterWithAttribute', function(string $expectedClass, string $expectedMethod, string $expectedParam, string $expectedAttribute) use($checkTargetReflectionMethodParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethodParameter($item, $expectedClass, $expectedMethod, $expectedParam) && - $item->attributeReflection()->getName() === $expectedAttribute->name() + $item->attributeReflection()->getName() === $expectedAttribute ); }); -expect()->extend('toContainTargetMethodParameterWithAttributeInstance', function(ObjectType $expectedClass, string $expectedMethod, string $expectedParam, ObjectType $expectedAttribute, callable $callable) use($checkTargetReflectionMethodParameter) { +expect()->extend('toContainTargetMethodParameterWithAttributeInstance', function(string $expectedClass, string $expectedMethod, string $expectedParam, string $expectedAttribute, callable $callable) use($checkTargetReflectionMethodParameter) { return $this->toContainAny( fn(AnnotatedTarget $item) => $checkTargetReflectionMethodParameter($item, $expectedClass, $expectedMethod, $expectedParam) && - $item->attributeReflection()->getName() === $expectedAttribute->name() && + $item->attributeReflection()->getName() === $expectedAttribute && $callable($item->attributeInstance()) ); }); @@ -261,14 +238,3 @@ Assert::assertTrue(true); return $this; }); - -/* -|-------------------------------------------------------------------------- -| Functions -|-------------------------------------------------------------------------- -| -| While Pest is very powerful out-of-the-box, you may have some testing code specific to your -| project that you don't want to repeat in every file. Here you can also expose helpers as -| global functions to help you to reduce the number of lines of code in your test files. -| -*/ diff --git a/tests/Unit/AliasedAttributeTest.php b/tests/Unit/AliasedAttributeTest.php index befb0f1..1c58ad6 100644 --- a/tests/Unit/AliasedAttributeTest.php +++ b/tests/Unit/AliasedAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -36,12 +35,12 @@ it('includes attribute reflection class') ->expect(fn() => $this->getTargets()) - ->toContainTargetClassWithAttribute(Fixtures::aliasedAttribute()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::aliasedAttribute()->fooClass(), ClassOnly::class); it('includes attribute instance with correct value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::aliasedAttribute()->fooClass(), - objectType(ClassOnly::class), + ClassOnly::class, fn(ClassOnly $classOnly) => $classOnly->value === 'my aliased value' ); diff --git a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php b/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php index c884200..ea501e2 100644 --- a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php +++ b/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php @@ -7,52 +7,43 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\MethodOnly; -use function Cspray\Typiphy\objectType; - -it('throws exception if directories is empty', function() { - AnnotatedTargetParserOptionsBuilder::scanDirectories(''); -})->throws(InvalidArgumentException::class, 'The directories to scan must not include an empty value.'); it('throws exception if directories is not a directory', function() { - AnnotatedTargetParserOptionsBuilder::scanDirectories('not-dir'); + AnnotatedTargetParserOptionsBuilder::scanDirectories(['not-dir']); })->throws(InvalidArgumentException::class, "The value 'not-dir' is not a directory."); -it('throws exception if attributes is empty', function() { - AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath())->filterAttributes(); -})->throws(InvalidArgumentException::class, 'The Attributes to filter by must not be empty.'); - it('has scan directories in options') ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath())->build(); + $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()])->build(); return $options->sourceDirectories(); }) ->toBe([Fixtures::classOnlyAttributeSingleClass()->getPath()]); it('has different instance for filterAttributes', function() { - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath()); - $filterBuilder = $builder->filterAttributes(objectType(ClassOnly::class)); + $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()]); + $filterBuilder = $builder->filterAttributes([ClassOnly::class]); expect($builder)->not->toBe($filterBuilder); }); it('has empty filterAttributes in options') ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath())->build(); + $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()])->build(); return $options->attributeTypes(); })->toBeEmpty(); it('has populated filterAttributes in options') ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath()) - ->filterAttributes(objectType(ClassOnly::class)) + $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()]) + ->filterAttributes([ClassOnly::class]) ->build(); return $options->attributeTypes(); - })->toBe([objectType(ClassOnly::class)]); + })->toBe([ClassOnly::class]); it('has populated filterAttributes in options, when chained') ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath()) - ->filterAttributes(objectType(ClassOnly::class)) - ->filterAttributes(objectType(MethodOnly::class)) + $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()]) + ->filterAttributes([ClassOnly::class]) + ->filterAttributes([MethodOnly::class]) ->build(); return $options->attributeTypes(); - })->toBe([objectType(ClassOnly::class), objectType(MethodOnly::class)]); \ No newline at end of file + })->toBe([ClassOnly::class, MethodOnly::class]); \ No newline at end of file diff --git a/tests/Unit/AnnotatedTargetParserTestCase.php b/tests/Unit/AnnotatedTargetParserTestCase.php index f3f2e8f..d639832 100644 --- a/tests/Unit/AnnotatedTargetParserTestCase.php +++ b/tests/Unit/AnnotatedTargetParserTestCase.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTarget\AnnotatedTargetParserOptionsBuilder; use Cspray\AnnotatedTarget\PhpParserAnnotatedTargetParser; use Cspray\AnnotatedTargetFixture\Fixture; -use Cspray\Typiphy\ObjectType; use PHPUnit\Framework\TestCase; abstract class AnnotatedTargetParserTestCase extends TestCase { @@ -22,9 +21,9 @@ public function getTargets() : array { throw new \BadMethodCallException('Before running any assertions on this test case you must provide a Fixture to load.'); } $paths = array_map(fn(Fixture $fixture) => $fixture->getPath(), $this->fixtures); - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories(...$paths); + $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories($paths); if (isset($this->attributes)) { - $builder = $builder->filterAttributes(...$this->attributes); + $builder = $builder->filterAttributes($this->attributes); } return iterator_to_array($this->getSubject()->parse($builder->build())); } @@ -34,7 +33,11 @@ public function withFixtures(Fixture... $fixtures) : self { return $this; } - public function withFilteredAttributes(ObjectType... $attributes) : self { + /** + * @param class-string ...$attributes + * @return $this + */ + public function withFilteredAttributes(string... $attributes) : self { $this->attributes = $attributes; return $this; } diff --git a/tests/Unit/ClassOnlyAttributeGroupTest.php b/tests/Unit/ClassOnlyAttributeGroupTest.php index 8bb1876..16884fa 100644 --- a/tests/Unit/ClassOnlyAttributeGroupTest.php +++ b/tests/Unit/ClassOnlyAttributeGroupTest.php @@ -38,43 +38,43 @@ it('includes grouped attribute reflection class') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttribute( - Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), objectType(RepeatableClassOnly::class) + Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), RepeatableClassOnly::class ); it('includes single attribute reflection class') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttribute( - Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), objectType(ClassOnly::class) + Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), ClassOnly::class ); it('includes attribute instance with correct first value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'foo' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'foo' ); it('includes attribute instance with correct second value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'bar' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'bar' ); it('includes ungrouped attribute instance with correct value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'baz' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'baz' ); it('includes attribute instance with correct third value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeGroupSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'qux' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'qux' ); diff --git a/tests/Unit/ClassOnlyAttributeTest.php b/tests/Unit/ClassOnlyAttributeTest.php index efd0b4f..e31e1d1 100644 --- a/tests/Unit/ClassOnlyAttributeTest.php +++ b/tests/Unit/ClassOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -36,12 +35,12 @@ it('includes attribute reflection class') ->expect(fn() => $this->getTargets()) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class); it('includes attribute instance with correct value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeSingleClass()->fooClass(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' ); \ No newline at end of file diff --git a/tests/Unit/ClassOnlyInterfaceAttributeTest.php b/tests/Unit/ClassOnlyInterfaceAttributeTest.php index d74bb0c..694ff37 100644 --- a/tests/Unit/ClassOnlyInterfaceAttributeTest.php +++ b/tests/Unit/ClassOnlyInterfaceAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -36,12 +35,12 @@ it('includes attribute reflection class') ->expect(fn() => $this->getTargets()) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleInterface()->fooInterface(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleInterface()->fooInterface(), ClassOnly::class); it('includes attribute instance with correct value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeSingleInterface()->fooInterface(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'foo' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'foo' ); \ No newline at end of file diff --git a/tests/Unit/ConstantOnlyAttributeTest.php b/tests/Unit/ConstantOnlyAttributeTest.php index acc4d01..f41a68b 100644 --- a/tests/Unit/ConstantOnlyAttributeTest.php +++ b/tests/Unit/ConstantOnlyAttributeTest.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTarget\Unit\AnnotatedTargetParserTestCase; use Cspray\AnnotatedTargetFixture\ConstantOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -40,12 +39,12 @@ it('contains target reflection class constant with attribute') ->expect(fn() => $this->getTargets()) ->toContainTargetClassConstantWithAttribute( - Fixtures::constantOnlyAttributeGroupSingleClass()->fooClass(), 'BAR', objectType(ConstantOnly::class) + Fixtures::constantOnlyAttributeGroupSingleClass()->fooClass(), 'BAR', ConstantOnly::class ); it('contains target reflection class constant with attribute instance') ->expect(fn() => $this->getTargets()) ->toContainTargetClassConstantWithAttributeInstance( - Fixtures::constantOnlyAttributeGroupSingleClass()->fooClass(), 'BAR', objectType(ConstantOnly::class), + Fixtures::constantOnlyAttributeGroupSingleClass()->fooClass(), 'BAR', ConstantOnly::class, fn(ConstantOnly $constantOnly) => $constantOnly->value === 'getting the constant' ); \ No newline at end of file diff --git a/tests/Unit/FilterAttributeTest.php b/tests/Unit/FilterAttributeTest.php index acbc51e..d51e891 100644 --- a/tests/Unit/FilterAttributeTest.php +++ b/tests/Unit/FilterAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -12,7 +11,7 @@ Fixtures::classOnlyAttributeSingleClass(), Fixtures::propertyOnlyAttributeSingleClass(), Fixtures::methodOnlyAttributeSingleClass() -)->withFilteredAttributes(objectType(ClassOnly::class)); +)->withFilteredAttributes(ClassOnly::class); $targets = fn() => $this->getTargets(); @@ -42,12 +41,12 @@ it('includes attribute reflection class') ->expect($targets) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class); it('includes attribute instance with correct value') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeSingleClass()->fooClass(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' ); diff --git a/tests/Unit/FunctionOnlyAttributeTest.php b/tests/Unit/FunctionOnlyAttributeTest.php index 5f7aa13..89bbaff 100644 --- a/tests/Unit/FunctionOnlyAttributeTest.php +++ b/tests/Unit/FunctionOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\FunctionOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -37,12 +36,12 @@ it('contains target reflection function and reflection attribute') ->expect(fn() => $this->getTargets()) ->toContainTargetFunctionWithAttribute( - Fixtures::functionOnlyAttributeSingleFunction()->fooFunction(), objectType(FunctionOnly::class) + Fixtures::functionOnlyAttributeSingleFunction()->fooFunction(), FunctionOnly::class ); it('contains target reflection function and attribute instance') ->expect(fn() => $this->getTargets()) ->toContainTargetFunctionWithAttributeInstance( - Fixtures::functionOnlyAttributeSingleFunction()->fooFunction(), objectType(FunctionOnly::class), - fn(FunctionOnly $functionOnly) => $functionOnly->value === 'would a crazy person do this?' + Fixtures::functionOnlyAttributeSingleFunction()->fooFunction(), FunctionOnly::class, + static fn(FunctionOnly $functionOnly) => $functionOnly->value === 'would a crazy person do this?' ); \ No newline at end of file diff --git a/tests/Unit/FunctionParameterOnlyAttributeTest.php b/tests/Unit/FunctionParameterOnlyAttributeTest.php index 70ed3e0..eb29998 100644 --- a/tests/Unit/FunctionParameterOnlyAttributeTest.php +++ b/tests/Unit/FunctionParameterOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\ParameterOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -41,12 +40,12 @@ it('contains target reflection and attribute') ->expect($targets) ->toContainTargetFunctionParameterWithAttribute( - Fixtures::functionParameterOnlyAttributeSingleFunction()->fooFunction(), 'param', objectType(ParameterOnly::class) + Fixtures::functionParameterOnlyAttributeSingleFunction()->fooFunction(), 'param', ParameterOnly::class ); it('contains target reflection and attribute instance') ->expect($targets) ->toContainTargetFunctionParameterWithAttributeInstance( - Fixtures::functionParameterOnlyAttributeSingleFunction()->fooFunction(), 'param', objectType(ParameterOnly::class), + Fixtures::functionParameterOnlyAttributeSingleFunction()->fooFunction(), 'param', ParameterOnly::class, fn(ParameterOnly $parameterOnly) => $parameterOnly->value === 'awesome' ); \ No newline at end of file diff --git a/tests/Unit/MethodOnlyAttributeTest.php b/tests/Unit/MethodOnlyAttributeTest.php index a86b9c6..d90f487 100644 --- a/tests/Unit/MethodOnlyAttributeTest.php +++ b/tests/Unit/MethodOnlyAttributeTest.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTarget\Unit\AnnotatedTargetParserTestCase; use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\MethodOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -42,12 +41,12 @@ it('has target reflection method and attribute') ->expect($targets) ->toContainTargetMethodWithAttribute( - Fixtures::methodOnlyAttributeSingleClass()->fooClass(), 'myMethod', objectType(MethodOnly::class) + Fixtures::methodOnlyAttributeSingleClass()->fooClass(), 'myMethod', MethodOnly::class ); it('has target method and attribute instance') ->expect($targets) ->toContainTargetMethodWithAttributeInstance( - Fixtures::methodOnlyAttributeSingleClass()->fooClass(), 'myMethod', objectType(MethodOnly::class), + Fixtures::methodOnlyAttributeSingleClass()->fooClass(), 'myMethod', MethodOnly::class, fn(MethodOnly $methodOnly) => $methodOnly->value === 'is the coolest method' ); diff --git a/tests/Unit/MultipleDifferentClassOnlyAttributeTest.php b/tests/Unit/MultipleDifferentClassOnlyAttributeTest.php index 49735e6..4746aa6 100644 --- a/tests/Unit/MultipleDifferentClassOnlyAttributeTest.php +++ b/tests/Unit/MultipleDifferentClassOnlyAttributeTest.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\RepeatableClassOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -41,36 +40,36 @@ ->expect($targets) ->toContainTargetClassWithAttribute( Fixtures::multipleDifferentClassOnlyAttributeSingleClass()->fooClass(), - objectType(ClassOnly::class) + ClassOnly::class ); it('includes attribute reflection class for repeatable class only') ->expect($targets) ->toContainTargetClassWithAttribute( Fixtures::multipleDifferentClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class) + RepeatableClassOnly::class ); it('includes attribute instance for class only') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::multipleDifferentClassOnlyAttributeSingleClass()->fooClass(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'foo' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'foo' ); it('includes attribute instance for first repeatable class only') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::multipleDifferentClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'bar' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'bar' ); it('includes attribute instance for second repeatable class only') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::multipleDifferentClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'baz' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'baz' ); \ No newline at end of file diff --git a/tests/Unit/MultipleDirectoryTest.php b/tests/Unit/MultipleDirectoryTest.php index d825967..4b72a79 100644 --- a/tests/Unit/MultipleDirectoryTest.php +++ b/tests/Unit/MultipleDirectoryTest.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\PropertyOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -39,12 +38,12 @@ it('contains class attribute target and attribute') ->expect($targets) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class); it('contains class attribute target and attribute instance') ->expect($targets) ->toContainTargetClassWithAttributeInstance( - Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class), + Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class, fn($classOnly) => $classOnly instanceof ClassOnly && $classOnly->value === 'single-class-foobar' ); @@ -57,12 +56,12 @@ it('contains property attribute target and attribute') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', objectType(PropertyOnly::class) + Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', PropertyOnly::class ); it('contains property attribute target and attribute instance') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', objectType(PropertyOnly::class), - fn($propertyOnly) => $propertyOnly instanceof PropertyOnly && $propertyOnly->value === 'nick' + Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', PropertyOnly::class, + static fn($propertyOnly) => $propertyOnly instanceof PropertyOnly && $propertyOnly->value === 'nick' ); \ No newline at end of file diff --git a/tests/Unit/NonPhpFileTest.php b/tests/Unit/NonPhpFileTest.php index 189417f..37aea36 100644 --- a/tests/Unit/NonPhpFileTest.php +++ b/tests/Unit/NonPhpFileTest.php @@ -38,11 +38,11 @@ it('contains target class and attribute') ->expect($targets) - ->toContainTargetClassWithAttribute(Fixtures::nonPhpFile()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::nonPhpFile()->fooClass(), ClassOnly::class); it('contains target class and attribute instance') ->expect($targets) ->toContainTargetClassWithAttributeInstance( - Fixtures::nonPhpFile()->fooClass(), objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'the one' + Fixtures::nonPhpFile()->fooClass(), ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'the one' ); \ No newline at end of file diff --git a/tests/Unit/ParameterOnlyAttributeTest.php b/tests/Unit/ParameterOnlyAttributeTest.php index 41ed685..42c11e6 100644 --- a/tests/Unit/ParameterOnlyAttributeTest.php +++ b/tests/Unit/ParameterOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\ParameterOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -41,12 +40,12 @@ it('contains target reflection and attribute') ->expect($targets) ->toContainTargetMethodParameterWithAttribute( - Fixtures::parameterOnlyAttributeSingleClass()->fooClass(), 'myMethod', 'myParam', objectType(ParameterOnly::class) + Fixtures::parameterOnlyAttributeSingleClass()->fooClass(), 'myMethod', 'myParam', ParameterOnly::class ); it('contains target reflection and attribute instance') ->expect($targets) ->toContainTargetMethodParameterWithAttributeInstance( - Fixtures::parameterOnlyAttributeSingleClass()->fooClass(), 'myMethod', 'myParam', objectType(ParameterOnly::class), + Fixtures::parameterOnlyAttributeSingleClass()->fooClass(), 'myMethod', 'myParam', ParameterOnly::class, fn(ParameterOnly $parameterOnly) => $parameterOnly->value === 'myParamValue' ); \ No newline at end of file diff --git a/tests/Unit/ParseAttributesMultipleDirectoryTest.php b/tests/Unit/ParseAttributesMultipleDirectoryTest.php index 9409a46..525fe3d 100644 --- a/tests/Unit/ParseAttributesMultipleDirectoryTest.php +++ b/tests/Unit/ParseAttributesMultipleDirectoryTest.php @@ -6,7 +6,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\PropertyOnly; use function Cspray\AnnotatedTarget\parseAttributes; -use function Cspray\Typiphy\objectType; $targets = fn() => iterator_to_array(parseAttributes([Fixtures::classOnlyAttributeSingleClass()->getPath(), Fixtures::propertyOnlyAttributeSingleClass()->getPath()])); @@ -36,13 +35,13 @@ it('contains class attribute target and attribute') ->expect($targets) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class); it('contains class attribute target and attribute instance') ->expect($targets) ->toContainTargetClassWithAttributeInstance( - Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class), - fn($classOnly) => $classOnly instanceof ClassOnly && $classOnly->value === 'single-class-foobar' + Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class, + static fn($classOnly) => $classOnly instanceof ClassOnly && $classOnly->value === 'single-class-foobar' ); it('contains property attribute target') @@ -54,12 +53,12 @@ it('contains property attribute target and attribute') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', objectType(PropertyOnly::class) + Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', PropertyOnly::class ); it('contains property attribute target and attribute instance') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', objectType(PropertyOnly::class), - fn($propertyOnly) => $propertyOnly instanceof PropertyOnly && $propertyOnly->value === 'nick' + Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', PropertyOnly::class, + static fn($propertyOnly) => $propertyOnly instanceof PropertyOnly && $propertyOnly->value === 'nick' ); \ No newline at end of file diff --git a/tests/Unit/ParseAttributesSingleDirectoryTest.php b/tests/Unit/ParseAttributesSingleDirectoryTest.php index 67e3540..aa4c0ab 100644 --- a/tests/Unit/ParseAttributesSingleDirectoryTest.php +++ b/tests/Unit/ParseAttributesSingleDirectoryTest.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; use function Cspray\AnnotatedTarget\parseAttributes; -use function Cspray\Typiphy\objectType; $targets = fn() => iterator_to_array(parseAttributes(Fixtures::classOnlyAttributeSingleClass()->getPath())); @@ -35,12 +34,12 @@ it('includes attribute reflection class') ->expect($targets) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class); it('includes attribute instance with correct value') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeSingleClass()->fooClass(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' ); diff --git a/tests/Unit/ParserAttributesFilterAttributeTest.php b/tests/Unit/ParserAttributesFilterAttributeTest.php index 256de82..ea198d6 100644 --- a/tests/Unit/ParserAttributesFilterAttributeTest.php +++ b/tests/Unit/ParserAttributesFilterAttributeTest.php @@ -5,7 +5,6 @@ use Cspray\AnnotatedTargetFixture\ClassOnly; use Cspray\AnnotatedTargetFixture\Fixtures; use function Cspray\AnnotatedTarget\parseAttributes; -use function Cspray\Typiphy\objectType; $targets = fn() => iterator_to_array(parseAttributes( [Fixtures::classOnlyAttributeSingleClass()->getPath(), Fixtures::propertyOnlyAttributeSingleClass()->getPath(), Fixtures::methodOnlyAttributeSingleClass()->getPath()], @@ -38,12 +37,12 @@ it('includes attribute reflection class') ->expect($targets) - ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), objectType(ClassOnly::class)); + ->toContainTargetClassWithAttribute(Fixtures::classOnlyAttributeSingleClass()->fooClass(), ClassOnly::class); it('includes attribute instance with correct value') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::classOnlyAttributeSingleClass()->fooClass(), - objectType(ClassOnly::class), - fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' + ClassOnly::class, + static fn(ClassOnly $classOnly) => $classOnly->value === 'single-class-foobar' ); diff --git a/tests/Unit/PropertyOnlyAttributeTest.php b/tests/Unit/PropertyOnlyAttributeTest.php index a012d72..c560d4b 100644 --- a/tests/Unit/PropertyOnlyAttributeTest.php +++ b/tests/Unit/PropertyOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\PropertyOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -41,12 +40,12 @@ it('includes attribute reflection property') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', objectType(PropertyOnly::class) + Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', PropertyOnly::class ); it('includes attribute instance value') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', objectType(PropertyOnly::class), - fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'nick' + Fixtures::propertyOnlyAttributeSingleClass()->fooClass(), 'prop', PropertyOnly::class, + static fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'nick' ); diff --git a/tests/Unit/RepeatableClassOnlyAttributeTest.php b/tests/Unit/RepeatableClassOnlyAttributeTest.php index 17d144b..dd85d30 100644 --- a/tests/Unit/RepeatableClassOnlyAttributeTest.php +++ b/tests/Unit/RepeatableClassOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\RepeatableClassOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -40,29 +39,29 @@ ->expect($targets) ->toContainTargetClassWithAttribute( Fixtures::repeatableClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class) + RepeatableClassOnly::class ); it('includes first attribute value') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::repeatableClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'foo' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'foo' ); it('includes second attribute value') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::repeatableClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'bar' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'bar' ); it('includes third attribute value') ->expect($targets) ->toContainTargetClassWithAttributeInstance( Fixtures::repeatableClassOnlyAttributeSingleClass()->fooClass(), - objectType(RepeatableClassOnly::class), - fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'baz' + RepeatableClassOnly::class, + static fn(RepeatableClassOnly $classOnly) => $classOnly->value === 'baz' ); \ No newline at end of file diff --git a/tests/Unit/RepeatableConstantOnlyAttributeTest.php b/tests/Unit/RepeatableConstantOnlyAttributeTest.php index 92a1ae5..076c049 100644 --- a/tests/Unit/RepeatableConstantOnlyAttributeTest.php +++ b/tests/Unit/RepeatableConstantOnlyAttributeTest.php @@ -2,10 +2,8 @@ namespace Cspray\AnnotatedTarget\Unit; -use Cspray\AnnotatedTargetFixture\Fixture; use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\RepeatableConstantOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -42,19 +40,19 @@ it('contains target reflection class constant with attribute') ->expect($targets) ->toContainTargetClassConstantWithAttribute( - Fixtures::repeatableConstantOnlyAttributeSingleClass()->fooClass(), 'FOO_BAR', objectType(RepeatableConstantOnly::class) + Fixtures::repeatableConstantOnlyAttributeSingleClass()->fooClass(), 'FOO_BAR', RepeatableConstantOnly::class ); it('contains target reflection class constant with first attribute instance') ->expect($targets) ->toContainTargetClassConstantWithAttributeInstance( - Fixtures::repeatableConstantOnlyAttributeSingleClass()->fooClass(), 'FOO_BAR', objectType(RepeatableConstantOnly::class), - fn(RepeatableConstantOnly $constantOnly) => $constantOnly->value === 'one' + Fixtures::repeatableConstantOnlyAttributeSingleClass()->fooClass(), 'FOO_BAR', RepeatableConstantOnly::class, + static fn(RepeatableConstantOnly $constantOnly) => $constantOnly->value === 'one' ); it('contains target reflection class constant with second attribute instance') ->expect($targets) ->toContainTargetClassConstantWithAttributeInstance( - Fixtures::repeatableConstantOnlyAttributeSingleClass()->fooClass(), 'FOO_BAR', objectType(RepeatableConstantOnly::class), - fn(RepeatableConstantOnly $constantOnly) => $constantOnly->value === 'two' + Fixtures::repeatableConstantOnlyAttributeSingleClass()->fooClass(), 'FOO_BAR', RepeatableConstantOnly::class, + static fn(RepeatableConstantOnly $constantOnly) => $constantOnly->value === 'two' ); diff --git a/tests/Unit/RepeatableFunctionOnlyAttributeTest.php b/tests/Unit/RepeatableFunctionOnlyAttributeTest.php index dc608d4..9e21ab2 100644 --- a/tests/Unit/RepeatableFunctionOnlyAttributeTest.php +++ b/tests/Unit/RepeatableFunctionOnlyAttributeTest.php @@ -3,9 +3,7 @@ namespace Cspray\AnnotatedTarget\Unit; use Cspray\AnnotatedTargetFixture\Fixtures; -use Cspray\AnnotatedTargetFixture\FunctionOnly; use Cspray\AnnotatedTargetFixture\RepeatableFunctionOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -40,19 +38,19 @@ it('contains target reflection function and reflection attribute') ->expect($targets) ->toContainTargetFunctionWithAttribute( - Fixtures::repeatableFunctionOnlyAttributeSingleFunction()->fooFunction(), objectType(RepeatableFunctionOnly::class) + Fixtures::repeatableFunctionOnlyAttributeSingleFunction()->fooFunction(), RepeatableFunctionOnly::class ); it('contains target reflection function and first attribute instance') ->expect($targets) ->toContainTargetFunctionWithAttributeInstance( - Fixtures::repeatableFunctionOnlyAttributeSingleFunction()->fooFunction(), objectType(RepeatableFunctionOnly::class), - fn(RepeatableFunctionOnly $functionOnly) => $functionOnly->value === 'nick' + Fixtures::repeatableFunctionOnlyAttributeSingleFunction()->fooFunction(), RepeatableFunctionOnly::class, + static fn(RepeatableFunctionOnly $functionOnly) => $functionOnly->value === 'nick' ); it('contains target reflection function and second attribute instance') ->expect($targets) ->toContainTargetFunctionWithAttributeInstance( - Fixtures::repeatableFunctionOnlyAttributeSingleFunction()->fooFunction(), objectType(RepeatableFunctionOnly::class), - fn(RepeatableFunctionOnly $functionOnly) => $functionOnly->value === 'xoe' + Fixtures::repeatableFunctionOnlyAttributeSingleFunction()->fooFunction(), RepeatableFunctionOnly::class, + static fn(RepeatableFunctionOnly $functionOnly) => $functionOnly->value === 'xoe' ); diff --git a/tests/Unit/RepeatableMethodOnlyAttributeTest.php b/tests/Unit/RepeatableMethodOnlyAttributeTest.php index 2fdd4c0..40354f3 100644 --- a/tests/Unit/RepeatableMethodOnlyAttributeTest.php +++ b/tests/Unit/RepeatableMethodOnlyAttributeTest.php @@ -6,7 +6,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\MethodOnly; use Cspray\AnnotatedTargetFixture\RepeatableMethodOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -43,25 +42,25 @@ it('contains target reflection method and first attribute') ->expect($targets) ->toContainTargetMethodWithAttribute( - Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', objectType(MethodOnly::class) + Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', MethodOnly::class ); it('contains target reflection method and second attribute') ->expect($targets) ->toContainTargetMethodWithAttribute( - Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', objectType(RepeatableMethodOnly::class) + Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', RepeatableMethodOnly::class ); it('contains target reflection method and first attribute instance') ->expect($targets) ->toContainTargetMethodWithAttributeInstance( - Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', objectType(MethodOnly::class), - fn(MethodOnly $methodOnly) => $methodOnly->value === 'methodOnly' + Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', MethodOnly::class, + static fn(MethodOnly $methodOnly) => $methodOnly->value === 'methodOnly' ); it('contains target reflection method and second attribute instance') ->expect($targets) ->toContainTargetMethodWithAttributeInstance( - Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', objectType(RepeatableMethodOnly::class), - fn(RepeatableMethodOnly $methodOnly) => $methodOnly->value === 'repeatableMethodOnly' + Fixtures::repeatableMethodOnlyAttributeSingleClass()->fooClass(), 'theirMethod', RepeatableMethodOnly::class, + static fn(RepeatableMethodOnly $methodOnly) => $methodOnly->value === 'repeatableMethodOnly' ); \ No newline at end of file diff --git a/tests/Unit/RepeatableParameterOnlyAttributeTest.php b/tests/Unit/RepeatableParameterOnlyAttributeTest.php index 8ddf5d2..6d8e9ee 100644 --- a/tests/Unit/RepeatableParameterOnlyAttributeTest.php +++ b/tests/Unit/RepeatableParameterOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\RepeatableParameterOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -41,19 +40,19 @@ it('contains target reflection and attribute') ->expect($targets) ->toContainTargetMethodParameterWithAttribute( - Fixtures::repeatableParameterOnlyAttributeSingleClass()->fooClass(), '__construct', 'baz', objectType(RepeatableParameterOnly::class) + Fixtures::repeatableParameterOnlyAttributeSingleClass()->fooClass(), '__construct', 'baz', RepeatableParameterOnly::class ); it('contains first target reflection and attribute instance') ->expect($targets) ->toContainTargetMethodParameterWithAttributeInstance( - Fixtures::repeatableParameterOnlyAttributeSingleClass()->fooClass(), '__construct', 'baz', objectType(RepeatableParameterOnly::class), - fn(RepeatableParameterOnly $parameterOnly) => $parameterOnly->value === 'foo' + Fixtures::repeatableParameterOnlyAttributeSingleClass()->fooClass(), '__construct', 'baz', RepeatableParameterOnly::class, + static fn(RepeatableParameterOnly $parameterOnly) => $parameterOnly->value === 'foo' ); it('contains second target reflection and attribute instance') ->expect($targets) ->toContainTargetMethodParameterWithAttributeInstance( - Fixtures::repeatableParameterOnlyAttributeSingleClass()->fooClass(), '__construct', 'baz', objectType(RepeatableParameterOnly::class), - fn(RepeatableParameterOnly $parameterOnly) => $parameterOnly->value === 'bar' + Fixtures::repeatableParameterOnlyAttributeSingleClass()->fooClass(), '__construct', 'baz', RepeatableParameterOnly::class, + static fn(RepeatableParameterOnly $parameterOnly) => $parameterOnly->value === 'bar' ); diff --git a/tests/Unit/RepeatablePropertyOnlyAttributeTest.php b/tests/Unit/RepeatablePropertyOnlyAttributeTest.php index 8445030..ade8f5f 100644 --- a/tests/Unit/RepeatablePropertyOnlyAttributeTest.php +++ b/tests/Unit/RepeatablePropertyOnlyAttributeTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\RepeatablePropertyOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -41,26 +40,26 @@ it('includes attribute reflection') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', objectType(RepeatablePropertyOnly::class) + Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', RepeatablePropertyOnly::class ); it('includes first attribute instance value') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', objectType(RepeatablePropertyOnly::class), - fn(RepeatablePropertyOnly $propertyOnly) => $propertyOnly->value === 'Archer' + Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', RepeatablePropertyOnly::class, + static fn(RepeatablePropertyOnly $propertyOnly) => $propertyOnly->value === 'Archer' ); it('includes second attribute instance value') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', objectType(RepeatablePropertyOnly::class), - fn(RepeatablePropertyOnly $propertyOnly) => $propertyOnly->value === 'Lana' + Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', RepeatablePropertyOnly::class, + static fn(RepeatablePropertyOnly $propertyOnly) => $propertyOnly->value === 'Lana' ); it('includes third attribute instance value') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', objectType(RepeatablePropertyOnly::class), - fn(RepeatablePropertyOnly $propertyOnly) => $propertyOnly->value === 'Ray' + Fixtures::repeatablePropertyOnlyAttributeSingleClass()->fooClass(), 'something', RepeatablePropertyOnly::class, + static fn(RepeatablePropertyOnly $propertyOnly) => $propertyOnly->value === 'Ray' ); diff --git a/tests/Unit/SingleAttributeMultipleConstantsPropertyTest.php b/tests/Unit/SingleAttributeMultipleConstantsPropertyTest.php index d7f72d3..c78c6cb 100644 --- a/tests/Unit/SingleAttributeMultipleConstantsPropertyTest.php +++ b/tests/Unit/SingleAttributeMultipleConstantsPropertyTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\ConstantOnly; use Cspray\AnnotatedTargetFixture\Fixtures; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -48,25 +47,25 @@ it('contains first target reflection class constant with attribute') ->expect($targets) ->toContainTargetClassConstantWithAttribute( - Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'FOO', objectType(ConstantOnly::class) + Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'FOO', ConstantOnly::class ); it('contains second target reflection class constant with attribute') ->expect($targets) ->toContainTargetClassConstantWithAttribute( - Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'BAR', objectType(ConstantOnly::class) + Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'BAR', ConstantOnly::class ); it('contains first target reflection class constant with attribute instance') ->expect($targets) ->toContainTargetClassConstantWithAttributeInstance( - Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'FOO', objectType(ConstantOnly::class), - fn(ConstantOnly $constantOnly) => $constantOnly->value === 'Mallory' + Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'FOO', ConstantOnly::class, + static fn(ConstantOnly $constantOnly) => $constantOnly->value === 'Mallory' ); it('contains second target reflection class constant with attribute instance') ->expect($targets) ->toContainTargetClassConstantWithAttributeInstance( - Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'BAR', objectType(ConstantOnly::class), - fn(ConstantOnly $constantOnly) => $constantOnly->value === 'Mallory' + Fixtures::singleAttributeMultipleConstantsSingleClass()->fooClass(), 'BAR', ConstantOnly::class, + static fn(ConstantOnly $constantOnly) => $constantOnly->value === 'Mallory' ); diff --git a/tests/Unit/SingleAttributeMultiplePropertyTest.php b/tests/Unit/SingleAttributeMultiplePropertyTest.php index e9f6ad6..76468d3 100644 --- a/tests/Unit/SingleAttributeMultiplePropertyTest.php +++ b/tests/Unit/SingleAttributeMultiplePropertyTest.php @@ -4,7 +4,6 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\PropertyOnly; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); @@ -53,38 +52,38 @@ it('includes attribute reflection class for first prop') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'foo', objectType(PropertyOnly::class) + Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'foo', PropertyOnly::class ); it('includes attribute reflection class for second prop') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'bar', objectType(PropertyOnly::class) + Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'bar', PropertyOnly::class ); it('includes attribute reflection class for third prop') ->expect($targets) ->toContainTargetPropertyWithAttribute( - Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'baz', objectType(PropertyOnly::class) + Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'baz', PropertyOnly::class ); it('includes attribute instance value for first prop') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'foo', objectType(PropertyOnly::class), - fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'foo-bar-baz' + Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'foo', PropertyOnly::class, + static fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'foo-bar-baz' ); it('includes attribute instance value for second prop') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'bar', objectType(PropertyOnly::class), - fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'foo-bar-baz' + Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'bar', PropertyOnly::class, + static fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'foo-bar-baz' ); it('includes attribute instance value for third prop') ->expect($targets) ->toContainTargetPropertyWithAttributeInstance( - Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'baz', objectType(PropertyOnly::class), - fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'foo-bar-baz' + Fixtures::singleAttributeMultiplePropertiesSingleClass()->fooClass(), 'baz', PropertyOnly::class, + static fn(PropertyOnly $propertyOnly) => $propertyOnly->value === 'foo-bar-baz' ); diff --git a/tests/Unit/TargetAttributeInterfaceTest.php b/tests/Unit/TargetAttributeInterfaceTest.php index 6c42862..576976d 100644 --- a/tests/Unit/TargetAttributeInterfaceTest.php +++ b/tests/Unit/TargetAttributeInterfaceTest.php @@ -5,12 +5,11 @@ use Cspray\AnnotatedTargetFixture\Fixtures; use Cspray\AnnotatedTargetFixture\TargetAttributeImplementation; use Cspray\AnnotatedTargetFixture\TargetAttributeInterface; -use function Cspray\Typiphy\objectType; uses(AnnotatedTargetParserTestCase::class); beforeEach()->withFixtures(Fixtures::targetAttributeInterface()) - ->withFilteredAttributes(objectType(TargetAttributeInterface::class)); + ->withFilteredAttributes(TargetAttributeInterface::class); it('counts parsed targets for single class') ->expect(fn() => $this->getTargets()) @@ -38,12 +37,12 @@ it('includes attribute reflection class') ->expect(fn() => $this->getTargets()) - ->toContainTargetClassWithAttribute(Fixtures::targetAttributeInterface()->targetClass(), objectType(TargetAttributeImplementation::class)); + ->toContainTargetClassWithAttribute(Fixtures::targetAttributeInterface()->targetClass(), TargetAttributeImplementation::class); it('includes attribute instance with correct value') ->expect(fn() => $this->getTargets()) ->toContainTargetClassWithAttributeInstance( Fixtures::targetAttributeInterface()->targetClass(), - objectType(TargetAttributeImplementation::class), - fn(TargetAttributeImplementation $classOnly) => $classOnly->value === 'target-attr' + TargetAttributeImplementation::class, + static fn(TargetAttributeImplementation $classOnly) => $classOnly->value === 'target-attr' ); From a28fcdcefe4f54547902e291b7fb53aed69a2fac Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Thu, 27 Jun 2024 10:47:54 -0400 Subject: [PATCH 4/6] update testing framework --- .gitignore | 1 + composer.json | 2 +- phpunit.xml | 27 +++++++++++---------------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 63dcaa1..d6495f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor/ composer.lock +.phpunit.cache .phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index d15c5f2..0068353 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "nikic/php-parser": "^v4.18 || ^5.0" }, "require-dev": { - "pestphp/pest": "^v1.21" + "pestphp/pest": "^v2" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 8f4b58c..a811e1d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,18 +1,13 @@ - - - - ./tests - - - - - ./app - ./src - - + + + + ./tests + + + + + ./src + + From 5bb1bde3ec85b0ea34e6d02ee637195148bcfa10 Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Fri, 5 Jul 2024 08:34:16 -0400 Subject: [PATCH 5/6] Improve AnnotatedTargetParserOptions into a value object --- src/AnnotatedTargetParserOptions.php | 28 ++++++++-- src/AnnotatedTargetParserOptionsBuilder.php | 56 ------------------- src/PhpParserAnnotatedTargetParser.php | 52 ++++++++++------- src/functions.php | 9 +-- ...nnotatedTargetParserOptionsBuilderTest.php | 49 ---------------- tests/Unit/AnnotatedTargetParserTestCase.php | 10 +++- 6 files changed, 67 insertions(+), 137 deletions(-) delete mode 100644 src/AnnotatedTargetParserOptionsBuilder.php delete mode 100644 tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php diff --git a/src/AnnotatedTargetParserOptions.php b/src/AnnotatedTargetParserOptions.php index 29439a0..3602f84 100644 --- a/src/AnnotatedTargetParserOptions.php +++ b/src/AnnotatedTargetParserOptions.php @@ -2,16 +2,32 @@ namespace Cspray\AnnotatedTarget; -interface AnnotatedTargetParserOptions { +final class AnnotatedTargetParserOptions { /** - * @return non-empty-list + * @param non-empty-list $sourceDirectories + * @param list $filteredAttributes */ - public function sourceDirectories() : array; + private function __construct( + public readonly array $sourceDirectories, + public readonly array $filteredAttributes + ) {} /** - * @return non-empty-list + * @param non-empty-string $path + * @param non-empty-string ...$additionalPaths + * @return self */ - public function attributeTypes() : array; + public static function scanAllAttributes(string $path, string... $additionalPaths) : self { + return new self(array_values([$path, ...$additionalPaths]), []); + } -} \ No newline at end of file + /** + * @param non-empty-list $paths + * @param non-empty-list $attributes + */ + public static function scanForSpecificAttributes(array $paths, array $attributes) : self { + return new self($paths, $attributes); + } + +} diff --git a/src/AnnotatedTargetParserOptionsBuilder.php b/src/AnnotatedTargetParserOptionsBuilder.php deleted file mode 100644 index 67ebb22..0000000 --- a/src/AnnotatedTargetParserOptionsBuilder.php +++ /dev/null @@ -1,56 +0,0 @@ - $dirs - * @return self - * @throws InvalidArgumentException - */ - public static function scanDirectories(array $dirs) : self { - $instance = new self; - foreach ($dirs as $dir) { - if (!is_dir($dir)) { - throw new InvalidArgumentException(sprintf("The value '%s' is not a directory.", $dir)); - } - - $instance->directories[] = $dir; - } - return $instance; - } - - /** - * @param non-empty-list $attributes - */ - public function filterAttributes(array $attributes) : self { - $instance = clone $this; - $instance->attributes = [...$this->attributes, ...$attributes]; - return $instance; - } - - public function build() : AnnotatedTargetParserOptions { - return new class($this->directories, $this->attributes) implements AnnotatedTargetParserOptions { - - public function __construct(private readonly array $directories, private readonly array $attributes) {} - - public function sourceDirectories() : array { - return $this->directories; - } - - public function attributeTypes() : array { - return $this->attributes; - } - }; - } - -} \ No newline at end of file diff --git a/src/PhpParserAnnotatedTargetParser.php b/src/PhpParserAnnotatedTargetParser.php index 84bf011..aaaaa25 100644 --- a/src/PhpParserAnnotatedTargetParser.php +++ b/src/PhpParserAnnotatedTargetParser.php @@ -2,6 +2,7 @@ namespace Cspray\AnnotatedTarget; +use Closure; use Cspray\AnnotatedTarget\Exception\InvalidPhpSyntax; use FilesystemIterator; use Generator; @@ -36,11 +37,12 @@ public function parse(AnnotatedTargetParserOptions $options) : Generator { $nodeTraverser = new NodeTraverser(); $nodeTraverser->addVisitor(new NodeVisitor\NodeConnectingVisitor()); $nodeTraverser->addVisitor(new NodeVisitor\NameResolver()); + /** @var \stdClass{targets: list} $data */ $data = new \stdClass(); $data->targets = []; $nodeTraverser->addVisitor($this->getVisitor( - static fn($target) => $data->targets[] = $target, - $options->attributeTypes() + static fn(AnnotatedTarget $target) => $data->targets[] = $target, + $options->filteredAttributes )); foreach ($this->getSourceIterator($options) as $sourceFile) { @@ -61,7 +63,7 @@ public function parse(AnnotatedTargetParserOptions $options) : Generator { } private function getSourceIterator(AnnotatedTargetParserOptions $options) : Iterator { - foreach ($options->sourceDirectories() as $directory) { + foreach ($options->sourceDirectories as $directory) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS) ); @@ -126,25 +128,25 @@ private function isAttributeInstanceOfFilteredAttribute(string $attrType) : bool private function getAnnotatedTargetFromClassNode(Node\Stmt\Class_|Node\Stmt\Interface_ $class, int $index) : AnnotatedTarget { $classType = $class->namespacedName->toString(); - return $this->getAnnotatedTarget(fn() => new ReflectionClass($classType), $index); + return $this->getAnnotatedTarget(static fn() : ReflectionClass => new ReflectionClass($classType), $index); } private function getAnnotatedTargetFromPropertyNode(Node\Stmt\PropertyProperty $property, int $index) : AnnotatedTarget { $classType = $property->getAttribute('parent')->getAttribute('parent')->namespacedName->toString(); $propertyName = $property->name->toString(); - return $this->getAnnotatedTarget(fn() => new ReflectionProperty($classType, $propertyName), $index); + return $this->getAnnotatedTarget(static fn() : ReflectionProperty => new ReflectionProperty($classType, $propertyName), $index); } private function getAnnotatedTargetFromClassConstantNode(Node\Const_ $classConst, int $index) : AnnotatedTarget { $classType = $classConst->getAttribute('parent')->getAttribute('parent')->namespacedName->toString(); $constName = $classConst->name->toString(); - return $this->getAnnotatedTarget(fn() => new ReflectionClassConstant($classType, $constName), $index); + return $this->getAnnotatedTarget(static fn() : ReflectionClassConstant => new ReflectionClassConstant($classType, $constName), $index); } private function getAnnotatedTargetFromMethodNode(Node\Stmt\ClassMethod $classMethod, int $index) : AnnotatedTarget { $classType = $classMethod->getAttribute('parent')->namespacedName->toString(); $methodName = $classMethod->name->toString(); - return $this->getAnnotatedTarget(fn() => new ReflectionMethod(sprintf('%s::%s', $classType, $methodName)), $index); + return $this->getAnnotatedTarget(static fn() : ReflectionMethod => new ReflectionMethod(sprintf('%s::%s', $classType, $methodName)), $index); } private function getAnnotatedTargetFromMethodParameter(Node\Param $param, int $index) : AnnotatedTarget { @@ -157,45 +159,57 @@ private function getAnnotatedTargetFromMethodParameter(Node\Param $param, int $i $callable = $paramParent->namespacedName->toString(); } $paramName = $param->var->name; - return $this->getAnnotatedTarget(fn() => new ReflectionParameter($callable, $paramName), $index); + return $this->getAnnotatedTarget(static fn() : ReflectionParameter => new ReflectionParameter($callable, $paramName), $index); } private function getAnnotatedTargetFromFunction(Node\Stmt\Function_ $function, int $index) : AnnotatedTarget { $function = $function->namespacedName->toString(); - return $this->getAnnotatedTarget(fn() => new ReflectionFunction($function), $index); + return $this->getAnnotatedTarget(static fn() => new ReflectionFunction($function), $index); } - private function getAnnotatedTarget(callable $reflectorSupplier, int $index) : AnnotatedTarget { + /** + * @param Closure():ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction $reflectorSupplier + * @param int $index + * @return AnnotatedTarget + */ + private function getAnnotatedTarget(Closure $reflectorSupplier, int $index) : AnnotatedTarget { return new class($reflectorSupplier, $index) implements AnnotatedTarget { - private $reflectorSupplier; - private ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction $reflection; - private ReflectionAttribute $reflectionAttribute; - private object $attribute; - + /** + * @var Closure():ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionFunction|ReflectionMethod|ReflectionParameter + */ + private Closure $reflectorSupplier; + private ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction|null $reflection = null; + private ReflectionAttribute|null $reflectionAttribute = null; + private object|null $attribute = null; + + /** + * @param Closure():ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction $reflectorSupplier + * @param int $index + */ public function __construct( - callable $reflectorSupplier, + Closure $reflectorSupplier, private readonly int $index ) { $this->reflectorSupplier = $reflectorSupplier; } public function targetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction { - if (!isset($this->reflection)) { + if ($this->reflection === null) { $this->reflection = ($this->reflectorSupplier)(); } return $this->reflection; } public function attributeReflection() : ReflectionAttribute { - if (!isset($this->reflectionAttribute)) { + if ($this->reflectionAttribute === null) { $this->reflectionAttribute = $this->targetReflection()->getAttributes()[$this->index]; } return $this->reflectionAttribute; } public function attributeInstance() : object { - if (!isset($this->attribute)) { + if ($this->attribute === null) { $this->attribute = $this->attributeReflection()->newInstance(); } return $this->attribute; diff --git a/src/functions.php b/src/functions.php index 05d63db..8d3b9ff 100644 --- a/src/functions.php +++ b/src/functions.php @@ -17,10 +17,11 @@ function parseAttributes(array|string $directories, array $filterAttributes = [] $parser = new PhpParserAnnotatedTargetParser(); $directories = is_string($directories) ? [$directories] : $directories; - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories($directories); - if ($filterAttributes !== []) { - $builder = $builder->filterAttributes($filterAttributes); + if ($filterAttributes === []) { + $options = AnnotatedTargetParserOptions::scanAllAttributes(...$directories); + } else { + $options = AnnotatedTargetParserOptions::scanForSpecificAttributes($directories, $filterAttributes); } - return $parser->parse($builder->build()); + return $parser->parse($options); } \ No newline at end of file diff --git a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php b/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php deleted file mode 100644 index ea501e2..0000000 --- a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php +++ /dev/null @@ -1,49 +0,0 @@ -throws(InvalidArgumentException::class, "The value 'not-dir' is not a directory."); - -it('has scan directories in options') - ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()])->build(); - return $options->sourceDirectories(); - }) - ->toBe([Fixtures::classOnlyAttributeSingleClass()->getPath()]); - -it('has different instance for filterAttributes', function() { - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()]); - $filterBuilder = $builder->filterAttributes([ClassOnly::class]); - expect($builder)->not->toBe($filterBuilder); -}); - -it('has empty filterAttributes in options') - ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()])->build(); - return $options->attributeTypes(); - })->toBeEmpty(); - -it('has populated filterAttributes in options') - ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()]) - ->filterAttributes([ClassOnly::class]) - ->build(); - return $options->attributeTypes(); - })->toBe([ClassOnly::class]); - -it('has populated filterAttributes in options, when chained') - ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories([Fixtures::classOnlyAttributeSingleClass()->getPath()]) - ->filterAttributes([ClassOnly::class]) - ->filterAttributes([MethodOnly::class]) - ->build(); - return $options->attributeTypes(); - })->toBe([ClassOnly::class, MethodOnly::class]); \ No newline at end of file diff --git a/tests/Unit/AnnotatedTargetParserTestCase.php b/tests/Unit/AnnotatedTargetParserTestCase.php index d639832..c57e152 100644 --- a/tests/Unit/AnnotatedTargetParserTestCase.php +++ b/tests/Unit/AnnotatedTargetParserTestCase.php @@ -2,6 +2,7 @@ namespace Cspray\AnnotatedTarget\Unit; +use Cspray\AnnotatedTarget\AnnotatedTargetParserOptions; use Cspray\AnnotatedTarget\AnnotatedTargetParserOptionsBuilder; use Cspray\AnnotatedTarget\PhpParserAnnotatedTargetParser; use Cspray\AnnotatedTargetFixture\Fixture; @@ -21,11 +22,14 @@ public function getTargets() : array { throw new \BadMethodCallException('Before running any assertions on this test case you must provide a Fixture to load.'); } $paths = array_map(fn(Fixture $fixture) => $fixture->getPath(), $this->fixtures); - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories($paths); + $options = AnnotatedTargetParserOptions::scanAllAttributes(...$paths); if (isset($this->attributes)) { - $builder = $builder->filterAttributes($this->attributes); + $options = AnnotatedTargetParserOptions::scanForSpecificAttributes( + $paths, + $this->attributes + ); } - return iterator_to_array($this->getSubject()->parse($builder->build())); + return iterator_to_array($this->getSubject()->parse($options)); } public function withFixtures(Fixture... $fixtures) : self { From 939aa5ddc17a589cee8bd726e1337de096f541af Mon Sep 17 00:00:00 2001 From: Charles Sprayberry Date: Thu, 8 Aug 2024 10:10:45 -0400 Subject: [PATCH 6/6] Run check so we can make it required status --- .github/workflows/php.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index e8cbb1d..907768b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,10 +1,6 @@ name: 'Unit Tests' -on: - push: - branches: [ release-1.x, release-2.x ] - pull_request: - branches: [ release-1.x, release-2.x ] +on: push jobs: build-test: