diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 2c8cc64..907768b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,26 +1,27 @@ name: 'Unit Tests' -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] +on: push 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/.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/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 aa70f39..0068353 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,10 @@ ], "require": { "php": "^8.1", - "nikic/php-parser": "^v4.14", - "cspray/typiphy": "^0.3" + "nikic/php-parser": "^v4.18 || ^5.0" }, "require-dev": { - "pestphp/pest": "^v1.21" + "pestphp/pest": "^v2" }, "autoload": { "psr-4": { 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 @@ + - - - - ./tests - - - - - ./app - ./src - - + + + + ./tests + + + + + ./src + + 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..3602f84 100644 --- a/src/AnnotatedTargetParserOptions.php +++ b/src/AnnotatedTargetParserOptions.php @@ -2,10 +2,32 @@ namespace Cspray\AnnotatedTarget; -interface AnnotatedTargetParserOptions { +final class AnnotatedTargetParserOptions { - public function getSourceDirectories() : array; + /** + * @param non-empty-list $sourceDirectories + * @param list $filteredAttributes + */ + private function __construct( + public readonly array $sourceDirectories, + public readonly array $filteredAttributes + ) {} - public function getAttributeTypes() : array; + /** + * @param non-empty-string $path + * @param non-empty-string ...$additionalPaths + * @return self + */ + 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 49ba9ab..0000000 --- a/src/AnnotatedTargetParserOptionsBuilder.php +++ /dev/null @@ -1,53 +0,0 @@ -directories[] = $dir; - } - return $instance; - } - - public function filterAttributes(ObjectType... $attributes) : self { - if (empty($attributes)) { - throw new InvalidArgumentException('The Attributes to filter by must not be empty.'); - } - $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 getSourceDirectories() : array { - return $this->directories; - } - - public function getAttributeTypes() : array { - return $this->attributes; - } - }; - } - -} \ No newline at end of file diff --git a/src/PhpParserAnnotatedTargetParser.php b/src/PhpParserAnnotatedTargetParser.php index b3cc425..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; @@ -29,18 +30,19 @@ final class PhpParserAnnotatedTargetParser implements AnnotatedTargetParser { private readonly Parser $parser; public function __construct() { - $this->parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7); + $this->parser = (new ParserFactory())->createForNewestSupportedVersion(); } 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( - fn($target) => $data->targets[] = $target, - $options->getAttributeTypes() + 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->getSourceDirectories() as $directory) { + foreach ($options->sourceDirectories as $directory) { $iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($directory, FilesystemIterator::SKIP_DOTS) ); @@ -75,9 +77,7 @@ private function getSourceIterator(AnnotatedTargetParserOptions $options) : Iter } private function getVisitor(callable $consumer, array $filteredAttributes) : NodeVisitor { - $filteredAttributes = array_map(fn($attr) => $attr->getName(), $filteredAttributes); return new class($consumer, $filteredAttributes) extends NodeVisitorAbstract { - private $consumer; public function __construct(callable $consumer, private readonly array $filteredAttributes) { @@ -128,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 { @@ -159,46 +159,58 @@ 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 getTargetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction { - if (!isset($this->reflection)) { + public function targetReflection() : ReflectionClass|ReflectionProperty|ReflectionClassConstant|ReflectionMethod|ReflectionParameter|ReflectionFunction { + if ($this->reflection === null) { $this->reflection = ($this->reflectorSupplier)(); } return $this->reflection; } - public function getAttributeReflection() : ReflectionAttribute { - if (!isset($this->reflectionAttribute)) { - $this->reflectionAttribute = $this->getTargetReflection()->getAttributes()[$this->index]; + public function attributeReflection() : ReflectionAttribute { + if ($this->reflectionAttribute === null) { + $this->reflectionAttribute = $this->targetReflection()->getAttributes()[$this->index]; } return $this->reflectionAttribute; } - public function getAttributeInstance() : object { - if (!isset($this->attribute)) { - $this->attribute = $this->getAttributeReflection()->newInstance(); + public function attributeInstance() : object { + if ($this->attribute === null) { + $this->attribute = $this->attributeReflection()->newInstance(); } return $this->attribute; } diff --git a/src/functions.php b/src/functions.php index c32b1a8..8d3b9ff 100644 --- a/src/functions.php +++ b/src/functions.php @@ -2,23 +2,26 @@ namespace Cspray\AnnotatedTarget; +use Cspray\AnnotatedTarget\Exception\InvalidArgumentException; +use Cspray\AnnotatedTarget\Exception\InvalidPhpSyntax; use Generator; -use function Cspray\Typiphy\objectType; /** - * @param array|string $directories - * @param array $filterAttributes + * @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); + 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/Pest.php b/tests/Pest.php index c0a50cb..5020d6c 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -1,70 +1,47 @@ getTargetReflection() instanceof ReflectionClass && - $target->getTargetReflection()->getName() === $expectedClass->getName(); +$checkTargetReflectionClass = function(AnnotatedTarget $target, string $expectedClass) : bool { + return $target->targetReflection() instanceof ReflectionClass && + $target->targetReflection()->getName() === $expectedClass; }; -$checkTargetReflectionClassConstant = function(AnnotatedTarget $target, ObjectType $expectedClass, string $expectedConst) : bool { - return $target->getTargetReflection() instanceof ReflectionClassConstant && - $target->getTargetReflection()->getDeclaringClass()->getName() === $expectedClass->getName() && - $target->getTargetReflection()->getName() === $expectedConst; +$checkTargetReflectionClassConstant = function(AnnotatedTarget $target, string $expectedClass, string $expectedConst) : bool { + return $target->targetReflection() instanceof ReflectionClassConstant && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && + $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; +$checkTargetReflectionMethod = function(AnnotatedTarget $target, string $expectedClass, string $expectedMethod) : bool { + return $target->targetReflection() instanceof ReflectionMethod && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && + $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; +$checkTargetReflectionProperty = function(AnnotatedTarget $target, string $expectedClass, string $expectedProp) : bool { + return $target->targetReflection() instanceof ReflectionProperty && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && + $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; +$checkTargetReflectionMethodParameter = function(AnnotatedTarget $target, string $expectedClass, string $expectedMethod, string $expectedParam) : bool { + return $target->targetReflection() instanceof ReflectionParameter && + $target->targetReflection()->getDeclaringClass()->getName() === $expectedClass && + $target->targetReflection()->getDeclaringFunction()->getName() === $expectedMethod && + $target->targetReflection()->getName() === $expectedParam; }; expect()->extend('toBeOne', function () { @@ -77,61 +54,61 @@ 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()); }); }); -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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute && + $callable($item->attributeInstance()) ); }); @@ -141,18 +118,18 @@ ); }); -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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $item->attributeReflection()->getName() === $expectedAttribute && + $callable($item->attributeInstance()) ); }); @@ -162,81 +139,81 @@ ); }); -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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() + $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->getAttributeReflection()->getName() === $expectedAttribute->getName() && - $callable($item->getAttributeInstance()) + $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 new file mode 100644 index 0000000..1c58ad6 --- /dev/null +++ b/tests/Unit/AliasedAttributeTest.php @@ -0,0 +1,46 @@ +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(), ClassOnly::class); + +it('includes attribute instance with correct value') + ->expect(fn() => $this->getTargets()) + ->toContainTargetClassWithAttributeInstance( + Fixtures::aliasedAttribute()->fooClass(), + ClassOnly::class, + fn(ClassOnly $classOnly) => $classOnly->value === 'my aliased value' + ); diff --git a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php b/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php deleted file mode 100644 index 884df28..0000000 --- a/tests/Unit/AnnotatedTargetParserOptionsBuilderTest.php +++ /dev/null @@ -1,58 +0,0 @@ -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'); -})->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(); - return $options->getSourceDirectories(); - }) - ->toBe([Fixtures::classOnlyAttributeSingleClass()->getPath()]); - -it('has different instance for filterAttributes', function() { - $builder = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath()); - $filterBuilder = $builder->filterAttributes(objectType(ClassOnly::class)); - expect($builder)->not->toBe($filterBuilder); -}); - -it('has empty filterAttributes in options') - ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath())->build(); - return $options->getAttributeTypes(); - })->toBeEmpty(); - -it('has populated filterAttributes in options') - ->expect(function() { - $options = AnnotatedTargetParserOptionsBuilder::scanDirectories(Fixtures::classOnlyAttributeSingleClass()->getPath()) - ->filterAttributes(objectType(ClassOnly::class)) - ->build(); - return $options->getAttributeTypes(); - })->toBe([objectType(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)) - ->build(); - return $options->getAttributeTypes(); - })->toBe([objectType(ClassOnly::class), objectType(MethodOnly::class)]); \ No newline at end of file diff --git a/tests/Unit/AnnotatedTargetParserTestCase.php b/tests/Unit/AnnotatedTargetParserTestCase.php index f3f2e8f..c57e152 100644 --- a/tests/Unit/AnnotatedTargetParserTestCase.php +++ b/tests/Unit/AnnotatedTargetParserTestCase.php @@ -2,10 +2,10 @@ namespace Cspray\AnnotatedTarget\Unit; +use Cspray\AnnotatedTarget\AnnotatedTargetParserOptions; 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,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 { @@ -34,7 +37,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 1d9a4a1..16884fa 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; @@ -39,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' );