@@ -37,131 +37,166 @@ public static function getResources(): array
3737 return [ChickenCoop::class, Chicken::class];
3838 }
3939
40+ /**
41+ * @return array{chickenIris: string[], coopIris: string[]}
42+ */
43+ private function getIris (): array
44+ {
45+ $ client = self ::createClient ();
46+ $ chickens = $ client ->request ('GET ' , '/chickens ' )->toArray ()['member ' ];
47+ $ coops = $ client ->request ('GET ' , '/chicken_coops ' )->toArray ()['member ' ];
48+
49+ $ chickenIris = [];
50+ foreach ($ chickens as $ c ) {
51+ $ chickenIris [$ c ['name ' ]] = '/chickens/ ' .$ c ['id ' ];
52+ }
53+
54+ $ coopIris = array_map (static fn ($ c ) => '/chicken_coops/ ' .$ c ['id ' ], $ coops );
55+
56+ return ['chickenIris ' => $ chickenIris , 'coopIris ' => $ coopIris ];
57+ }
58+
4059 public function testIriFilter (): void
4160 {
61+ $ iris = $ this ->getIris ();
4262 $ client = $ this ->createClient ();
4363
44- $ res = $ client ->request ('GET ' , '/chickens?chickenCoop=/chicken_coops/2 ' )->toArray ();
64+ $ res = $ client ->request ('GET ' , '/chickens?chickenCoop= ' . $ iris [ ' coopIris ' ][ 1 ] )->toArray ();
4565 $ this ->assertCount (1 , $ res ['member ' ]);
46- $ this ->assertEquals (' /chicken_coops/2 ' , $ res ['member ' ][0 ]['chickenCoop ' ]);
66+ $ this ->assertEquals ($ iris [ ' coopIris ' ][ 1 ] , $ res ['member ' ][0 ]['chickenCoop ' ]);
4767
4868 $ res = $ client ->request ('GET ' , '/chickens?chickenCoop=/chicken_coops/595 ' )->toArray ();
4969 $ this ->assertCount (0 , $ res ['member ' ]);
5070 }
5171
5272 public function testIriFilterMultiple (): void
5373 {
74+ $ iris = $ this ->getIris ();
5475 $ client = $ this ->createClient ();
55- $ res = $ client ->request ('GET ' , '/chickens?chickenCoop[]=/chicken_coops/2 &chickenCoop[]=/chicken_coops/1 ' )->toArray ();
76+ $ res = $ client ->request ('GET ' , '/chickens?chickenCoop[]= ' . $ iris [ ' coopIris ' ][ 1 ]. ' &chickenCoop[]= ' . $ iris [ ' coopIris ' ][ 0 ] )->toArray ();
5677 $ this ->assertCount (2 , $ res ['member ' ]);
5778 }
5879
5980 public function testIriFilterWithOneToManyRelation (): void
6081 {
82+ $ iris = $ this ->getIris ();
83+ $ chickenIri = $ iris ['chickenIris ' ]['Gertrude ' ];
6184 $ client = $ this ->createClient ();
6285
63- $ response = $ client ->request ('GET ' , '/chicken_coops?chickenIri=/chickens/1 ' );
86+ $ response = $ client ->request ('GET ' , '/chicken_coops?chickenIri= ' . $ chickenIri );
6487 $ this ->assertResponseIsSuccessful ();
6588
6689 $ responseData = $ response ->toArray ();
6790 $ filteredCoops = $ responseData ['member ' ];
6891
69- $ this ->assertCount (1 , $ filteredCoops, ' Expected 1 coop for URL /chicken_coops?chickenIri=/chickens/1 ' );
92+ $ this ->assertCount (1 , $ filteredCoops );
7093
7194 $ allChickenNames = [];
7295 foreach ($ filteredCoops as $ coop ) {
73- foreach ($ coop ['chickens ' ] as $ chickenIri ) {
74- $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ chickenIri );
96+ foreach ($ coop ['chickens ' ] as $ ci ) {
97+ $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ ci );
7598 $ chickenData = $ chickenResponse ->toArray ();
7699 $ allChickenNames [] = $ chickenData ['name ' ];
77100 }
78101 }
79102
80103 sort ($ allChickenNames );
81- $ this ->assertSame (['Gertrude ' ], $ allChickenNames, ' The chicken names in coops do not match the expected values. ' );
104+ $ this ->assertSame (['Gertrude ' ], $ allChickenNames );
82105
83106 $ res = $ client ->request ('GET ' , '/chicken_coops?chickenIri=/chickens/595 ' )->toArray ();
84107 $ this ->assertCount (0 , $ res ['member ' ]);
85108 }
86109
87110 public function testIriFilterWithOneToManyRelationWithMultiple (): void
88111 {
89- $ response = $ this ->createClient ()->request ('GET ' , '/chicken_coops?chickenIri[]=/chickens/1&chickenIri[]=/chickens/2 ' );
112+ $ iris = $ this ->getIris ();
113+ $ chicken1Iri = $ iris ['chickenIris ' ]['Gertrude ' ];
114+ $ chicken2Iri = $ iris ['chickenIris ' ]['Henriette ' ];
115+
116+ $ response = $ this ->createClient ()->request ('GET ' , '/chicken_coops?chickenIri[]= ' .$ chicken1Iri .'&chickenIri[]= ' .$ chicken2Iri );
90117 $ this ->assertResponseIsSuccessful ();
91118
92119 $ responseData = $ response ->toArray ();
93120 $ filteredCoops = $ responseData ['member ' ];
94121
95- $ this ->assertCount (2 , $ filteredCoops, ' Expected 2 coops for URL /chicken_coops?chickenIri[]=/chickens/1&chickenIri[]=/chickens/2 ' );
122+ $ this ->assertCount (2 , $ filteredCoops );
96123
97124 $ allChickenNames = [];
98125 foreach ($ filteredCoops as $ coop ) {
99- foreach ($ coop ['chickens ' ] as $ chickenIri ) {
100- $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ chickenIri );
126+ foreach ($ coop ['chickens ' ] as $ ci ) {
127+ $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ ci );
101128 $ chickenData = $ chickenResponse ->toArray ();
102129 $ allChickenNames [] = $ chickenData ['name ' ];
103130 }
104131 }
105132
106133 sort ($ allChickenNames );
107- $ this ->assertSame (['Gertrude ' , 'Henriette ' ], $ allChickenNames, ' The chicken names in coops do not match the expected values. ' );
134+ $ this ->assertSame (['Gertrude ' , 'Henriette ' ], $ allChickenNames );
108135 }
109136
110137 public function testIriFilterWithOneToManyRelationWithPropertyPlaceholder (): void
111138 {
139+ $ iris = $ this ->getIris ();
140+ $ chickenIri = $ iris ['chickenIris ' ]['Gertrude ' ];
112141 $ client = $ this ->createClient ();
113142
114143 $ propertyName = $ this ->isMongoDB () ? 'chickenReferences ' : 'chickens ' ;
115- $ response = $ client ->request ('GET ' , '/chicken_coops?searchChickenIri[ ' .$ propertyName .']=/chickens/1 ' );
144+ $ response = $ client ->request ('GET ' , '/chicken_coops?searchChickenIri[ ' .$ propertyName .']= ' . $ chickenIri );
116145 $ this ->assertResponseIsSuccessful ();
117146
118147 $ responseData = $ response ->toArray ();
119148 $ filteredCoops = $ responseData ['member ' ];
120149
121- $ this ->assertCount (1 , $ filteredCoops, ' Expected 1 coop for URL /chicken_coops?searchChickenIri[ ' . $ propertyName . ' ]=/chickens/1 ' );
150+ $ this ->assertCount (1 , $ filteredCoops );
122151
123152 $ allChickenNames = [];
124153 foreach ($ filteredCoops as $ coop ) {
125- foreach ($ coop ['chickens ' ] as $ chickenIri ) {
126- $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ chickenIri );
154+ foreach ($ coop ['chickens ' ] as $ ci ) {
155+ $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ ci );
127156 $ chickenData = $ chickenResponse ->toArray ();
128157 $ allChickenNames [] = $ chickenData ['name ' ];
129158 }
130159 }
131160
132161 sort ($ allChickenNames );
133- $ this ->assertSame (['Gertrude ' ], $ allChickenNames, ' The chicken names in coops do not match the expected values. ' );
162+ $ this ->assertSame (['Gertrude ' ], $ allChickenNames );
134163
135164 $ res = $ client ->request ('GET ' , '/chicken_coops?searchChickenIri[ ' .$ propertyName .']=/chickens/595 ' )->toArray ();
136165 $ this ->assertCount (0 , $ res ['member ' ]);
137166 }
138167
139168 public function testIriFilterWithOneToManyRelationWithMultiplePropertyPlaceholder (): void
140169 {
141- $ response = $ this ->createClient ()->request ('GET ' , '/chicken_coops?searchChickenIri[chickens][]=/chickens/1&searchChickenIri[chickens][]=/chickens/2 ' );
170+ $ iris = $ this ->getIris ();
171+ $ chicken1Iri = $ iris ['chickenIris ' ]['Gertrude ' ];
172+ $ chicken2Iri = $ iris ['chickenIris ' ]['Henriette ' ];
173+ $ propertyName = $ this ->isMongoDB () ? 'chickenReferences ' : 'chickens ' ;
174+
175+ $ response = $ this ->createClient ()->request ('GET ' , '/chicken_coops?searchChickenIri[ ' .$ propertyName .'][]= ' .$ chicken1Iri .'&searchChickenIri[ ' .$ propertyName .'][]= ' .$ chicken2Iri );
142176 $ this ->assertResponseIsSuccessful ();
143177
144178 $ responseData = $ response ->toArray ();
145179 $ filteredCoops = $ responseData ['member ' ];
146180
147- $ this ->assertCount (2 , $ filteredCoops, ' Expected 2 coops for URL /chicken_coops?searchChickenIri[chickens][]=/chickens/1&searchChickenIri[chickens][]=/chickens/2 ' );
181+ $ this ->assertCount (2 , $ filteredCoops );
148182
149183 $ allChickenNames = [];
150184 foreach ($ filteredCoops as $ coop ) {
151- foreach ($ coop ['chickens ' ] as $ chickenIri ) {
152- $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ chickenIri );
185+ foreach ($ coop ['chickens ' ] as $ ci ) {
186+ $ chickenResponse = $ this ->createClient ()->request ('GET ' , $ ci );
153187 $ chickenData = $ chickenResponse ->toArray ();
154188 $ allChickenNames [] = $ chickenData ['name ' ];
155189 }
156190 }
157191
158192 sort ($ allChickenNames );
159- $ this ->assertSame (['Gertrude ' , 'Henriette ' ], $ allChickenNames, ' The chicken names in coops do not match the expected values. ' );
193+ $ this ->assertSame (['Gertrude ' , 'Henriette ' ], $ allChickenNames );
160194 }
161195
162196 public function testIriFilterThrowsExceptionWhenPropertyIsMissing (): void
163197 {
164- $ response = self ::createClient ()->request ('GET ' , '/chickens?chickenCoopNoProperty=/chicken_coops/1 ' );
198+ $ iris = $ this ->getIris ();
199+ $ response = self ::createClient ()->request ('GET ' , '/chickens?chickenCoopNoProperty= ' .$ iris ['coopIris ' ][0 ]);
165200 $ this ->assertResponseStatusCodeSame (400 );
166201
167202 $ responseData = $ response ->toArray (false );
0 commit comments