Completed
Push — master ( 550482...257fa6 )
by Loïc
15s
created

InstallerContext::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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\SetupCommand;
15
use Symfony\Bundle\FrameworkBundle\Console\Application;
16
use Symfony\Component\Console\Tester\CommandTester;
17
use Symfony\Component\HttpKernel\KernelInterface;
18
19
class InstallerContext extends DefaultContext
20
{
21
    /**
22
     * @var SetupCommand
23
     */
24
    private $setupCommand;
25
26
    /**
27
     * @var array
28
     */
29
    private $inputChoices = [
30
        'e-mail' => '[email protected]',
31
        'password' => 'pswd',
32
        'confirmation' => 'pswd',
33
    ];
34
35
    /**
36
     * @param KernelInterface $kernel
37
     * @param SetupCommand    $setupCommand
38
     */
39
    public function __construct(KernelInterface $kernel, SetupCommand $setupCommand)
40
    {
41
        $this->setupCommand = $setupCommand;
42
43
        parent::__construct($kernel);
44
    }
45
46
    /**
47
     * @Given I do not provide an email
48
     */
49
    public function iDoNotProvideEmail()
50
    {
51
        $this->inputChoices['e-mail'] = '';
52
    }
53
54
    /**
55
     * @Given I do not provide a correct email
56
     */
57
    public function iDoNotProvideCorrectEmail()
58
    {
59
        $this->inputChoices['e-mail'] = 'janusz';
60
    }
61
62
    /**
63
     * @Given I provide full administrator data
64
     */
65
    public function iProvideFullAdministratorData()
66
    {
67
        $this->inputChoices['e-mail'] = '[email protected]';
68
        $this->inputChoices['password'] = 'pswd1$';
69
        $this->inputChoices['confirmation'] = $this->inputChoices['password'];
70
    }
71
72
    /**
73
     * @param string $name
74
     */
75
    private function iExecuteCommandWithInputChoices($name)
76
    {
77
        $this->questionHelper = $this->command->getHelper('question');
78
        $this->getTester()->setInputs($this->inputChoices);
79
80
        try {
81
            $this->getTester()->execute(['command' => $name]);
82
        } catch (\Exception $e) {
83
        }
84
    }
85
86
    /**
87
     * @When /^I run Install setup command$/
88
     */
89
    public function iRunInstallSetupCommmandLine()
90
    {
91
        $this->application = new Application($this->kernel);
92
        $this->application->add($this->setupCommand);
93
94
        $this->command = $this->application->find('app:install:setup');
95
        $this->setTester(new CommandTester($this->command));
96
97
        $this->iExecuteCommandWithInputChoices('app:install:setup');
98
    }
99
100
    /**
101
     * @param string $name
102
     */
103
    protected function iExecuteCommandAndConfirm($name)
104
    {
105
        $this->questionHelper = $this->command->getHelper('question');
106
107
        $this->getTester()->setInputs(['y', 'y']);
108
109
        try {
110
            $this->getTester()->execute(['command' => $name]);
111
        } catch (\Exception $e) {
112
        }
113
    }
114
}
115