Skip to content

Commit 19e28a9

Browse files
committed
fix: delete unesco_id and replace into primary id
1 parent 236ce77 commit 19e28a9

5 files changed

Lines changed: 38 additions & 225 deletions

File tree

src/app/Packages/Domains/Test/WorldHeritageEntityCollectionTest.php

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use App\Models\Country;
66
use App\Models\WorldHeritage;
77
use App\Packages\Domains\WorldHeritageEntityCollection;
8-
use Database\Seeders\CountrySeeder;
8+
use Database\Seeders\DatabaseSeeder;
99
use Illuminate\Support\Facades\DB;
1010
use Tests\TestCase;
1111
use App\Packages\Domains\WorldHeritageEntity;
@@ -16,7 +16,7 @@ protected function setUp(): void
1616
{
1717
parent::setUp();
1818
$this->refresh();
19-
$seeder = new CountrySeeder();
19+
$seeder = new DatabaseSeeder();
2020
$seeder->run();
2121
}
2222

@@ -41,8 +41,7 @@ private static function arraySingleData(): array
4141
{
4242
return [
4343
[
44-
'id' => 1,
45-
'unesco_id' => '668',
44+
'id' => 668,
4645
'official_name' => 'Historic Monuments of Ancient Nara',
4746
'name' => 'Historic Monuments of Ancient Nara',
4847
'name_jp' => '古都奈良の文化財',
@@ -65,64 +64,14 @@ private static function arraySingleData(): array
6564
'image_url' => '',
6665
'unesco_site_url' => 'https://whc.unesco.org/en/list/668/',
6766
],
68-
[
69-
'id' => 2,
70-
'unesco_id' => '1234',
71-
'official_name' => 'Example Heritage Site',
72-
'name' => 'Example Heritage Site',
73-
'name_jp' => '例の文化遺産',
74-
'country' => 'Japan',
75-
'region' => 'Asia',
76-
'state_party' => 'JP',
77-
'state_parties' => ['JP'],
78-
'state_parties_meta' => [
79-
'JP' => ['is_primary' => true, 'inscription_year' => 2000],
80-
],
81-
'category' => 'natural',
82-
'criteria' => ['vii', 'viii'],
83-
'year_inscribed' => 2000,
84-
'area_hectares' => 500.0,
85-
'buffer_zone_hectares' => 400.0,
86-
'is_endangered' => true,
87-
'latitude' => 35.6895,
88-
'longitude' => 139.6917,
89-
'short_description' => 'An example of a natural heritage site.',
90-
'image_url' => '',
91-
'unesco_site_url' => 'https://whc.unesco.org/en/list/1234/',
92-
],
93-
[
94-
'id' => 3,
95-
'unesco_id' => '669',
96-
'official_name' => 'Shrines and Temples of Nikko',
97-
'name' => 'Shrines and Temples of Nikko',
98-
'name_jp' => '日光の社寺',
99-
'country' => 'Japan',
100-
'region' => 'Asia',
101-
'state_party' => 'JP',
102-
'state_parties' => ['JP'],
103-
'state_parties_meta' => [
104-
'JP' => ['is_primary' => true, 'inscription_year' => 1999],
105-
],
106-
'category' => 'cultural',
107-
'criteria' => ['ii', 'iii', 'v'],
108-
'year_inscribed' => 1999,
109-
'area_hectares' => 442.0,
110-
'buffer_zone_hectares' => 320.0,
111-
'is_endangered' => false,
112-
'latitude' => 36.7578,
113-
'longitude' => 139.598,
114-
'short_description' => 'Lavishly decorated shrines set among ancient cedar trees.',
115-
'image_url' => '',
116-
'unesco_site_url' => 'https://whc.unesco.org/en/list/669/',
117-
],
11867
];
11968
}
12069

