-
Notifications
You must be signed in to change notification settings - Fork 720
Expand file tree
/
Copy pathCsvLoaderCommandTest.php
More file actions
83 lines (69 loc) · 2.65 KB
/
Copy pathCsvLoaderCommandTest.php
File metadata and controls
83 lines (69 loc) · 2.65 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
<?php
declare(strict_types=1);
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\Tests\Command;
use Eccube\Command\CsvLoaderCommand;
use Eccube\Entity\Master\Job;
use Symfony\Component\Console\Tester\CommandTester;
final class CsvLoaderCommandTest extends CommandTestCase
{
protected \SplFileObject $file;
protected function setUp(): void
{
$this->markTestIncomplete(self::class.' は未実装です');
parent::setUp();
if ($this->app['config']['database']['driver'] == 'pdo_sqlite') {
$this->markTestSkipped('Can not support for sqlite3');
}
$this->initCommand(new CsvLoaderCommand());
$Jobs = $this->app['orm.em']->getRepository(Job::class)->findAll();
foreach ($Jobs as $Job) {
$this->app['orm.em']->remove($Job);
}
$this->app['orm.em']->flush();
$this->file = new \SplFileObject(__DIR__.'/../../../Fixtures/import_csv/mtb_job.csv');
}
public function testExecute()
{
$commandArg = [
'command' => 'csv-loader',
'--file' => $this->file->getRealPath(),
];
$command = $this->app['console']->find($this->command->getName());
$this->expected = $commandArg['command'];
$this->actual = $command->getName();
$this->verify();
$CommandTester = new CommandTester($command);
$CommandTester->execute($commandArg);
$output = $CommandTester->getDisplay();
$this->assertStringContainsString('CSV Loader complete.', $output);
$this->file->setFlags(\SplFileObject::READ_CSV | \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY);
$this->file->rewind();
$this->file->next();
// ファイルのデータ行を取得しておく
$rows = [];
while (!$this->file->eof()) {
$rows[] = $this->file->current();
$this->file->next();
}
$this->file->rewind();
$Jobs = $this->app['orm.em']->getRepository(Job::class)->findAll();
$this->expected = count($rows);
$this->actual = count($Jobs);
$this->verify('行数は一致するか?');
foreach ($Jobs as $key => $Job) {
$this->expected = $rows[$key][0].', '.$rows[$key][1].', '.$rows[$key][2];
$this->actual = $Job->getId().', '.$Job->getName().', '.$Job->getRank();
$this->verify($key.'行目のデータは一致するか?');
}
}
}