22
33namespace App \Packages \Features \QueryUseCases \Tests ;
44
5+ use Database \Seeders \CountrySeeder ;
56use Illuminate \Support \Facades \DB ;
67use Mockery ;
78use Tests \TestCase ;
1011use App \Packages \Features \QueryUseCases \Dto \WorldHeritageDto ;
1112use App \Packages \Domains \WorldHeritageEntity ;
1213use App \Packages \Domains \WorldHeritageRepositoryInterface ;
13- use App \Packages \Features \QueryUseCases \Factory \WorldHeritageListQueryFactory ;
14- use App \Packages \Features \QueryUseCases \ListQuery \WorldHeritageListQuery ;
1514
1615class CreateWorldHeritageUseCaseTest extends TestCase
1716{
1817 protected function setUp (): void
1918 {
2019 parent ::setUp ();
2120 $ this ->refresh ();
21+ $ seeder = new CountrySeeder ();
22+ $ seeder ->run ();
2223 }
2324
2425 protected function tearDown (): void
@@ -39,15 +40,16 @@ private function refresh(): void
3940 private function arrayData (): array
4041 {
4142 return [
43+ 'id ' => 1 ,
4244 'unesco_id ' => '668 ' ,
4345 'official_name ' => 'Historic Monuments of Ancient Nara ' ,
4446 'name ' => 'Historic Monuments of Ancient Nara ' ,
4547 'name_jp ' => '古都奈良の文化財 ' ,
4648 'country ' => 'Japan ' ,
4749 'region ' => 'Asia ' ,
48- 'state_party ' => 'JP ' ,
4950 'category ' => 'cultural ' ,
5051 'criteria ' => ['ii ' , 'iii ' , 'v ' ],
52+ 'state_party ' => null ,
5153 'year_inscribed ' => 1998 ,
5254 'area_hectares ' => 442.0 ,
5355 'buffer_zone_hectares ' => 320.0 ,
@@ -57,92 +59,16 @@ private function arrayData(): array
5759 'short_description ' => 'Temples and shrines of the first permanent capital of Japan. ' ,
5860 'image_url ' => '' ,
5961 'unesco_site_url ' => 'https://whc.unesco.org/en/list/668/ ' ,
62+ 'state_parties ' => ['JP ' ],
63+ 'state_parties_meta ' => [
64+ 'JP ' => [
65+ 'is_primary ' => true ,
66+ 'inscription_year ' => 1998 ,
67+ ],
68+ ],
6069 ];
6170 }
6271
63- private function mockEntity (): WorldHeritageEntity
64- {
65- $ mock = Mockery::mock (WorldHeritageEntity::class);
66-
67- $ mock
68- ->shouldReceive ('getId ' )
69- ->andReturn ($ this ->arrayData ()['id ' ] ?? null );
70-
71- $ mock
72- ->shouldReceive ('getUnescoId ' )
73- ->andReturn ($ this ->arrayData ()['unesco_id ' ]);
74-
75- $ mock
76- ->shouldReceive ('getOfficialName ' )
77- ->andReturn ($ this ->arrayData ()['official_name ' ]);
78-
79- $ mock
80- ->shouldReceive ('getName ' )
81- ->andReturn ($ this ->arrayData ()['name ' ]);
82-
83- $ mock
84- ->shouldReceive ('getCountry ' )
85- ->andReturn ($ this ->arrayData ()['country ' ]);
86-
87- $ mock
88- ->shouldReceive ('getRegion ' )
89- ->andReturn ($ this ->arrayData ()['region ' ]);
90-
91- $ mock
92- ->shouldReceive ('getStateParty ' )
93- ->andReturn ($ this ->arrayData ()['state_party ' ]);
94-
95- $ mock
96- ->shouldReceive ('getCategory ' )
97- ->andReturn ($ this ->arrayData ()['category ' ]);
98-
99- $ mock
100- ->shouldReceive ('getCriteria ' )
101- ->andReturn ($ this ->arrayData ()['criteria ' ]);
102-
103- $ mock
104- ->shouldReceive ('getYearInscribed ' )
105- ->andReturn ($ this ->arrayData ()['year_inscribed ' ]);
106-
107- $ mock
108- ->shouldReceive ('getAreaHectares ' )
109- ->andReturn ($ this ->arrayData ()['area_hectares ' ]);
110-
111- $ mock
112- ->shouldReceive ('getBufferZoneHectares ' )
113- ->andReturn ($ this ->arrayData ()['buffer_zone_hectares ' ]);
114-
115- $ mock
116- ->shouldReceive ('getLatitude ' )
117- ->andReturn ($ this ->arrayData ()['latitude ' ]);
118-
119- $ mock
120- ->shouldReceive ('getLongitude ' )
121- ->andReturn ($ this ->arrayData ()['longitude ' ]);
122-
123- $ mock
124- ->shouldReceive ('isEndangered ' )
125- ->andReturn ($ this ->arrayData ()['is_endangered ' ]);
126-
127- $ mock
128- ->shouldReceive ('getNameJp ' )
129- ->andReturn ($ this ->arrayData ()['name_jp ' ]);
130-
131- $ mock
132- ->shouldReceive ('getShortDescription ' )
133- ->andReturn ($ this ->arrayData ()['short_description ' ]);
134-
135- $ mock
136- ->shouldReceive ('getImageUrl ' )
137- ->andReturn ($ this ->arrayData ()['image_url ' ]);
138-
139- $ mock
140- ->shouldReceive ('getUnescoSiteUrl ' )
141- ->andReturn ($ this ->arrayData ()['unesco_site_url ' ]);
142-
143- return $ mock ;
144- }
145-
14672 private function mockRepository (): WorldHeritageRepositoryInterface
14773 {
14874 $ mock = Mockery::mock (WorldHeritageRepositoryInterface::class);
@@ -170,101 +96,15 @@ private function mockRepository(): WorldHeritageRepositoryInterface
17096 bufferZoneHectares: $ this ->arrayData ()['buffer_zone_hectares ' ],
17197 shortDescription: $ this ->arrayData ()['short_description ' ],
17298 imageUrl: $ this ->arrayData ()['image_url ' ],
173- unescoSiteUrl: $ this ->arrayData ()['unesco_site_url ' ]
99+ unescoSiteUrl: $ this ->arrayData ()['unesco_site_url ' ],
100+ statePartyCodes: $ this ->arrayData ()['state_parties ' ],
101+ statePartyMeta: $ this ->arrayData ()['state_parties_meta ' ] ?? []
174102 )
175103 );
176104
177105 return $ mock ;
178106 }
179107
180- private function mockListQuery (): WorldHeritageListQuery
181- {
182- $ factory = Mockery::mock (
183- 'alias: ' . WorldHeritageListQueryFactory::class
184- );
185-
186- $ mock = Mockery::mock (WorldHeritageListQuery::class);
187-
188- $ factory
189- ->shouldReceive ('build ' )
190- ->with (Mockery::type ($ this ->arrayData ()))
191- ->andReturn ($ mock );
192-
193- $ mock
194- ->shouldReceive ('getUnescoId ' )
195- ->andReturn ($ this ->arrayData ()['unesco_id ' ]);
196-
197- $ mock
198- ->shouldReceive ('getOfficialName ' )
199- ->andReturn ($ this ->arrayData ()['official_name ' ]);
200-
201- $ mock
202- ->shouldReceive ('getName ' )
203- ->andReturn ($ this ->arrayData ()['name ' ]);
204-
205- $ mock
206- ->shouldReceive ('getCountry ' )
207- ->andReturn ($ this ->arrayData ()['country ' ]);
208-
209- $ mock
210- ->shouldReceive ('getRegion ' )
211- ->andReturn ($ this ->arrayData ()['region ' ]);
212-
213- $ mock
214- ->shouldReceive ('getStateParty ' )
215- ->andReturn ($ this ->arrayData ()['state_party ' ]);
216-
217- $ mock
218- ->shouldReceive ('getCategory ' )
219- ->andReturn ($ this ->arrayData ()['category ' ]);
220-
221- $ mock
222- ->shouldReceive ('getCriteria ' )
223- ->andReturn ($ this ->arrayData ()['criteria ' ]);
224-
225- $ mock
226- ->shouldReceive ('getYearInscribed ' )
227- ->andReturn ($ this ->arrayData ()['year_inscribed ' ]);
228-
229- $ mock
230- ->shouldReceive ('getAreaHectares ' )
231- ->andReturn ($ this ->arrayData ()['area_hectares ' ]);
232-
233- $ mock
234- ->shouldReceive ('getBufferZoneHectares ' )
235- ->andReturn ($ this ->arrayData ()['buffer_zone_hectares ' ]);
236-
237- $ mock
238- ->shouldReceive ('getLatitude ' )
239- ->andReturn ($ this ->arrayData ()['latitude ' ]);
240-
241- $ mock
242- ->shouldReceive ('getLongitude ' )
243- ->andReturn ($ this ->arrayData ()['longitude ' ]);
244-
245- $ mock
246- ->shouldReceive ('isEndangered ' )
247- ->andReturn ($ this ->arrayData ()['is_endangered ' ]);
248-
249- $ mock
250- ->shouldReceive ('getNameJp ' )
251- ->andReturn ($ this ->arrayData ()['name_jp ' ]);
252-
253- $ mock
254- ->shouldReceive ('getShortDescription ' )
255- ->andReturn ($ this ->arrayData ()['short_description ' ]);
256-
257- $ mock
258- ->shouldReceive ('getImageUrl ' )
259- ->andReturn ($ this ->arrayData ()['image_url ' ]);
260-
261- $ mock
262- ->shouldReceive ('getUnescoSiteUrl ' )
263- ->andReturn ($ this ->arrayData ()['unesco_site_url ' ]);
264-
265- return $ mock ;
266- }
267-
268108 public function test_use_case_check_type (): void
269109 {
270110 $ useCase = new CreateWorldHeritageUseCase (
@@ -303,5 +143,7 @@ public function test_use_case_check_value(): void
303143 $ this ->assertEquals ($ this ->arrayData ()['short_description ' ], $ result ->getShortDescription ());
304144 $ this ->assertEquals ($ this ->arrayData ()['image_url ' ], $ result ->getImageUrl ());
305145 $ this ->assertEquals ($ this ->arrayData ()['unesco_site_url ' ], $ result ->getUnescoSiteUrl ());
146+ $ this ->assertEquals ($ this ->arrayData ()['state_parties ' ], $ result ->getStatePartyCodes ());
147+ $ this ->assertEquals ($ this ->arrayData ()['state_parties_meta ' ], $ result ->getStatePartiesMeta ());
306148 }
307149}
0 commit comments