Skip to content

Commit 4c5b4a3

Browse files
committed
Add phpcs + config
Fix automatic fixable phpcs issues update phpcs config Fix phpcs issues manually update phpcs config
1 parent f579e32 commit 4c5b4a3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+773
-1255
lines changed

PHPUnit/Extensions/Selenium2TestCase.php

+110-118
Large diffs are not rendered by default.

PHPUnit/Extensions/Selenium2TestCase/Command.php

+5-19
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3535
* POSSIBILITY OF SUCH DAMAGE.
3636
*
37-
* @package PHPUnit_Selenium
38-
* @author Giorgio Sironi <[email protected]>
39-
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
40-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
4137
* @link http://www.phpunit.de/
42-
* @since File available since Release 1.2.0
4338
*/
4439

4540
namespace PHPUnit\Extensions\Selenium2TestCase;
@@ -49,29 +44,23 @@
4944
/**
5045
* Base class for implementing commands with special semantics.
5146
*
52-
* @package PHPUnit_Selenium
53-
* @author Giorgio Sironi <[email protected]>
54-
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
55-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
56-
* @version Release: @package_version@
5747
* @link http://www.phpunit.de/
58-
* @since Class available since Release 1.2.0
5948
*/
6049
abstract class Command
6150
{
6251
protected $jsonParameters;
63-
private $commandName;
6452

6553
/**
66-
* @param array $jsonParameters null in case of no parameters
54+
* @param array $jsonParameters null in case of no parameters
6755
*/
6856
public function __construct($jsonParameters, URL $url)
6957
{
70-
if (!is_array($jsonParameters) && $jsonParameters !== NULL) {
71-
throw new InvalidArgumentException("The JSON parameters must be an array, or a NULL value in case they are not required.");
58+
if (! is_array($jsonParameters) && $jsonParameters !== null) {
59+
throw new InvalidArgumentException('The JSON parameters must be an array, or a NULL value in case they are not required.');
7260
}
61+
7362
$this->jsonParameters = $jsonParameters;
74-
$this->url = $url;
63+
$this->url = $url;
7564
}
7665

7766
public function url()
@@ -84,9 +73,6 @@ public function url()
8473
*/
8574
abstract public function httpMethod();
8675

87-
/**
88-
* @param array $jsonParameters null in case of no parameters
89-
*/
9076
public function jsonParameters()
9177
{
9278
return $this->jsonParameters;

PHPUnit/Extensions/Selenium2TestCase/CommandsHolder.php

+31-38
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3535
* POSSIBILITY OF SUCH DAMAGE.
3636
*
37-
* @package PHPUnit_Selenium
38-
* @author Giorgio Sironi <[email protected]>
39-
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
40-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
4137
* @link http://www.phpunit.de/
42-
* @since File available since Release 1.2.4
4338
*/
4439

4540
namespace PHPUnit\Extensions\Selenium2TestCase;
@@ -51,24 +46,14 @@
5146
/**
5247
* Object representing elements, or everything that may have subcommands.
5348
*
54-
* @package PHPUnit_Selenium
55-
* @author Giorgio Sironi <[email protected]>
56-
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
57-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
58-
* @version Release: @package_version@
5949
* @link http://www.phpunit.de/
60-
* @since Class available since Release 1.2.4
6150
*/
6251
abstract class CommandsHolder
6352
{
64-
/**
65-
* @var Driver
66-
*/
53+
/** @var Driver */
6754
protected $driver;
6855

69-
/**
70-
* @var string the API URL for this element,
71-
*/
56+
/** @var string the API URL for this element, */
7257
protected $url;
7358

7459
/**
@@ -79,16 +64,16 @@ abstract class CommandsHolder
7964

8065
public function __construct($driver, URL $url)
8166
{
82-
$this->driver = $driver;
83-
$this->url = $url;
84-
$this->commands = array();
67+
$this->driver = $driver;
68+
$this->url = $url;
69+
$this->commands = [];
8570
foreach ($this->initCommands() as $commandName => $handler) {
8671
if (is_string($handler)) {
8772
$this->commands[$commandName] = $this->factoryMethod($handler);
88-
} else if (is_callable($handler)) {
73+
} elseif (is_callable($handler)) {
8974
$this->commands[$commandName] = $handler;
9075
} else {
91-
throw new InvalidArgumentException("Command $commandName is not configured correctly.");
76+
throw new InvalidArgumentException(sprintf('Command %s is not configured correctly.', $commandName));
9277
}
9378
}
9479
}
@@ -97,30 +82,35 @@ public function __construct($driver, URL $url)
9782
* @return array class names, or
9883
* callables of the form function($parameter, $commandUrl)
9984
*/
100-
protected abstract function initCommands();
85+
abstract protected function initCommands();
10186

10287
public function __call($commandName, $arguments)
10388
{
10489
$jsonParameters = $this->extractJsonParameters($arguments);
105-
$response = $this->driver->execute($this->newCommand($commandName, $jsonParameters));
90+
$response = $this->driver->execute($this->newCommand($commandName, $jsonParameters));
91+
10692
return $response->getValue();
10793
}
10894

10995
protected function postCommand($name, ElementCriteria $criteria)
11096
{
111-
$response = $this->driver->curl('POST',
112-
$this->url->addCommand($name),
113-
$criteria->getArrayCopy());
97+
$response = $this->driver->curl(
98+
'POST',
99+
$this->url->addCommand($name),
100+
$criteria->getArrayCopy()
101+
);
102+
114103
return $response->getValue();
115104
}
116105

117106
/**
118-
* @params string $commandClass a class name, descending from Command
119107
* @return callable
108+
*
109+
* @params string $commandClass a class name, descending from Command
120110
*/
121111
private function factoryMethod($commandClass)
122112
{
123-
return function($jsonParameters, $url) use ($commandClass) {
113+
return static function ($jsonParameters, $url) use ($commandClass) {
124114
return new $commandClass($jsonParameters, $url);
125115
};
126116
}
@@ -129,9 +119,10 @@ private function extractJsonParameters($arguments)
129119
{
130120
$this->checkArguments($arguments);
131121

132-
if (count($arguments) == 0) {
133-
return NULL;
122+
if (count($arguments) === 0) {
123+
return null;
134124
}
125+
135126
return $arguments[0];
136127
}
137128

@@ -143,19 +134,21 @@ private function checkArguments($arguments)
143134
}
144135

145136
/**
146-
* @param string $commandName The called method name
147-
* defined as a key in initCommands()
148-
* @param array $jsonParameters
137+
* @param string $commandName The called method name
138+
* defined as a key in initCommands()
139+
* @param array $jsonParameters
140+
*
149141
* @return Command
150142
*/
151143
protected function newCommand($commandName, $jsonParameters)
152144
{
153145
if (isset($this->commands[$commandName])) {
154146
$factoryMethod = $this->commands[$commandName];
155-
$url = $this->url->addCommand($commandName);
156-
$command = $factoryMethod($jsonParameters, $url);
157-
return $command;
147+
$url = $this->url->addCommand($commandName);
148+
149+
return $factoryMethod($jsonParameters, $url);
158150
}
159-
throw new BadMethodCallException("The command '$commandName' is not existent or not supported yet.");
151+
152+
throw new BadMethodCallException(sprintf("The command '%s' is not existent or not supported yet.", $commandName));
160153
}
161154
}

PHPUnit/Extensions/Selenium2TestCase/Driver.php

+41-44
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@
3434
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3535
* POSSIBILITY OF SUCH DAMAGE.
3636
*
37-
* @package PHPUnit_Selenium
38-
* @author Giorgio Sironi <[email protected]>
39-
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
40-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
4137
* @link http://www.phpunit.de/
42-
* @since File available since Release 1.2.0
4338
*/
4439

4540
namespace PHPUnit\Extensions\Selenium2TestCase;
@@ -50,13 +45,7 @@
5045
/**
5146
* Driver for creating browser session with Selenium 2 (WebDriver API).
5247
*
53-
* @package PHPUnit_Selenium
54-
* @author Giorgio Sironi <[email protected]>
55-
* @copyright 2010-2013 Sebastian Bergmann <[email protected]>
56-
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
57-
* @version Release: @package_version@
5848
* @link http://www.phpunit.de/
59-
* @since Class available since Release 1.2.0
6049
*/
6150
class Driver
6251
{
@@ -65,23 +54,22 @@ class Driver
6554

6655
public function __construct(URL $seleniumServerUrl, $timeout = 60)
6756
{
68-
$this->seleniumServerUrl = $seleniumServerUrl;
57+
$this->seleniumServerUrl = $seleniumServerUrl;
6958
$this->seleniumServerRequestsTimeout = $timeout;
7059
}
7160

7261
public function startSession(array $desiredCapabilities, URL $browserUrl)
7362
{
74-
$sessionCreation = $this->seleniumServerUrl->descend("/wd/hub/session");
75-
$response = $this->curl('POST', $sessionCreation, array(
76-
'desiredCapabilities' => $desiredCapabilities
77-
));
78-
$sessionPrefix = $response->getURL();
63+
$sessionCreation = $this->seleniumServerUrl->descend('/wd/hub/session');
64+
$response = $this->curl('POST', $sessionCreation, ['desiredCapabilities' => $desiredCapabilities,]);
65+
$sessionPrefix = $response->getURL();
7966

8067
$timeouts = new Timeouts(
8168
$this,
8269
$sessionPrefix->descend('timeouts'),
8370
$this->seleniumServerRequestsTimeout * 1000
8471
);
72+
8573
return new Session(
8674
$this,
8775
$sessionPrefix,
@@ -93,59 +81,66 @@ public function startSession(array $desiredCapabilities, URL $browserUrl)
9381
/**
9482
* Performs an HTTP request to the Selenium 2 server.
9583
*
96-
* @param string $method 'GET'|'POST'|'DELETE'|...
84+
* @param string $method 'GET'|'POST'|'DELETE'|...
9785
* @param string $url
98-
* @param array $params JSON parameters for POST requests
86+
* @param array $params JSON parameters for POST requests
9987
*/
100-
public function curl($http_method, URL $url, $params = NULL)
88+
public function curl($httpMethod, URL $url, $params = null)
10189
{
10290
$curl = curl_init($url->getValue());
10391
curl_setopt($curl, CURLOPT_TIMEOUT, $this->seleniumServerRequestsTimeout);
104-
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
105-
curl_setopt($curl,
106-
CURLOPT_HTTPHEADER,
107-
array(
108-
'Content-type: application/json;charset=UTF-8',
109-
'Accept: application/json;charset=UTF-8'
110-
));
111-
112-
if ($http_method === 'POST') {
113-
curl_setopt($curl, CURLOPT_POST, TRUE);
92+
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
93+
curl_setopt(
94+
$curl,
95+
CURLOPT_HTTPHEADER,
96+
[
97+
'Content-type: application/json;charset=UTF-8',
98+
'Accept: application/json;charset=UTF-8',
99+
]
100+
);
101+
102+
if ($httpMethod === 'POST') {
103+
curl_setopt($curl, CURLOPT_POST, true);
114104
if ($params && is_array($params)) {
115105
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));
116106
} else {
117107
curl_setopt($curl, CURLOPT_POSTFIELDS, '');
118108
}
119-
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
120-
} else if ($http_method == 'DELETE') {
109+
110+
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
111+
} elseif ($httpMethod === 'DELETE') {
121112
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
122113
}
123114

124115
$rawResponse = trim(curl_exec($curl));
125116
if (curl_errno($curl)) {
126117
throw new NoSeleniumException(
127118
'Error connection[' . curl_errno($curl) . '] to ' .
128-
$url->getValue() . ': ' . curl_error($curl)
119+
$url->getValue() . ': ' . curl_error($curl)
129120
);
130121
}
122+
131123
$info = curl_getinfo($curl);
132-
if ($info['http_code'] == 0) {
124+
if ($info['http_code'] === 0) {
133125
throw new NoSeleniumException();
134126
}
135-
if ($info['http_code'] == 404) {
136-
throw new BadMethodCallException("The command $url is not recognized by the server.");
127+
128+
if ($info['http_code'] === 404) {
129+
throw new BadMethodCallException(sprintf('The command %s is not recognized by the server.', $url));
137130
}
131+
138132
if (($info['http_code'] >= 400) && ($info['http_code'] < 500)) {
139-
throw new BadMethodCallException("Something unexpected happened: '$rawResponse'");
133+
throw new BadMethodCallException(sprintf("Something unexpected happened: '%s'", $rawResponse));
140134
}
135+
141136
curl_close($curl);
142-
$content = json_decode($rawResponse, TRUE);
137+
$content = json_decode($rawResponse, true);
143138

144139
if ($content === null && json_last_error() !== JSON_ERROR_NONE) {
145140
throw new \PHPUnit\Extensions\Selenium2TestCase\Exception(
146141
sprintf(
147-
"JSON decoding of remote response failed.\n".
148-
"Error code: %d\n".
142+
"JSON decoding of remote response failed.\n" .
143+
"Error code: %d\n" .
149144
"The response: '%s'\n",
150145
json_last_error(),
151146
$rawResponse
@@ -163,7 +158,7 @@ public function curl($http_method, URL $url, $params = NULL)
163158
$message = $value['message'];
164159
}
165160

166-
$status = isset($content['status']) ? $content['status'] : 0;
161+
$status = $content['status'] ?? 0;
167162
if ($status !== WebDriverException::Success) {
168163
throw new WebDriverException($message, $status);
169164
}
@@ -173,8 +168,10 @@ public function curl($http_method, URL $url, $params = NULL)
173168

174169
public function execute(Command $command)
175170
{
176-
return $this->curl($command->httpMethod(),
177-
$command->url(),
178-
$command->jsonParameters());
171+
return $this->curl(
172+
$command->httpMethod(),
173+
$command->url(),
174+
$command->jsonParameters()
175+
);
179176
}
180177
}

0 commit comments

Comments
 (0)