2323use App \Domain \Regulation \RegulationOrderRecord ;
2424use App \Domain \Regulation \Repository \RegulationOrderRecordRepositoryInterface ;
2525use PHPUnit \Framework \TestCase ;
26+ use Symfony \Contracts \Translation \TranslatorInterface ;
2627
2728final class GetCifsIncidentsQueryHandlerTest extends TestCase
2829{
2930 private $ regulationOrderRecordRepository ;
3031 private $ polylineMaker ;
3132 private $ dateUtils ;
33+ private $ translator ;
3234
3335 protected function setUp (): void
3436 {
3537 $ this ->regulationOrderRecordRepository = $ this ->createMock (RegulationOrderRecordRepositoryInterface::class);
3638 $ this ->polylineMaker = $ this ->createMock (PolylineMakerInterface::class);
3739 $ this ->dateUtils = $ this ->createMock (DateUtilsInterface::class);
40+ $ this ->translator = $ this ->createMock (TranslatorInterface::class);
3841 }
3942
4043 public function testGetAllEmpty (): void
@@ -44,7 +47,7 @@ public function testGetAllEmpty(): void
4447 ->method ('findRegulationOrdersForCifsIncidentFormat ' )
4548 ->willReturn ([]);
4649
47- $ handler = new GetCifsIncidentsQueryHandler ($ this ->regulationOrderRecordRepository , $ this ->polylineMaker , $ this ->dateUtils );
50+ $ handler = new GetCifsIncidentsQueryHandler ($ this ->regulationOrderRecordRepository , $ this ->polylineMaker , $ this ->dateUtils , $ this -> translator );
4851 $ regulationOrders = $ handler (new GetCifsIncidentsQuery ());
4952
5053 $ this ->assertEquals ([], $ regulationOrders );
@@ -90,38 +93,40 @@ public function testGetAll(): void
9093 $ period4Id = '0661e7ed-e549-7e4b-8000-945882a092c4 ' ;
9194 $ period5Id = '066e2bff-d436-7f16-8000-57d9f6b99960 ' ;
9295
96+ $ descriptionNoEntry = 'Interdiction d \'accès ' ;
97+ $ descriptionAlternateRoad = 'Route à alternance ' ;
98+
9399 $ incident1 = new CifsIncidentView (
94100 id: '2024T1:02d5eb61-9ca3-4e67-aacd-726f124382d0:0 ' ,
95101 creationTime: new \DateTimeImmutable ('2023-11-01T00:00:00+00:00 ' ),
96102 type: 'ROAD_CLOSED ' ,
97- subType: 'ROAD_BLOCKED_HAZARD ' ,
98- street: 'Rue des Arts ' ,
103+ description: $ descriptionNoEntry ,
99104 direction: 'BOTH_DIRECTIONS ' ,
100105 polyline: $ polyline1Merged ,
101106 startTime: new \DateTimeImmutable ('2023-11-02T00:00:00+00:00 ' ),
102107 endTime: new \DateTimeImmutable ('2023-11-07T00:00:00+00:00 ' ),
103108 schedule: [],
109+ subType: 'ROAD_BLOCKED_HAZARD ' ,
104110 );
105111
106112 $ incident1bis = new CifsIncidentView (
107113 id: '2024T1:066e98a9-0ce0-7e4b-8000-677c1eafc53d:0 ' ,
108114 creationTime: $ incident1 ->creationTime ,
109115 type: $ incident1 ->type ,
110- subType: $ incident1 ->subType ,
111- street: 'Zone Olympique ' ,
116+ description: $ descriptionNoEntry ,
112117 direction: $ incident1 ->direction ,
113118 polyline: $ polyline1bis ,
114119 startTime: $ incident1 ->startTime ,
115120 endTime: new \DateTimeImmutable ('2023-11-07T00:00:00+00:00 ' ),
116121 schedule: $ incident1 ->schedule ,
122+ subType: $ incident1 ->subType ,
117123 );
118124
119125 $ incident3 = new CifsIncidentView (
120126 id: \sprintf ('2024T2:9698b212-705c-4c46-8968-63b5a55a4d66:%s ' , $ period1Id ),
121127 creationTime: new \DateTimeImmutable ('2023-11-01T00:00:00+00:00 ' ),
122128 type: 'HAZARD ' ,
123- subType: 'HAZARD_ON_ROAD_LANE_CLOSED ' ,
124- street: 'Avenue de Fonneuve ' ,
129+ description: $ descriptionAlternateRoad ,
125130 direction: 'BOTH_DIRECTIONS ' ,
126131 polyline: $ polyline3 ,
127132 startTime: new \DateTimeImmutable ('2023-11-02T00:00:00+00:00 ' ),
@@ -148,14 +153,14 @@ public function testGetAll(): void
148153 ],
149154 ],
150155 ],
156+ subType: 'HAZARD_ON_ROAD_LANE_CLOSED ' ,
151157 );
152158
153159 $ incident4 = new CifsIncidentView (
154160 id: \sprintf ('2024T2:9698b212-705c-4c46-8968-63b5a55a4d66:%s ' , $ period2Id ),
155161 creationTime: $ incident3 ->creationTime ,
156162 type: $ incident3 ->type ,
157- subType: $ incident3 ->subType ,
158- street: $ incident3 ->street ,
163+ description: $ incident3 ->description ,
159164 direction: $ incident3 ->direction ,
160165 polyline: $ incident3 ->polyline ,
161166 startTime: new \DateTimeImmutable ('2023-11-03T00:00:00+00:00 ' ),
@@ -174,14 +179,14 @@ public function testGetAll(): void
174179 ],
175180 ],
176181 ],
182+ subType: $ incident3 ->subType ,
177183 );
178184
179185 $ incident5 = new CifsIncidentView (
180186 id: \sprintf ('2024T2:9698b212-705c-4c46-8968-63b5a55a4d66:%s ' , $ period3Id ),
181187 creationTime: $ incident3 ->creationTime ,
182188 type: $ incident3 ->type ,
183- subType: $ incident3 ->subType ,
184- street: $ incident3 ->street ,
189+ description: $ incident3 ->description ,
185190 direction: $ incident3 ->direction ,
186191 polyline: $ incident3 ->polyline ,
187192 startTime: $ incident4 ->startTime ,
@@ -194,14 +199,14 @@ public function testGetAll(): void
194199 ],
195200 ],
196201 ],
202+ subType: $ incident3 ->subType ,
197203 );
198204
199205 $ incident6 = new CifsIncidentView (
200206 id: \sprintf ('2024T2:9698b212-705c-4c46-8968-63b5a55a4d66:%s ' , $ period4Id ),
201207 creationTime: $ incident3 ->creationTime ,
202208 type: $ incident3 ->type ,
203- subType: $ incident3 ->subType ,
204- street: $ incident3 ->street ,
209+ description: $ incident3 ->description ,
205210 direction: $ incident3 ->direction ,
206211 polyline: $ incident3 ->polyline ,
207212 startTime: $ incident4 ->startTime ,
@@ -214,14 +219,14 @@ public function testGetAll(): void
214219 ],
215220 ],
216221 ],
222+ subType: $ incident3 ->subType ,
217223 );
218224
219225 $ incident7 = new CifsIncidentView (
220226 id: \sprintf ('2024T2:9698b212-705c-4c46-8968-63b5a55a4d66:%s ' , $ period5Id ),
221227 creationTime: $ incident3 ->creationTime ,
222228 type: $ incident3 ->type ,
223- subType: $ incident3 ->subType ,
224- street: $ incident3 ->street ,
229+ description: $ incident3 ->description ,
225230 direction: $ incident3 ->direction ,
226231 polyline: $ incident3 ->polyline ,
227232 startTime: $ incident4 ->startTime ,
@@ -234,6 +239,7 @@ public function testGetAll(): void
234239 ],
235240 ],
236241 ],
242+ subType: $ incident3 ->subType ,
237243 );
238244
239245 $ regulationOrderRecord1 = $ this ->createMock (RegulationOrderRecord::class);
@@ -276,15 +282,20 @@ public function testGetAll(): void
276282 ->with (new \DateTimeImmutable ('2023-11-06 00:00:00 ' ), 1 )
277283 ->willReturn (new \DateTimeImmutable ('2023-11-07 00:00:00 ' ));
278284
285+ $ this ->translator
286+ ->expects (self ::exactly (7 ))
287+ ->method ('trans ' )
288+ ->with (self ::logicalOr (
289+ self ::equalTo ('regulation.measure.type.noEntry ' ),
290+ self ::equalTo ('regulation.measure.type.alternateRoad ' ),
291+ ))
292+ ->willReturnCallback (fn (string $ id ) => $ id === 'regulation.measure.type.noEntry ' ? $ descriptionNoEntry : $ descriptionAlternateRoad );
293+
279294 $ location1 = $ this ->createMock (Location::class);
280295 $ location1
281296 ->expects (self ::once ())
282297 ->method ('getUuid ' )
283298 ->willReturn ('02d5eb61-9ca3-4e67-aacd-726f124382d0 ' );
284- $ location1
285- ->expects (self ::once ())
286- ->method ('getCifsStreetLabel ' )
287- ->willReturn ('Rue des Arts ' );
288299 $ location1
289300 ->expects (self ::once ())
290301 ->method ('getGeometry ' )
@@ -300,10 +311,6 @@ public function testGetAll(): void
300311 ->expects (self ::once ())
301312 ->method ('getRawGeoJSON ' )
302313 ->willReturn ($ rawGeoJSON );
303- $ location1bis
304- ->expects (self ::once ())
305- ->method ('getCifsStreetLabel ' )
306- ->willReturn ('Zone Olympique ' );
307314 $ location1bis
308315 ->expects (self ::once ())
309316 ->method ('getGeometry ' )
@@ -572,10 +579,6 @@ public function testGetAll(): void
572579 ->expects (self ::once ())
573580 ->method ('getUuid ' )
574581 ->willReturn ('9698b212-705c-4c46-8968-63b5a55a4d66 ' );
575- $ location2
576- ->expects (self ::once ())
577- ->method ('getCifsStreetLabel ' )
578- ->willReturn ('Avenue de Fonneuve ' );
579582 $ location2
580583 ->expects (self ::once ())
581584 ->method ('getGeometry ' )
@@ -621,7 +624,7 @@ public function testGetAll(): void
621624 $ uuid2 => ['uuid ' => $ uuid2 , 'overallStartDate ' => $ startDate2 , 'overallEndDate ' => $ endDate2 ],
622625 ]);
623626
624- $ handler = new GetCifsIncidentsQueryHandler ($ this ->regulationOrderRecordRepository , $ this ->polylineMaker , $ this ->dateUtils );
627+ $ handler = new GetCifsIncidentsQueryHandler ($ this ->regulationOrderRecordRepository , $ this ->polylineMaker , $ this ->dateUtils , $ this -> translator );
625628 $ incidents = $ handler (new GetCifsIncidentsQuery ());
626629 $ this ->assertEquals (
627630 [$ incident1 , $ incident1bis , $ incident3 , $ incident4 , $ incident5 , $ incident6 , $ incident7 ],
@@ -641,6 +644,7 @@ public function testFilters(): void
641644 $ this ->regulationOrderRecordRepository ,
642645 $ this ->polylineMaker ,
643646 $ this ->dateUtils ,
647+ $ this ->translator ,
644648 new CifsFilterSet (
645649 allowedSources: ['my_source ' ],
646650 excludedIdentifiers: ['identifier1 ' ],
0 commit comments