Completed
Push — example/managing-articles ( fd231a...05f396 )
by Loïc
05:52 queued 02:50
created

iRunInstallDatabaseCommmandLine()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of UnivNantes.
5
 *
6
 * (c) Monofony
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace App\Behat\Context\Cli;
13
14
use App\Command\Installer\InstallDatabaseCommand;
15
use App\Command\Installer\SetupCommand;
16
use Symfony\Bundle\FrameworkBundle\Console\Application;
17
use Symfony\Component\Console\Tester\CommandTester;
18
19
class InstallerContext extends CommandContext
20
{
21
    /**
22
     * @var array
23
     */
24
    private $inputChoices = [
25
        'e-mail' => '[email protected]',
26
        'password' => 'pswd',
27
        'confirmation' => 'pswd',
28
    ];
29
30
    /**
31
     * @Given I do not provide an email
32
     */
33
    public function iDoNotProvideEmail()
34
    {
35
        $this->inputChoices['e-mail'] = '';
36
    }
37
38
    /**
39
     * @Given I do not provide a correct email
40
     */
41
    public function iDoNotProvideCorrectEmail()
42
    {
43
        $this->inputChoices['e-mail'] = 'janusz';
44
    }
45
46
    /**
47
     * @Given I provide full administrator data
48
     */
49
    public function iProvideFullAdministratorData()
50
    {
51
        $this->inputChoices['e-mail'] = '[email protected]';
52
        $this->inputChoices['password'] = 'pswd1$';
53
        $this->inputChoices['confirmation'] = $this->inputChoices['password'];
54
    }
55
56
    /**
57
     * @param string $name
58
     */
59
    private function iExecuteCommandWithInputChoices($name)
60
    {
61
        $this->questionHelper = $this->command->getHelper('question');
62
        $this->getTester()->setInputs($this->inputChoices);
63
64
        try {
65
            $this->getTester()->execute(['command' => $name]);
66
        } catch (\Exception $e) {
67
        }
68
    }
69
70
    /**
71
     * @When /^I run Install setup command$/
72
     */
73
    public function iRunInstallSetupCommmandLine()
74
    {
75
        $this->application = new Application($this->kernel);
76
        $this->application->add(new SetupCommand());
77
78
        $this->command = $this->application->find('app:install:setup');
79
        $this->setTester(new CommandTester($this->command));
80
81
        $this->iExecuteCommandWithInputChoices('app:install:setup');
82
    }
83
84
    /**
85
     * @When /^I run Install database command$/
86
     */
87
    public function iRunInstallDatabaseCommmandLine()
88
    {
89
        $this->application = new Application($this->kernel);
90
        $this->application->add(new InstallDatabaseCommand());
91
92
        $this->command = $this->application->find('app:install:database');
93
        $this->setTester(new CommandTester($this->command));
94
95
        $this->iExecuteCommandAndConfirm('app:install:database');
96
    }
97
98
    /**
99
     * @param string $name
100
     */
101
    protected function iExecuteCommandAndConfirm($name)
102
    {
103
        $this->questionHelper = $this->command->getHelper('question');
104
105
        $this->getTester()->setInputs(['y', 'y']);
106
107
        try {
108
            $this->getTester()->execute(['command' => $name]);
109
        } catch (\Exception $e) {
110
        }
111
    }
112
}
113