Skip to content

Commit c35aaa1

Browse files
committed
Coding style changes
1 parent 6230447 commit c35aaa1

File tree

7 files changed

+66
-39
lines changed

7 files changed

+66
-39
lines changed

lib/WebDriver/AbstractWebDriver.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ protected function curl($requestMethod, $command, $parameters = null, $extraOpti
139139
}
140140

141141
$value = null;
142+
142143
if (array_key_exists('value', $result)) {
143144
$value = $result['value'];
144145
}
145146

146147
$message = null;
148+
147149
if (is_array($value) && array_key_exists('message', $value)) {
148150
$message = $value['message'];
149151
}
@@ -195,6 +197,7 @@ public function __call($name, $arguments)
195197
}
196198

197199
$methods = $this->methods();
200+
198201
if (!in_array($requestMethod, (array) $methods[$webdriverCommand])) {
199202
throw WebDriverException::factory(
200203
WebDriverException::INVALID_REQUEST,

lib/WebDriver/Exception/CurlExec.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*
1919
* @author Justin Bishop <[email protected]>
2020
* @author Anthon Pang <[email protected]>
21+
* @author Gaetano Giunta <[email protected]>
2122
*/
2223

2324
namespace WebDriver\Exception;
@@ -31,4 +32,28 @@
3132
*/
3233
final class CurlExec extends BaseException
3334
{
35+
/**
36+
* @var array
37+
*/
38+
private $curlInfo = array();
39+
40+
/**
41+
* {@inheritdoc}
42+
*/
43+
public function __construct($message = null, $code = 0, \Exception $previous = null, $curlInfo = array())
44+
{
45+
parent::__construct($message, $code, $previous);
46+
47+
$this->curlInfo = $curlInfo;
48+
}
49+
50+
/**
51+
* Get curl info
52+
*
53+
* @return array
54+
*/
55+
public function getCurlInfo()
56+
{
57+
return $this->curlInfo;
58+
}
3459
}

lib/WebDriver/SauceLabs/SauceRest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($userId, $accessKey)
6262
*
6363
* @return mixed
6464
*
65-
* @throws \WebDriver\Service\CurlServiceException
65+
* @throws \WebDriver\Exception\CurlExec
6666
*
6767
* @see http://saucelabs.com/docs/saucerest
6868
*/

lib/WebDriver/Service/CurlService.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace WebDriver\Service;
2525

26+
use WebDriver\Exception as WebDriverException;
27+
2628
/**
2729
* WebDriver\Service\CurlService class
2830
*
@@ -87,24 +89,28 @@ public function execute($requestMethod, $url, $parameters = null, $extraOptions
8789
curl_setopt($curl, CURLOPT_HTTPHEADER, $customHeaders);
8890

8991
$rawResult = trim(curl_exec($curl));
92+
9093
$info = curl_getinfo($curl);
91-
// enrich the info a bit
9294
$info['request_method'] = $requestMethod;
9395

94-
// NB: this only gets triggered when CURLOPT_FAILONERROR has been set in extraOptions.
96+
// This only gets triggered when CURLOPT_FAILONERROR has been set in extraOptions.
9597
// In that case, $rawResult is always empty.
9698
if (CURLE_GOT_NOTHING !== ($errno = curl_errno($curl)) && $error = curl_error($curl)) {
97-
9899
curl_close($curl);
99100

100-
$message = sprintf(
101-
"Curl error thrown for http %s to %s%s\n\n%s",
102-
$requestMethod,
103-
$url,
104-
$parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '',
105-
$error
101+
throw WebDriverException::factory(
102+
WebDriverException::CURL_EXEC,
103+
sprintf(
104+
"Curl error thrown for http %s to %s%s\n\n%s",
105+
$requestMethod,
106+
$url,
107+
$parameters && is_array($parameters) ? ' with params: ' . json_encode($parameters) : '',
108+
$error
109+
),
110+
$errno,
111+
null,
112+
$info
106113
);
107-
throw new CurlServiceException($message, $errno, null, $info);
108114
}
109115

110116
curl_close($curl);

lib/WebDriver/Service/CurlServiceException.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/WebDriver/Service/CurlServiceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface CurlServiceInterface
3939
*
4040
* @return array
4141
*
42-
* @throws \WebDriver\Service\CurlServiceException only if http error and CURLOPT_FAILONERROR has been set in extraOptions
42+
* @throws \WebDriver\Exception\CurlExec only if http error and CURLOPT_FAILONERROR has been set in extraOptions
4343
*/
4444
public function execute($requestMethod, $url, $parameters = null, $extraOptions = array());
4545
}

test/Test/WebDriver/WebDriverTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
* Test WebDriver\WebDriver class
2828
*
2929
* @package WebDriver
30+
*
31+
* @group Functional
3032
*/
3133
class WebDriverTest extends \PHPUnit_Framework_TestCase
3234
{
@@ -43,9 +45,11 @@ protected function setUp()
4345
if ($url = getenv('ROOT_URL')) {
4446
$this->testDocumentRootUrl = $url;
4547
}
48+
4649
if ($url = getenv('SELENIUM_URL')) {
4750
$this->testSeleniumRootUrl = $url;
4851
}
52+
4953
$this->driver = new WebDriver($this->getTestSeleniumRootUrl());
5054
$this->session = null;
5155
}
@@ -63,6 +67,7 @@ protected function tearDown()
6367
/**
6468
* Returns the full url to the test site (corresponding to the root dir of the library).
6569
* You can set this via env var ROOT_URL
70+
*
6671
* @return string
6772
*/
6873
protected function getTestDocumentRootUrl()
@@ -72,6 +77,7 @@ protected function getTestDocumentRootUrl()
7277

7378
/**
7479
* Returns the full url to the Selenium server used for functional tests
80+
*
7581
* @return string
7682
*
7783
* @todo make this configurable via env var
@@ -81,19 +87,27 @@ protected function getTestSeleniumRootUrl()
8187
return $this->testSeleniumRootUrl;
8288
}
8389

90+
/**
91+
* Is Selenium down?
92+
*
93+
* @param \Exception $exception
94+
*
95+
* @return boolean
96+
*/
8497
protected function isSeleniumDown($exception)
8598
{
8699
return preg_match('/Failed to connect to .* Connection refused/', $exception->getMessage()) != false
87-
|| strpos($exception->getMessage(), 'couldn\'t connect to host') !== false;
100+
|| strpos($exception->getMessage(), 'couldn\'t connect to host') !== false
101+
|| strpos($exception->getMessage(), 'Unable to connect to host') !== false;
88102
}
89103

90104
/**
91-
* @group Functional
105+
* Test driver sessions
92106
*/
93107
public function testSessions()
94108
{
95109
try {
96-
$this->assertCount(0, $this->driver->sessions());
110+
$this->assertCount(0, $this->driver->sessions());
97111

98112
$this->session = $this->driver->session();
99113
} catch (\Exception $e) {
@@ -109,7 +123,7 @@ public function testSessions()
109123
}
110124

111125
/**
112-
* @group Functional
126+
* Test driver status
113127
*/
114128
public function testStatus()
115129
{
@@ -131,7 +145,6 @@ public function testStatus()
131145

132146
/**
133147
* Checks that an error connecting to Selenium gives back the expected exception
134-
* @group Functional
135148
*/
136149
public function testSeleniumError()
137150
{
@@ -151,13 +164,9 @@ public function testSeleniumError()
151164

152165
/**
153166
* Checks that a successful command to Selenium which returns an http error response gives back the expected exception
154-
* @group Functional
155167
*/
156168
public function testSeleniumErrorResponse()
157169
{
158-
$this->markTestSkipped('this test is currently broken'); // see https://github.com/instaclick/php-webdriver/issues/77
159-
return;
160-
161170
try {
162171
$status = $this->driver->status();
163172
} catch (\Exception $e) {
@@ -171,6 +180,7 @@ public function testSeleniumErrorResponse()
171180
try {
172181
$this->session = $this->driver->session();
173182
$this->session->open($this->getTestDocumentRootUrl().'/test/Assets/index.html');
183+
174184
$element = $this->session->element('id', 'a-quite-unlikely-html-element-id');
175185

176186
$this->fail('Exception not thrown while looking for missing element in page');
@@ -181,7 +191,6 @@ public function testSeleniumErrorResponse()
181191

182192
/**
183193
* Checks that a successful command to Selenium which returns 'nothing' according to spec does not raise an error
184-
* @group Functional
185194
*/
186195
public function testSeleniumNoResponse()
187196
{
@@ -198,6 +207,7 @@ public function testSeleniumNoResponse()
198207
$this->session = $this->driver->session();
199208
$timeouts = $this->session->timeouts();
200209
$out = $timeouts->async_script(array('type' => 'implicit', 'ms' => 1000));
210+
201211
$this->assertEquals(null, $out);
202212
}
203213
}

0 commit comments

Comments
 (0)