77namespace OpenApi \Tests \Analysers ;
88
99use OpenApi \Analysers \AttributeAnnotationFactory ;
10+ use OpenApi \Generator ;
1011use OpenApi \Tests \Fixtures \UsingAttributes ;
1112use OpenApi \Tests \Fixtures \InvalidPropertyAttribute ;
1213use OpenApi \Tests \OpenApiTestCase ;
1617 */
1718class AttributeAnnotationFactoryTest extends OpenApiTestCase
1819{
19- public function testReturnedAnnotationsCout (): void
20+ protected function getFactory (?array $ config = null ): AttributeAnnotationFactory
21+ {
22+ $ generator = new Generator ();
23+ if (null !== $ config ) {
24+ $ generator ->setConfig ($ config );
25+ }
26+
27+ return (new AttributeAnnotationFactory ())
28+ ->setGenerator ($ generator );
29+ }
30+
31+ public function testReturnedAnnotationsCount (): void
2032 {
2133 $ rc = new \ReflectionClass (UsingAttributes::class);
2234
23- $ annotations = ( new AttributeAnnotationFactory () )->build ($ rc , $ this ->getContext ());
35+ $ annotations = $ this -> getFactory ( )->build ($ rc , $ this ->getContext ());
2436 $ this ->assertCount (1 , $ annotations );
2537 }
2638
@@ -32,6 +44,18 @@ public function testErrorOnInvalidAttribute(): void
3244 $ this ->expectException (\TypeError::class);
3345 $ this ->expectExceptionMessage ('OpenApi\Attributes\Property::__construct(): Argument #8 ($required) must be of type ?array ' );
3446
35- (new AttributeAnnotationFactory ())->build ($ rm , $ this ->getContext ());
47+ $ this ->getFactory ()->build ($ rm , $ this ->getContext ());
48+ }
49+
50+ public function testIgnoreOtherAttributes (): void
51+ {
52+ $ rc = new \ReflectionClass (UsingAttributes::class);
53+
54+ $ this ->getFactory ()->build ($ rc , $ context = $ this ->getContext ());
55+ $ this ->assertIsArray ($ context ->other );
56+ $ this ->assertCount (1 , $ context ->other );
57+
58+ $ this ->getFactory (['generator ' => ['ignoreOtherAttributes ' => true ]])->build ($ rc , $ context = $ this ->getContext ());
59+ $ this ->assertNull ($ context ->other );
3660 }
3761}
0 commit comments