Completed
Push — master ( 265a2d...f9e310 )
by jerome
02:58
created

ServerContext::thereIsSteamServer()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 30
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 30
rs 8.5806
cc 4
eloc 19
nc 5
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * This file is part of Dedipanel project
5
 *
6
 * (c) 2010-2015 Dedipanel <http://www.dedicated-panel.net>
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 DP\Core\CoreBundle\Behat;
13
14
class ServerContext extends DefaultContext
15
{
16
    /**
17
     * @Given /^I am on the (teamspeak) instance creation page for "([^""]*)"$/
18
     * @When /^I go to the (teamspeak) instance creation page for "([^""]*)"$/
19
     */
20
    public function iAmOnTheVoipPage($type, $value)
21
    {
22
        $parts   = explode('@', $value);
23
        $machine = $this->findOneBy('machine', array('username' => $parts[0]));
24
        $server  = $this->findOneBy($type, array('machine' => $machine->getId()));
25
26
        $this->getSession()->visit($this->generatePageUrl($type . ' instance creation', array('serverId' => $server->getId())));
27
    }
28
29
    /**
30
     * @Given /^I should be on the (teamspeak) instance creation page for "([^""]*)"$/
31
     * @Given /^I should still be on the (teamspeak) instance creation page for "([^""]*)"$/
32
     */
33 View Code Duplication
    public function iShouldBeOnTheVoipPage($type, $value)
34
    {
35
        $parts   = explode('@', $value);
36
        $machine = $this->findOneBy('machine', array('username' => $parts[0]));
37
        $server  = $this->findOneBy($type, array('machine' => $machine->getId()));
38
39
        $this->assertSession()->addressEquals($this->generatePageUrl($type . ' instance creation', array('serverId' => $server->getId())));
40
        $this->assertStatusCodeEquals(200);
41
    }
42
43
    /**
44
     * @Given /^I am on the page of (teamspeak) instance "([^""]*)"$/
45
     * @Given /^I go to the page of (teamspeak) instance "([^""]*)"$/
46
     */
47
    public function iAmOnTheInstancePageByName($type, $name)
48
    {
49
        $resource = $this->findOneBy('instance', array('name' => $name), $type);
50
51
        $this->getSession()->visit($this->generatePageUrl(sprintf('%s_instance_show', $type), array('id' => $resource->getId(), 'serverId' => $resource->getServer()->getId())));
52
    }
53
54
    /**
55
     * @Given /^I am (building|viewing|editing) (teamspeak) instance "([^""]*)"$/
56
     */
57 View Code Duplication
    public function iAmDoingSomethingWithVoipResourceByName($action, $type, $name)
58
    {
59
        $action = str_replace(array_keys($this->actions), array_values($this->actions), $action);
60
        $resource = $this->findOneBy('instance', array('name' => $name), $type);
61
62
        $this->getSession()->visit($this->generatePageUrl(sprintf('%s_instance_%s', $type, $action), array('id' => $resource->getId(), 'serverId' => $resource->getServer()->getId())));
63
    }
64
65
    /**
66
     * @Then /^I should be (building|viewing|editing) (teamspeak) instance "([^""]*)"$/
67
     * @Then /^I should still be (building|viewing|editing) (teamspeak) instance "([^""]*)"$/
68
     */
69 View Code Duplication
    public function iShouldBeDoingSomethingWithVoipResourceByName($action, $type, $name)
70
    {
71
        $action = str_replace(array_keys($this->actions), array_values($this->actions), $action);
72
        $resource = $this->findOneBy('instance', array('name' => $name), $type);
73
74
        $this->assertSession()->addressEquals($this->generatePageUrl(sprintf('%s_instance_%s', $type, $action), array('id' => $resource->getId(), 'serverId' => $resource->getServer()->getId())));
75
        $this->assertStatusCodeEquals(200);
76
    }
77
78
    /**
79
     * @Then /^I should be on the page of ([^""(w)]*) server "([^""]*)"$/
80
     * @Then /^I should still be on the page of ([^""(w)]*) server "([^""]*)"$/
81
     */
82
    public function iShouldBeOnTheServerPageByName($type, $name)
83
    {
84
        $this->iShouldBeOnTheResourcePage($type, 'name', $name);
85
    }
86
87
    /**
88
     * @Then /^I should be on the page of (teamspeak) instance "([^""]*)"$/
89
     * @Then /^I should still be on the page of (teamspeak) instance "([^""]*)"$/
90
     */
91 View Code Duplication
    public function iShouldBeOnTheInstancePageByName($type, $name)
92
    {
93
        $type = str_replace(' ', '_', $type);
94
        $resource = $this->findOneBy('instance', array('name' => $name), $type);
95
96
        $this->assertSession()->addressEquals($this->generatePageUrl(sprintf('%s_instance_show', $type), array('id' => $resource->getId(), 'serverId' => $resource->getServer()->getId())));
97
        $this->assertStatusCodeEquals(200);
98
    }
99
100
    /**
101
     * @Given /^I am on the (teamspeak) "([^""]*)" instance index$/
102
     * @TODO: Refactorer comme iAmOnTheVoipPage()
103
     */
104
    public function iAmOnTheInstanceIndex($type, $value)
105
    {
106
        $parts   = explode('@', $value);
107
        $machine = $this->findOneBy('machine', array('username' => $parts[0]));
108
        $server  = $this->findOneBy($type, array('machine' => $machine->getId()));
109
110
        $this->getSession()->visit($this->generatePageUrl(sprintf('dedipanel_%s_instance_index', $type), array('serverId' => $server->getId())));
111
    }
112
113
    /**
114
     * @Then /^I should be on the (teamspeak) "([^"]*)" instance index$/
115
     */
116 View Code Duplication
    public function iShouldBeOnTheInstanceIndexPage($type, $value)
117
    {
118
        $parts   = explode('@', $value);
119
        $machine = $this->findOneBy('machine', array('username' => $parts[0]));
120
        $server  = $this->findOneBy($type, array('machine' => $machine->getId()));
121
122
        $this->assertSession()->addressEquals($this->generatePageUrl(sprintf('dedipanel_%s_instance_index', $type), array('serverId' => $server->getId())));
123
        $this->assertStatusCodeEquals(200);
124
    }
125
126
    /**
127
     * @Given /^I am (building|viewing|editing) (teamspeak) "([^""]*)"$/
128
     */
129 View Code Duplication
    public function iAmDoingSomethingWithVoipServer($action, $type, $value)
130
    {
131
        $type = str_replace(' ', '_', $type);
132
133
        $action = str_replace(array_keys($this->actions), array_values($this->actions), $action);
134
        $parts   = explode('@', $value);
135
        $machine = $this->findOneBy('machine', array('username' => $parts[0]));
136
        $server  = $this->findOneBy($type, array('machine' => $machine->getId()));
137
138
        $this->getSession()->visit($this->generatePageUrl(sprintf('dedipanel_%s_%s', $type, $action), array('id' => $server->getId())));
139
    }
140
141
    /**
142
     * @Then /^I should be (building|viewing|editing|testing) (teamspeak) "([^""]*)"$/
143
     */
144 View Code Duplication
    public function iShouldBeDoingSomethingWithVoipServer($action, $type, $value)
145
    {
146
        $type = str_replace(' ', '_', $type);
147
148
        $action  = str_replace(array_keys($this->actions), array_values($this->actions), $action);
149
        $parts   = explode('@', $value);
150
        $machine = $this->findOneBy('machine', array('username' => $parts[0]));
151
        $server  = $this->findOneBy($type, array('machine' => $machine->getId()));
152
153
        $this->assertSession()->addressEquals($this->generatePageUrl(sprintf('dedipanel_%s_%s', $type, $action), array('id' => $server->getId())));
154
        $this->assertStatusCodeEquals(200);
155
    }
156
157
    /**
158
     * @When /^I (?:click|press|follow) "([^"]*)" near "([^"]*)"$/
159
     */
160 View Code Duplication
    public function iClickNear($button, $value)
161
    {
162
        $selector = sprintf('.server-list .server-item:contains("%s")', $value);
163
        $item = $this->assertSession()->elementExists('css', $selector);
164
165
        $locator = sprintf('button:contains("%s")', $button);
166
167
        if ($item->has('css', $locator)) {
168
            $item->find('css', $locator)->press();
169
        } else {
170
            $item->clickLink($button);
171
        }
172
    }
173
174
    /**
175
     * @Then /^I should be on the ftp page of ([^""]*) "([^""]*)"$/
176
     */
177 View Code Duplication
    public function iShouldBeOnTheFtpPage($type, $name)
178
    {
179
        $type = str_replace(' ', '_', $type);
180
        $resource = $this->findOneBy($type, array('name' => $name));
181
182
        $this->assertSession()->addressEquals($this->generatePageUrl(sprintf('%s_ftp_show', $type), array('id' => $resource->getId())));
183
        $this->assertStatusCodeEquals(200);
184
    }
185
186
    /**
187
     * @Then /^I should see (\d+) ([^" ]*) instances in (that|the) list$/
188
     */
189 View Code Duplication
    public function iShouldSeeThatMuchInstancesInTheList($amount, $type)
190
    {
191
        if (1 === count($this->getSession()->getPage()->findAll('css', '.instance-list'))) {
192
            $this->assertSession()->elementsCount('css', '.instance-list > .instance-item', $amount);
193
        } else {
194
            $this->assertSession()->elementsCount('css', sprintf('#%s.instance-list > .instance-item', $type), $amount);
195
        }
196
    }
197
}
198