From 555d0eacfc5b1258f2b64a7ef969ac0f390595eb Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Mon, 25 Aug 2025 08:56:13 +0900 Subject: [PATCH 1/2] feat: fix tests --- .../WorldHeritageEntityCollectionTest.php | 7 +- .../Tests/CreateWorldHeritageUseCaseTest.php | 1 - .../Tests/CreateWorldHeritagesUseCaseTest.php | 141 +++++++-------- .../Tests/WorldHeritageDtoCollectionTest.php | 170 ++++++++++-------- 4 files changed, 161 insertions(+), 158 deletions(-) diff --git a/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php b/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php index b3d47de..473700d 100644 --- a/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php +++ b/src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php @@ -121,13 +121,12 @@ private static function arraySingleData(): array private static function arrayMultiData(): array { return [ - // 既存: ブナ林(ヨーロッパ各地) [ 'unesco_id' => 1133, 'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe", 'name' => "Ancient and Primeval Beech Forests", 'name_jp' => null, - 'country' => 'Slovakia', // 便宜上代表国(実際は汎欧州の連続資産) + 'country' => 'Slovakia', 'region' => 'Europe', 'category' => 'natural', 'criteria' => ['ix'], @@ -165,8 +164,6 @@ private static function arrayMultiData(): array 'UA' => ['is_primary' => false, 'inscription_year' => 2007], ], ], - - // 追加: シルクロード(長安–天山回廊) [ 'unesco_id' => 1442, 'official_name' => "Silk Roads: the Routes Network of Chang'an-Tianshan Corridor", @@ -196,8 +193,6 @@ private static function arrayMultiData(): array ]; } - - public function test_collection_check_type(): void { $collection = new WorldHeritageEntityCollection( diff --git a/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritageUseCaseTest.php b/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritageUseCaseTest.php index a42e686..677b8a3 100644 --- a/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritageUseCaseTest.php +++ b/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritageUseCaseTest.php @@ -40,7 +40,6 @@ private function refresh(): void private function arrayData(): array { return [ - 'id' => 1, 'unesco_id' => '668', 'official_name' => 'Historic Monuments of Ancient Nara', 'name' => 'Historic Monuments of Ancient Nara', diff --git a/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritagesUseCaseTest.php b/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritagesUseCaseTest.php index 8060ea8..852e254 100644 --- a/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritagesUseCaseTest.php +++ b/src/app/Packages/Features/QueryUseCases/Tests/CreateWorldHeritagesUseCaseTest.php @@ -2,11 +2,13 @@ namespace App\Packages\Features\QueryUseCases\Tests; +use App\Models\Country; use App\Models\WorldHeritage; use App\Packages\Features\QueryUseCases\Dto\WorldHeritageDtoCollection; use Illuminate\Support\Facades\DB; use Tests\TestCase; use Mockery; +use Database\Seeders\CountrySeeder; use App\Packages\Domains\WorldHeritageEntityCollection; use App\Packages\Domains\WorldHeritageRepositoryInterface; use App\Packages\Features\QueryUseCases\UseCase\CreateWorldManyHeritagesUseCase; @@ -18,6 +20,8 @@ protected function setUp(): void { parent::setUp(); $this->refresh(); + $seeder = new CountrySeeder(); + $seeder->run(); $this->repository = Mockery::mock(WorldHeritageRepositoryInterface::class); } @@ -32,6 +36,8 @@ private function refresh(): void if (env('APP_ENV') === 'testing') { DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=0;'); WorldHeritage::truncate(); + Country::truncate(); + DB::table('site_state_parties')->truncate(); DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); } } @@ -55,91 +61,74 @@ private static function arrayData(): array return [ [ 'id' => 1, - 'unesco_id' => '660', - 'official_name' => 'Buddhist Monuments in the Horyu-ji Area', - 'name' => 'Buddhist Monuments in the Horyu-ji Area', - 'name_jp' => '法隆寺地域の仏教建造物', - 'country' => 'Japan', - 'region' => 'Asia', - 'state_party' => 'JP', - 'category' => 'cultural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, + 'unesco_id' => '1133', + 'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe", + 'name' => "Ancient and Primeval Beech Forests", + 'name_jp' => null, + 'country' => 'Slovakia', + 'region' => 'Europe', + 'category' => 'natural', + 'criteria' => ['ix'], + 'state_party' => null, + 'year_inscribed' => 2007, + 'area_hectares' => 99947.81, + 'buffer_zone_hectares' => 296275.8, 'is_endangered' => false, - 'latitude' => 34.6147, - 'longitude' => 135.7355, - 'short_description' => "Early Buddhist wooden structures including the world's oldest wooden building.", + 'latitude' => 0.0, + 'longitude' => 0.0, + 'short_description' => 'Transnational serial property of European beech forests illustrating post-glacial expansion and ecological processes across Europe.', 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/660/', - 'created_at' => now(), 'updated_at' => now(), + 'unesco_site_url' => 'https://whc.unesco.org/en/list/1133/', + 'state_parties' => [ + 'AL','AT','BE','BA','BG','HR','CZ','FR','DE','IT','MK','PL','RO','SK','SI','ES','CH','UA' + ], + 'state_parties_meta' => [ + 'AL' => ['is_primary' => false, 'inscription_year' => 2007], + 'AT' => ['is_primary' => false, 'inscription_year' => 2007], + 'BE' => ['is_primary' => false, 'inscription_year' => 2007], + 'BA' => ['is_primary' => false, 'inscription_year' => 2007], + 'BG' => ['is_primary' => false, 'inscription_year' => 2007], + 'HR' => ['is_primary' => false, 'inscription_year' => 2007], + 'CZ' => ['is_primary' => false, 'inscription_year' => 2007], + 'FR' => ['is_primary' => false, 'inscription_year' => 2007], + 'DE' => ['is_primary' => false, 'inscription_year' => 2007], + 'IT' => ['is_primary' => false, 'inscription_year' => 2007], + 'MK' => ['is_primary' => false, 'inscription_year' => 2007], + 'PL' => ['is_primary' => false, 'inscription_year' => 2007], + 'RO' => ['is_primary' => false, 'inscription_year' => 2007], + 'SK' => ['is_primary' => true, 'inscription_year' => 2007], + 'SI' => ['is_primary' => false, 'inscription_year' => 2007], + 'ES' => ['is_primary' => false, 'inscription_year' => 2007], + 'CH' => ['is_primary' => false, 'inscription_year' => 2007], + 'UA' => ['is_primary' => false, 'inscription_year' => 2007], + ], ], [ 'id' => 2, - 'unesco_id' => '661', - 'official_name' => 'Himeji-jo', - 'name' => 'Himeji-jo', - 'name_jp' => '姫路城', - 'country' => 'Japan', + 'unesco_id' => '1442', + 'official_name' => "Silk Roads: the Routes Network of Chang'an-Tianshan Corridor", + 'name' => "Silk Roads: Chang'an–Tianshan Corridor", + 'name_jp' => 'シルクロード:長安-天山回廊の交易路網', + 'country' => 'China, Kazakhstan, Kyrgyzstan', 'region' => 'Asia', - 'state_party' => 'JP', 'category' => 'cultural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, - 'is_endangered' => false, - 'latitude' => 34.8394, - 'longitude' => 134.6939, - 'short_description' => "A masterpiece of Japanese castle architecture in original form.", - 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/661/', - 'created_at' => now(), 'updated_at' => now(), - ], - [ - 'id' => 3, - 'unesco_id' => '662', - 'official_name' => 'Yakushima', - 'name' => 'Yakushima', - 'name_jp' => '屋久島', - 'country' => 'Japan', - 'region' => 'Asia', - 'state_party' => 'JP', - 'category' => 'natural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, - 'is_endangered' => false, - 'latitude' => 30.3581, - 'longitude' => 130.546, - 'short_description' => "A subtropical island with ancient cedar forests and diverse ecosystems.", - 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/662/', - 'created_at' => now(), 'updated_at' => now(), - ], - [ - 'id' => 4, - 'unesco_id' => '663', - 'official_name' => 'Shirakami-Sanchi', - 'name' => 'Shirakami-Sanchi', - 'name_jp' => '白神山地', - 'country' => 'Japan', - 'region' => 'Asia', - 'state_party' => 'JP', - 'category' => 'natural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, + 'criteria' => ['ii','iii','vi'], + 'state_party' => null, + 'year_inscribed' => 2014, + 'area_hectares' => 0.0, + 'buffer_zone_hectares' => 0.0, 'is_endangered' => false, - 'latitude' => 40.5167, - 'longitude' => 140.05, - 'short_description' => "Pristine beech forest with minimal human impact.", + 'latitude' => 0.0, + 'longitude' => 0.0, + 'short_description' => 'Transnational Silk Road corridor across China, Kazakhstan and Kyrgyzstan illustrating exchange of goods, ideas and beliefs.', 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/663/', - 'created_at' => now(), 'updated_at' => now(), + 'unesco_site_url' => 'https://whc.unesco.org/en/list/1442/', + 'state_parties' => ['CN','KZ','KG'], + 'state_parties_meta' => [ + 'CN' => ['is_primary' => true, 'inscription_year' => 2014], + 'KZ' => ['is_primary' => false, 'inscription_year' => 2014], + 'KG' => ['is_primary' => false, 'inscription_year' => 2014], + ], ], ]; } diff --git a/src/app/Packages/Features/QueryUseCases/Tests/WorldHeritageDtoCollectionTest.php b/src/app/Packages/Features/QueryUseCases/Tests/WorldHeritageDtoCollectionTest.php index ea01b2e..f4ca7b8 100644 --- a/src/app/Packages/Features/QueryUseCases/Tests/WorldHeritageDtoCollectionTest.php +++ b/src/app/Packages/Features/QueryUseCases/Tests/WorldHeritageDtoCollectionTest.php @@ -2,9 +2,11 @@ namespace App\Packages\Features\QueryUseCases\Tests; -use App\Packages\Domains\WorldHeritageQueryService; +use Database\Seeders\CountrySeeder; use Tests\TestCase; -use Mockery; +use Illuminate\Support\Facades\DB; +use App\Models\WorldHeritage; +use App\Models\Country; use App\Packages\Features\QueryUseCases\Factory\WorldHeritageDtoCollectionFactory; use Illuminate\Support\Str; use App\Packages\Features\QueryUseCases\Dto\WorldHeritageDtoCollection; @@ -14,100 +16,102 @@ class WorldHeritageDtoCollectionTest extends TestCase protected function setUp(): void { parent::setUp(); + $this->refresh(); + $seeder = new CountrySeeder(); + $seeder->run(); } protected function tearDown(): void { + $this->refresh(); parent::tearDown(); } + private function refresh(): void + { + if (env('APP_ENV') === 'testing') { + DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=0;'); + WorldHeritage::truncate(); + Country::truncate(); + DB::table('site_state_parties')->truncate(); + DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;'); + } + } + private static function arrayData(): array { return [ [ 'id' => 1, - 'unesco_id' => '660', - 'official_name' => 'Buddhist Monuments in the Horyu-ji Area', - 'name' => 'Buddhist Monuments in the Horyu-ji Area', - 'name_jp' => '法隆寺地域の仏教建造物', - 'country' => 'Japan', - 'region' => 'Asia', - 'state_party' => 'JP', - 'category' => 'cultural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, + 'unesco_id' => '1133', + 'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe", + 'name' => "Ancient and Primeval Beech Forests", + 'name_jp' => null, + 'country' => 'Slovakia', + 'region' => 'Europe', + 'category' => 'natural', + 'criteria' => ['ix'], + 'state_party' => null, + 'year_inscribed' => 2007, + 'area_hectares' => 99947.81, + 'buffer_zone_hectares' => 296275.8, 'is_endangered' => false, - 'latitude' => 34.6147, - 'longitude' => 135.7355, - 'short_description' => "Early Buddhist wooden structures including the world's oldest wooden building.", + 'latitude' => 0.0, + 'longitude' => 0.0, + 'short_description' => 'Transnational serial property of European beech forests illustrating post-glacial expansion and ecological processes across Europe.', 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/660/', + 'unesco_site_url' => 'https://whc.unesco.org/en/list/1133/', + 'state_parties' => [ + 'AL','AT','BE','BA','BG','HR','CZ','FR','DE','IT','MK','PL','RO','SK','SI','ES','CH','UA' + ], + 'state_parties_meta' => [ + 'AL' => ['is_primary' => false, 'inscription_year' => 2007], + 'AT' => ['is_primary' => false, 'inscription_year' => 2007], + 'BE' => ['is_primary' => false, 'inscription_year' => 2007], + 'BA' => ['is_primary' => false, 'inscription_year' => 2007], + 'BG' => ['is_primary' => false, 'inscription_year' => 2007], + 'HR' => ['is_primary' => false, 'inscription_year' => 2007], + 'CZ' => ['is_primary' => false, 'inscription_year' => 2007], + 'FR' => ['is_primary' => false, 'inscription_year' => 2007], + 'DE' => ['is_primary' => false, 'inscription_year' => 2007], + 'IT' => ['is_primary' => false, 'inscription_year' => 2007], + 'MK' => ['is_primary' => false, 'inscription_year' => 2007], + 'PL' => ['is_primary' => false, 'inscription_year' => 2007], + 'RO' => ['is_primary' => false, 'inscription_year' => 2007], + 'SK' => ['is_primary' => true, 'inscription_year' => 2007], + 'SI' => ['is_primary' => false, 'inscription_year' => 2007], + 'ES' => ['is_primary' => false, 'inscription_year' => 2007], + 'CH' => ['is_primary' => false, 'inscription_year' => 2007], + 'UA' => ['is_primary' => false, 'inscription_year' => 2007], + ], ], [ 'id' => 2, - 'unesco_id' => '661', - 'official_name' => 'Himeji-jo', - 'name' => 'Himeji-jo', - 'name_jp' => '姫路城', - 'country' => 'Japan', + 'unesco_id' => '1442', + 'official_name' => "Silk Roads: the Routes Network of Chang'an-Tianshan Corridor", + 'name' => "Silk Roads: Chang'an–Tianshan Corridor", + 'name_jp' => 'シルクロード:長安-天山回廊の交易路網', + 'country' => 'China, Kazakhstan, Kyrgyzstan', 'region' => 'Asia', - 'state_party' => 'JP', 'category' => 'cultural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, - 'is_endangered' => false, - 'latitude' => 34.8394, - 'longitude' => 134.6939, - 'short_description' => "A masterpiece of Japanese castle architecture in original form.", - 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/661/', - ], - [ - 'id' => 3, - 'unesco_id' => '662', - 'official_name' => 'Yakushima', - 'name' => 'Yakushima', - 'name_jp' => '屋久島', - 'country' => 'Japan', - 'region' => 'Asia', - 'state_party' => 'JP', - 'category' => 'natural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, + 'criteria' => ['ii','iii','vi'], + 'state_party' => null, + 'year_inscribed' => 2014, + 'area_hectares' => 0.0, + 'buffer_zone_hectares' => 0.0, 'is_endangered' => false, - 'latitude' => 30.3581, - 'longitude' => 130.546, - 'short_description' => "A subtropical island with ancient cedar forests and diverse ecosystems.", + 'latitude' => 0.0, + 'longitude' => 0.0, + 'short_description' => 'Transnational Silk Road corridor across China, Kazakhstan and Kyrgyzstan illustrating exchange of goods, ideas and beliefs.', 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/662/', + 'unesco_site_url' => 'https://whc.unesco.org/en/list/1442/', + 'state_parties' => ['CN','KZ','KG'], + 'state_parties_meta' => [ + 'CN' => ['is_primary' => true, 'inscription_year' => 2014], + 'KZ' => ['is_primary' => false, 'inscription_year' => 2014], + 'KG' => ['is_primary' => false, 'inscription_year' => 2014], + ], ], - [ - 'id' => 4, - 'unesco_id' => '663', - 'official_name' => 'Shirakami-Sanchi', - 'name' => 'Shirakami-Sanchi', - 'name_jp' => '白神山地', - 'country' => 'Japan', - 'region' => 'Asia', - 'state_party' => 'JP', - 'category' => 'natural', - 'criteria' => ['ii', 'iii', 'v'], - 'year_inscribed' => 1993, - 'area_hectares' => 442.0, - 'buffer_zone_hectares' => 320.0, - 'is_endangered' => false, - 'latitude' => 40.5167, - 'longitude' => 140.05, - 'short_description' => "Pristine beech forest with minimal human impact.", - 'image_url' => '', - 'unesco_site_url' => 'https://whc.unesco.org/en/list/663/', - ] ]; } @@ -128,11 +132,27 @@ public function test_check_dto_collection_value(): void $this->assertEquals(count($data), $arrayDtoCollection); $actual = collect($dtoCollection->toArray())->map(function($item) { + if (is_array($item['statePartyCodes'])) { + $item['state_parties'] = collect($item['statePartyCodes'])->map(function($code) { + return Str::upper($code); + })->toArray(); + } + return collect($item)->keyBy(function($value, $key) { + return Str::snake($key); + })->toArray(); + })->toArray(); + + $expected = collect($data)->map(function($item) { + if (is_array($item['state_parties'])) { + $item['state_party_codes'] = collect($item['state_parties'])->map(function($code) { + return Str::upper($code); + })->toArray(); + } return collect($item)->keyBy(function($value, $key) { return Str::snake($key); })->toArray(); })->toArray(); - $this->assertEquals($this->arrayData(), $actual); + $this->assertEquals($expected, $actual); } } \ No newline at end of file From 534b6aca866f85f31985583e7e0b2af0d0ce5c5d Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Mon, 25 Aug 2025 09:00:41 +0900 Subject: [PATCH 2/2] feat: add new array keys --- .../Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php | 2 +- .../Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php | 4 +++- .../Factory/WorldHeritageDtoCollectionFactory.php | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php index 52d38f1..00a8e20 100644 --- a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php +++ b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDto.php @@ -169,7 +169,7 @@ public function toArray(): array 'short_description' => $this->getShortDescription(), 'image_url' => $this->getImageUrl(), 'unesco_site_url' => $this->getUnescoSiteUrl(), - 'state_parties' => $this->getStatePartyCodes(), + 'state_party_codes' => $this->getStatePartyCodes(), 'state_parties_meta' => $this->getStatePartiesMeta(), ]; } diff --git a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php index 8976ac3..6a41bed 100644 --- a/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php +++ b/src/app/Packages/Features/QueryUseCases/Dto/WorldHeritageDtoCollection.php @@ -33,7 +33,9 @@ public function toArray(): array 'bufferZoneHectares' => $heritage->getBufferZoneHectares(), 'shortDescription' => $heritage->getShortDescription(), 'imageUrl' => $heritage->getImageUrl(), - 'unescoSiteUrl' => $heritage->getUnescoSiteUrl() + 'unescoSiteUrl' => $heritage->getUnescoSiteUrl(), + 'statePartyCodes' => $heritage->getStatePartyCodes(), + 'statePartiesMeta' => $heritage->getStatePartiesMeta(), ]; }, $this->heritages); } diff --git a/src/app/Packages/Features/QueryUseCases/Factory/WorldHeritageDtoCollectionFactory.php b/src/app/Packages/Features/QueryUseCases/Factory/WorldHeritageDtoCollectionFactory.php index b73a006..895edfa 100644 --- a/src/app/Packages/Features/QueryUseCases/Factory/WorldHeritageDtoCollectionFactory.php +++ b/src/app/Packages/Features/QueryUseCases/Factory/WorldHeritageDtoCollectionFactory.php @@ -29,7 +29,9 @@ public static function build(array $data): WorldHeritageDtoCollection bufferZoneHectares: $heritage['buffer_zone_hectares'] ?? null, shortDescription: $heritage['short_description'] ?? null, imageUrl: $heritage['image_url'] ?? null, - unescoSiteUrl: $heritage['unesco_site_url'] ?? null + unescoSiteUrl: $heritage['unesco_site_url'] ?? null, + statePartyCodes: $heritage['state_parties'] ?? [], + statePartiesMeta: $heritage['state_parties_meta'] ?? [] ); }, $data);