From d068f1aa2204cb638e9500b8bac31c5c51f5066b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 20 Nov 2026 23:43:11 +0400 Subject: [PATCH 1/2] test(locator): cover a failing attribute reader Assisted-By: Claude Opus 5.5 --- tests/Fixtures/Locator/FailingClassReader.php | 42 +++++++++++++++++++ .../Locator/TokenizerEmbeddingLocatorTest.php | 16 +++++++ .../Locator/TokenizerEntityLocatorTest.php | 16 +++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/Fixtures/Locator/FailingClassReader.php diff --git a/tests/Fixtures/Locator/FailingClassReader.php b/tests/Fixtures/Locator/FailingClassReader.php new file mode 100644 index 00000000..21914133 --- /dev/null +++ b/tests/Fixtures/Locator/FailingClassReader.php @@ -0,0 +1,42 @@ +error; + } + + public function getFunctionMetadata(\ReflectionFunctionAbstract $function, ?string $name = null): iterable + { + return []; + } + + public function getPropertyMetadata(\ReflectionProperty $property, ?string $name = null): iterable + { + return []; + } + + public function getConstantMetadata(\ReflectionClassConstant $constant, ?string $name = null): iterable + { + return []; + } + + public function getParameterMetadata(\ReflectionParameter $parameter, ?string $name = null): iterable + { + return []; + } +} diff --git a/tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php b/tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php index 94a57e5d..9d5742e0 100644 --- a/tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php +++ b/tests/Unit/Locator/TokenizerEmbeddingLocatorTest.php @@ -5,14 +5,17 @@ namespace Cycle\Annotated\Tests\Unit\Locator; use Cycle\Annotated\Annotation\Embeddable; +use Cycle\Annotated\Exception\AnnotationException; use Cycle\Annotated\Locator\Embedding; use Cycle\Annotated\Locator\TokenizerEmbeddingLocator; use Cycle\Annotated\Tests\Fixtures\Configurator\Address as PostalAddress; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Child; use Cycle\Annotated\Tests\Fixtures\Fixtures7\Address; +use Cycle\Annotated\Tests\Fixtures\Locator\FailingClassReader; use Cycle\Testing\ORM\Schema\ClassList; use Testo\Assert; use Testo\Data\DataProvider; +use Testo\Expect; use Testo\Test; #[Test] @@ -61,4 +64,17 @@ public function testGetEmbeddings(array $expected, array $classes): void Assert::equals($locator->getEmbeddings(), $expected); } + + public function wrapsAnExceptionOfTheReader(): never + { + $previous = new \RuntimeException('broken', 42); + $locator = new TokenizerEmbeddingLocator(new ClassList(Address::class), new FailingClassReader($previous)); + + Expect::exception(AnnotationException::class) + ->withMessage('broken') + ->withCode(42) + ->withPrevious($previous); + + $locator->getEmbeddings(); + } } diff --git a/tests/Unit/Locator/TokenizerEntityLocatorTest.php b/tests/Unit/Locator/TokenizerEntityLocatorTest.php index d2f9cfe7..2fc38762 100644 --- a/tests/Unit/Locator/TokenizerEntityLocatorTest.php +++ b/tests/Unit/Locator/TokenizerEntityLocatorTest.php @@ -5,6 +5,7 @@ namespace Cycle\Annotated\Tests\Unit\Locator; use Cycle\Annotated\Annotation\Entity as Attribute; +use Cycle\Annotated\Exception\AnnotationException; use Cycle\Annotated\Locator\Entity; use Cycle\Annotated\Locator\TokenizerEntityLocator; use Cycle\Annotated\Tests\Fixtures\Fixtures1\AnotherClass; @@ -12,9 +13,11 @@ use Cycle\Annotated\Tests\Fixtures\Fixtures1\Typecast\Typecaster; use Cycle\Annotated\Tests\Fixtures\Fixtures1\Typecast\UuidTypecaster; use Cycle\Annotated\Tests\Fixtures\Fixtures1\WithTable; +use Cycle\Annotated\Tests\Fixtures\Locator\FailingClassReader; use Cycle\Testing\ORM\Schema\ClassList; use Testo\Assert; use Testo\Data\DataProvider; +use Testo\Expect; use Testo\Test; #[Test] @@ -51,4 +54,17 @@ public function testGetEntities(array $expected, array $classes): void Assert::equals($locator->getEntities(), $expected); } + + public function wrapsAnExceptionOfTheReader(): never + { + $previous = new \RuntimeException('broken', 42); + $locator = new TokenizerEntityLocator(new ClassList(Tag::class), new FailingClassReader($previous)); + + Expect::exception(AnnotationException::class) + ->withMessage('broken') + ->withCode(42) + ->withPrevious($previous); + + $locator->getEntities(); + } } From 657e3299b09d8ecc11aea26ecf40a5e85b512ac0 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 20 Nov 2026 23:43:12 +0400 Subject: [PATCH 2/2] test(annotation): cover the embeddable columns and relation load accessors Assisted-By: Claude Opus 5.5 --- tests/Unit/Attribute/AnnotationsTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/Unit/Attribute/AnnotationsTest.php b/tests/Unit/Attribute/AnnotationsTest.php index 34d2b596..2671a840 100644 --- a/tests/Unit/Attribute/AnnotationsTest.php +++ b/tests/Unit/Attribute/AnnotationsTest.php @@ -4,10 +4,13 @@ namespace Cycle\Annotated\Tests\Unit\Attribute; +use Cycle\Annotated\Annotation\Column; +use Cycle\Annotated\Annotation\Embeddable; use Cycle\Annotated\Annotation\Entity; use Cycle\Annotated\Annotation\GeneratedValue; use Cycle\Annotated\Annotation\Inheritance\JoinedTable; use Cycle\Annotated\Annotation\Inheritance\SingleTable; +use Cycle\Annotated\Annotation\Relation\HasOne; use Cycle\Annotated\Annotation\Relation\Inverse; use Cycle\Annotated\Annotation\Table\PrimaryKey; use Cycle\ORM\Relation; @@ -76,4 +79,19 @@ public function primaryKeyIsAUniqueIndex(): void Assert::true($key->isUnique()); Assert::same($key->getColumns(), ['id', 'type']); } + + public function embeddableKeepsItsColumns(): void + { + $columns = [new Column('string', property: 'street')]; + + $embeddable = new Embeddable(columns: $columns); + + Assert::same($embeddable->getColumns(), $columns); + } + + public function relationLoadsLazilyByDefault(): void + { + Assert::same((new HasOne(target: 'user'))->getLoad(), 'lazy'); + Assert::same((new HasOne(target: 'user', load: 'eager'))->getLoad(), 'eager'); + } }