Repository navigation
Expand file tree
/
Copy pathBuildCommandTest.php
More file actions
106 lines (92 loc) · 4.32 KB
/
Copy pathBuildCommandTest.php
File metadata and controls
106 lines (92 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace Ttskch\JpPostalCodeApi\Command;
use League\Csv\Reader;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Console\Tester\CommandTester;
use Ttskch\JpPostalCodeApi\Csv\CsvParserInterface;
use Ttskch\JpPostalCodeApi\DataSource\CsvProviderInterface;
use Ttskch\JpPostalCodeApi\FileSystem\BaseDirectoryInterface;
use Ttskch\JpPostalCodeApi\Model\Address;
use Ttskch\JpPostalCodeApi\Model\AddressUnit;
use Ttskch\JpPostalCodeApi\Model\ParsedCsvRow;
class BuildCommandTest extends TestCase
{
use ProphecyTrait;
public function testExecute(): void
{
$csvProvider = $this->prophesize(CsvProviderInterface::class);
$csvProvider->fromZipUrl('https://www.post.japanpost.jp/service/search/zipcode/download/kogaki/zip/ken_all.zip')->willReturn(Reader::createFromString('ken,all,csv'));
$csvProvider->fromZipUrl('https://www.post.japanpost.jp/service/search/zipcode/download/roman/KEN_ALL_ROME.zip')->willReturn(Reader::createFromString('kenall,rome,csv'));
$csvProvider->fromZipUrl('https://www.post.japanpost.jp/service/search/zipcode/download/office/zip/jigyosyo.zip')->willReturn(Reader::createFromString('jigyo,syo,csv'));
$kenAllCsvParser = $this->prophesize(CsvParserInterface::class);
$kenAllCsvParser->parse(['ken', 'all', 'csv'])->willReturn(new ParsedCsvRow(
'0600000',
new Address(
'01',
ja: new AddressUnit('北海道', '札幌市中央区', '旭ケ丘', '', ''),
kana: new AddressUnit('ホッカイドウ', 'サッポロシチュウオウク', 'アサヒガオカ', '', ''),
),
));
$kenAllRomeCsvParser = $this->prophesize(CsvParserInterface::class);
$kenAllRomeCsvParser->parse(['kenall', 'rome', 'csv'])->willReturn(new ParsedCsvRow(
'0600000',
new Address(
'01',
ja: new AddressUnit('北海道', '札幌市中央区', '旭ケ丘', '', ''),
en: new AddressUnit('Hokkaido', 'Chuo-ku, Sapporo-shi', 'Asahigaoka', '', ''),
),
));
$jigyosyoCsvParser = $this->prophesize(CsvParserInterface::class);
$jigyosyoCsvParser->parse(['jigyo', 'syo', 'csv'])->willReturn(new ParsedCsvRow(
'1008111',
new Address(
'13',
ja: new AddressUnit('東京都', '千代田区', '千代田', '1-1', '宮内庁'),
en: new AddressUnit(),
),
));
$baseDirectory = $this->prophesize(BaseDirectoryInterface::class);
$baseDirectory->clear()->shouldBeCalled();
$baseDirectory->putJsonFile(new ParsedCsvRow(
'0600000',
new Address(
'01',
ja: new AddressUnit('北海道', '札幌市中央区', '旭ケ丘', '', ''),
kana: new AddressUnit('ホッカイドウ', 'サッポロシチュウオウク', 'アサヒガオカ', '', ''),
),
))->shouldBeCalled();
$baseDirectory->putJsonFile(new ParsedCsvRow(
'0600000',
new Address(
'01',
ja: new AddressUnit('北海道', '札幌市中央区', '旭ケ丘', '', ''),
en: new AddressUnit('Hokkaido', 'Chuo-ku, Sapporo-shi', 'Asahigaoka', '', ''),
),
), true)->shouldBeCalled();
$baseDirectory->putJsonFile(new ParsedCsvRow(
'1008111',
new Address(
'13',
ja: new AddressUnit('東京都', '千代田区', '千代田', '1-1', '宮内庁'),
en: new AddressUnit(),
),
))->shouldBeCalled();
$baseDirectory->countJsonFiles()->willReturn(1);
$command = new BuildCommand(
$csvProvider->reveal(),
$kenAllCsvParser->reveal(),
$kenAllRomeCsvParser->reveal(),
$jigyosyoCsvParser->reveal(),
$baseDirectory->reveal(),
);
$commandTester = new CommandTester($command);
ob_start();
$commandTester->execute([]);
ob_end_clean();
$commandTester->assertCommandIsSuccessful();
$output = $commandTester->getDisplay();
self::assertStringContainsString('Finished! 1 files are created from 3 CSV records.', $output);
}
}