12170
private static function arrayMultiData(): array
12271
{
12372
return [
12473
[
125-
'unesco_id' => 1133,
74+
'id' => 1133,
12675
'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe",
12776
'name' => "Ancient and Primeval Beech Forests",
12877
'name_jp' => null,
@@ -165,7 +114,7 @@ private static function arrayMultiData(): array
165114
],
166115
],
167116
[
168-
'unesco_id' => 1442,
117+
'id' => 1442,
169118
'official_name' => "Silk Roads: the Routes Network of Chang'an-Tianshan Corridor",
170119
'name' => "Silk Roads: Chang'an–Tianshan Corridor",
171120
'name_jp' => 'シルクロード:長安-天山回廊の交易路網',
@@ -199,7 +148,6 @@ public function test_collection_check_type(): void
199148
array_map(function ($data) {
200149
return new WorldHeritageEntity(
201150
$data['id'],
202-
$data['unesco_id'],
203151
$data['official_name'],
204152
$data['name'],
205153
$data['country'],
@@ -238,7 +186,6 @@ public function test_collection_check_count_value(): void
238186
array_map(function ($data) {
239187
return new WorldHeritageEntity(
240188
$data['id'],
241-
$data['unesco_id'],
242189
$data['official_name'],
243190
$data['name'],
244191
$data['country'],
@@ -262,16 +209,15 @@ public function test_collection_check_count_value(): void
262209
}, $this->arraySingleData())
263210
);
264211

265-
$this->assertCount(3, $collection->getAllHeritages());
212+
$this->assertCount(1, $collection->getAllHeritages());
266213
}
267214

268215
public function test_multi_collection_check_type(): void
269216
{
270217
$collection = new WorldHeritageEntityCollection(
271218
array_map(function ($data) {
272219
return new WorldHeritageEntity(
273-
null, // IDは自動生成されるためnull
274-
$data['unesco_id'],
220+
$data['id'],
275221
$data['official_name'],
276222
$data['name'],
277223
$data['country'],
@@ -303,8 +249,7 @@ public function test_multi_collection_check_count_value(): void
303249
$collection = new WorldHeritageEntityCollection(
304250
array_map(function ($data) {
305251
return new WorldHeritageEntity(
306-
null,
307-
$data['unesco_id'],
252+
$data['id'],
308253
$data['official_name'],
309254
$data['name'],
310255
$data['country'],

src/app/Packages/Domains/Test/WorldHeritageEntityTest.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,40 @@
22

33
namespace App\Packages\Domains\Test;
44

5-
use PHPUnit\Framework\TestCase;
5+
use App\Models\Country;
6+
use App\Models\WorldHeritage;
7+
use Illuminate\Support\Facades\DB;
8+
use Tests\TestCase;
69
use App\Packages\Domains\WorldHeritageEntity;
710

811
class WorldHeritageEntityTest extends TestCase
912
{
1013
protected function setUp(): void
1114
{
1215
parent::setUp();
16+
$this->refresh();
1317
}
1418

1519
protected function tearDown(): void
1620
{
1721
parent::tearDown();
1822
}
1923

24+
private function refresh(): void
25+
{
26+
if (env('APP_ENV') === 'testing') {
27+
DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=0;');
28+
WorldHeritage::truncate();
29+
Country::truncate();
30+
DB::table('site_state_parties')->truncate();
31+
DB::connection('mysql')->statement('SET FOREIGN_KEY_CHECKS=1;');
32+
}
33+
}
34+
2035
private static function arraySingleData(): array
2136
{
2237
return [
23-
'unesco_id' => '668',
38+
'id' => 668,
2439
'official_name' => 'Historic Monuments of Ancient Nara',
2540
'name' => 'Historic Monuments of Ancient Nara',
2641
'name_jp' => '古都奈良の文化財',
@@ -51,7 +66,7 @@ private static function arraySingleData(): array
5166
private static function arrayMultiData(): array
5267
{
5368
return [
54-
'unesco_id' => 1133,
69+
'id' => 1133,
5570
'official_name' => "Ancient and Primeval Beech Forests of the Carpathians and Other Regions of Europe",
5671
'name' => "Ancient and Primeval Beech Forests",
5772
'name_jp' => null,
@@ -99,8 +114,7 @@ private static function arrayMultiData(): array
99114
public function test_entity_check_single_type(): void
100115
{
101116
$entity = new WorldHeritageEntity(
102-
self::arraySingleData()['id'] ?? null,
103-
self::arraySingleData()['unesco_id'],
117+
self::arraySingleData()['id'],
104118
self::arraySingleData()['official_name'],
105119
self::arraySingleData()['name'],
106120
self::arraySingleData()['country'],
@@ -128,8 +142,7 @@ public function test_entity_check_single_type(): void
128142
public function test_entity_check_single_value(): void
129143
{
130144
$entity = new WorldHeritageEntity(
131-
self::arraySingleData()['id'] ?? null,
132-
self::arraySingleData()['unesco_id'],
145+
self::arraySingleData()['id'],
133146
self::arraySingleData()['official_name'],
134147
self::arraySingleData()['name'],
135148
self::arraySingleData()['country'],
@@ -151,7 +164,7 @@ public function test_entity_check_single_value(): void
151164
self::arraySingleData()['state_parties_meta']
152165
);
153166

154-
$this->assertEquals(self::arraySingleData()['unesco_id'], $entity->getUnescoId());
167+
$this->assertEquals(self::arraySingleData()['id'], $entity->getId());
155168
$this->assertEquals(self::arraySingleData()['official_name'], $entity->getOfficialName());
156169
$this->assertEquals(self::arraySingleData()['name'], $entity->getName());
157170
$this->assertEquals(self::arraySingleData()['country'], $entity->getCountry());
@@ -176,8 +189,7 @@ public function test_entity_check_single_value(): void
176189
public function test_entity_check_multi_type(): void
177190
{
178191
$entity = new WorldHeritageEntity(
179-
self::arrayMultiData()['id'] ?? null,
180-
self::arrayMultiData()['unesco_id'],
192+
self::arrayMultiData()['id'],
181193
self::arrayMultiData()['official_name'],
182194
self::arrayMultiData()['name'],
183195
self::arrayMultiData()['country'],
@@ -205,8 +217,7 @@ public function test_entity_check_multi_type(): void
205217
public function test_entity_check_multi_value(): void
206218
{
207219
$entity = new WorldHeritageEntity(
208-
self::arrayMultiData()['id'] ?? null,
209-
self::arrayMultiData()['unesco_id'],
220+
self::arrayMultiData()['id'],
210221
self::arrayMultiData()['official_name'],
211222
self::arrayMultiData()['name'],
212223
self::arrayMultiData()['country'],
@@ -228,7 +239,7 @@ public function test_entity_check_multi_value(): void
228239
self::arrayMultiData()['state_parties_meta']
229240
);
230241

231-
$this->assertEquals(self::arrayMultiData()['unesco_id'], $entity->getUnescoId());
242+
$this->assertEquals(self::arrayMultiData()['id'], $entity->getId());
232243
$this->assertEquals(self::arrayMultiData()['official_name'], $entity->getOfficialName());
233244
$this->assertEquals(self::arrayMultiData()['name'], $entity->getName());
234245
$this->assertEquals(self::arrayMultiData()['country'], $entity->getCountry());

src/app/Packages/Domains/WorldHeritageEntity.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
class WorldHeritageEntity
66
{
77
public function __construct(
8-
public ?int $id,
9-
public string $unescoId,
8+
public int $id,
109
public string $officialName,
1110
public string $name,
1211
public string $country,
@@ -28,16 +27,11 @@ public function __construct(
2827
private array $statePartyMeta = []
2928
) {}
3029

31-
public function getId(): ?int
30+
public function getId(): int
3231
{
3332
return $this->id;
3433
}
3534

36-
public function getUnescoId(): string
37-
{
38-
return $this->unescoId;
39-
}
40-
4135
public function getOfficialName(): string
4236
{
4337
return $this->officialName;
@@ -155,7 +149,7 @@ public function getStatePartyCodesOrFallback(): array
155149
return [];
156150

157151
$parts = preg_split('/[;,\s]+/', strtoupper($this->stateParty));
158-
$codes = array_filter($parts, fn($country) => preg_match('/^[A-Z]{2}$/', $country));
152+
$codes = array_filter($parts, fn($country) => preg_match('/^[A-Z]{3}$/', $country));
159153

160154
return array_values(array_unique($codes));
161155
}
@@ -164,7 +158,7 @@ private function normalizeCodes(array $codes): array
164158
$codes = array_map('trim', $codes);
165159
$codes = array_filter($codes, fn($v) => $v !== '');
166160
$codes = array_map('strtoupper', $codes);
167-
$codes = array_filter($codes, fn($v) => preg_match('/^[A-Z]{2}$/', $v));
161+
$codes = array_filter($codes, fn($v) => preg_match('/^[A-Z]{3}$/', $v));
168162

169163
return array_values(array_unique($codes));
170164
}
@@ -191,11 +185,11 @@ public function setStatePartyMeta(array $meta): void
191185
$normalized = [];
192186
foreach ($meta as $code => $m) {
193187
$code = strtoupper(trim((string)$code));
194-
if (!preg_match('/^[A-Z]{2}$/', $code)) {
188+
if (!preg_match('/^[A-Z]{3}$/', $code)) {
195189
continue;
196190
}
197191
$normalized[$code] = [
198-
'is_primary' => (bool)($m['is_primary'] ?? false),
192+
'is_primary' => (bool)($m['is_primary'] ?? false),
199193
'inscription_year' => isset($m['inscription_year'])
200194
? (is_numeric($m['inscription_year']) ? (int)$m['inscription_year'] : null)
201195
: null,

src/app/Packages/Domains/WorldHeritageEntityCollection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace App\Packages\Domains;
44

5-
use App\Packages\Domains\WorldHeritageEntity;
6-
75
class WorldHeritageEntityCollection
86
{
97
public function __construct(

0 commit comments

Comments
 (0)