Blame view

vendor/robmorgan/phinx/tests/Phinx/Config/ConfigFileTest.php 3.21 KB
6c4edfa3   Alexandre   First Commit LabI...
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php

namespace Test\Phinx\Config;

use Phinx\Console\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;

class ConfigFileTest extends \PHPUnit_Framework_TestCase
{
    private $previousDir;

    private $baseDir;

    public function setUp()
    {
        $this->previousDir = getcwd();
        $this->baseDir = realpath(__DIR__ . '/_rootDirectories');
    }

    public function tearDown()
    {
        chdir($this->previousDir);
    }

    /**
     * Test workingContext
     *
     * @dataProvider workingProvider
     *
     * @param $input
     * @param $dir
     * @param $expectedFile
     */
    public function testWorkingGetConfigFile($input, $dir, $expectedFile)
    {
        $foundPath = $this->runLocateFile($input, $dir);
        $expectedPath = $this->baseDir . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $expectedFile;

        $this->assertEquals($foundPath, $expectedPath);
    }

    /**
     * Test workingContext
     *
     * @dataProvider notWorkingProvider
     *
     * @param $input
     * @param $dir
     * @expectedException \InvalidArgumentException
     */
    public function testNotWorkingGetConfigFile($input, $dir)
    {
        $this->runLocateFile($input, $dir);
    }

    /**
     * Do the locateFile Action
     *
     * @param $arg
     * @param $dir
     * @return string
     */
    protected function runLocateFile($arg, $dir)
    {
        chdir($this->baseDir . '/' . $dir);
        $definition = new InputDefinition(array(new InputOption('configuration')));
        $input = new ArgvInput(array(), $definition);
        if ($arg) {
            $input->setOption('configuration', $arg);
        }
        $command = new VoidCommand('void');
        return $command->locateConfigFile($input);
    }

    /**
     * Working cases
     *
     *
     * @return array
     */
    public function workingProvider()
    {
        return array(
            //explicit yaml
            array('phinx.yml', 'OnlyYaml', 'phinx.yml'),
            //implicit with all choice
            array(null, 'all', 'phinx.php'),
            //implicit with no php choice
            array(null, 'noPhp', 'phinx.json'),
            //implicit with only yaml choice
            array(null, 'OnlyYaml', 'phinx.yml'),
            //explicit Php
            array('phinx.php', 'all', 'phinx.php'),
            //explicit json
            array('phinx.json', 'all', 'phinx.json'),
        );
    }

    /**
     * Not working cases
     *
     * @return array
     */
    public function notWorkingProvider()
    {
        return array(
            //no valid file available
            array(null, 'NoValidFile'),
            //called file not available
            array('phinx.yml', 'noYaml'),
            array('phinx.json', 'OnlyYaml'),
            array('phinx.php', 'OnlyYaml'),
        );
    }
}

/**
 * Class VoidCommand : used to expose locateConfigFile To testing
 *
 * @package Test\Phinx\Config
 */
class VoidCommand extends AbstractCommand
{
    public function locateConfigFile(InputInterface $input)
    {
        return parent::locateConfigFile($input);
    }
}