-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check filtered attributes on instance type (#13)
- Loading branch information
Showing
7 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Cspray\AnnotatedTargetFixture; | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
final class TargetAttributeImplementation implements TargetAttributeInterface { | ||
|
||
public function __construct(public readonly string $value) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Cspray\AnnotatedTargetFixture; | ||
|
||
interface TargetAttributeInterface { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Cspray\AnnotatedTargetFixture\TargetAttributeInterface; | ||
|
||
use Cspray\AnnotatedTargetFixture\TargetAttributeImplementation; | ||
|
||
#[TargetAttributeImplementation('target-attr')] | ||
class TargetClass { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Cspray\AnnotatedTargetFixture; | ||
|
||
use Cspray\AnnotatedTargetFixture\TargetAttributeInterface\TargetClass; | ||
use Cspray\Typiphy\ObjectType; | ||
use function Cspray\Typiphy\objectType; | ||
|
||
final class TargetAttributeInterfaceFixture implements Fixture { | ||
|
||
public function getPath() : string { | ||
return __DIR__ . '/TargetAttributeInterface'; | ||
} | ||
|
||
public function targetClass() : ObjectType { | ||
return objectType(TargetClass::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Cspray\AnnotatedTarget\Unit; | ||
|
||
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)); | ||
|
||
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::targetAttributeInterface()->targetClass()); | ||
|
||
it('includes attribute reflection class') | ||
->expect(fn() => $this->getTargets()) | ||
->toContainTargetClassWithAttribute(Fixtures::targetAttributeInterface()->targetClass(), objectType(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' | ||
); |