Completed
Pull Request — master (#30)
by Christian
02:50 queued 20s
created

FileListSqlTest::testFileListQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
namespace uuf6429\ElderBrother\Action;
4
5
use uuf6429\ElderBrother\BaseProjectTest;
6
use uuf6429\ElderBrother\Change;
7
8
class FileListSqlTest extends BaseProjectTest
9
{
10
    public static function setUpBeforeClass()
11
    {
12
        parent::setUpBeforeClass();
13
14
        foreach (
15
            [
16
                'src/Acme/Combinator.php' => '<?php namespace Acme; class Combinator {}',
17
                'src/Acme/Comparator.php' => '<?php namespace Acme; class Comparator {}',
18
                'README' => 'Please read me!',
19
                'sql/EB-000-schema.sql' => <<<'SQL'
20
                    CREATE TABLE `City` (
21
                      `ID` int(11) NOT NULL,
22
                      `Name` char(35) NOT NULL DEFAULT '',
23
                      `CountryCode` char(3) NOT NULL DEFAULT '',
24
                      `District` char(20) NOT NULL DEFAULT '',
25
                      `Population` int(11) NOT NULL DEFAULT '0'
26
                    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
27
SQL
28
                ,
29
                'sql/EB-001-data.sql' => <<<'SQL'
30
                    INSERT INTO `City` (`ID`, `Name`, `CountryCode`, `District`, `Population`) VALUES
31
                    (1, 'Kabul', 'AFG', 'Kabol', 1780000),
32
                    (2, 'Qandahar', 'AFG', 'Qandahar', 237500),
33
                    (3, 'Herat', 'AFG', 'Herat', 186800),
34
                    (4, 'Mazar-e-Sharif', 'AFG', 'Balkh', 127800),
35
                    (5, 'Amsterdam', 'NLD', 'Noord-Holland', 731200),
36
                    (6, 'Rotterdam', 'NLD', 'Zuid-Holland', 593321),
37
                    (7, 'Haag', 'NLD', 'Zuid-Holland', 440900),
38
                    (8, 'Utrecht', 'NLD', 'Utrecht', 234323),
39
                    (9, 'Eindhoven', 'NLD', 'Noord-Brabant', 201843);
40
SQL
41
                ,
42
                'sql/EB-002-keys.sql' => 'ALTER TABLE `City` ADD PRIMARY KEY (`ID`);',
43
            ] as $filename => $content
44
        ) {
45
            if (!is_dir(dirname($filename))) {
46
                mkdir(dirname($filename), 0755, true);
47
            }
48
            file_put_contents($filename, $content);
49
        }
50
    }
51
52
    /**
53
     * @param string[] $expectedItems
54
     * @param \Closure $itemsProvider
55
     *
56
     * @dataProvider fileListQueryDataProvider
57
     */
58
    public function testFileListQuery($expectedItems, $itemsProvider)
59
    {
60
        $baseDir = getcwd();
61
        $actualItems = array_map(
62
            function ($file) use ($baseDir) {
63
                return str_replace([$baseDir . DIRECTORY_SEPARATOR, '\\'], ['', '/'], $file);
64
            },
65
            $itemsProvider()
66
        );
67
        sort($actualItems);
68
69
        $this->assertEquals($expectedItems, $actualItems);
70
        $this->assertSame($expectedItems, $actualItems);
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function fileListQueryDataProvider()
77
    {
78
        return [
79
            'directories' => [
80
                '$expectedItems' => [
81
                    'sql/EB-000-schema.sql',
82
                    'sql/EB-002-keys.sql',
83
                ],
84
                '$itemsProvider' => function () {
85
                    return Change\FullChangeSet::get()->sqlWithDDL()->toArray();
86
                },
87
            ],
88
        ];
89
    }
90
}
91