Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit b7186fb

Browse files
authored
Merge pull request #311 from OndraM/psr-2
PSR-2 codestyle
2 parents 7d14872 + 642b5e4 commit b7186fb

File tree

147 files changed

+7708
-7160
lines changed

Some content is hidden

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

147 files changed

+7708
-7160
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
composer.phar
22
composer.lock
33
vendor
4+
.php_cs.cache
45

56
# generic files to ignore
67
*.lock
78
*.DS_Store
89
*~
910
*.swp
10-
.idea
11+
.idea

.php_cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
$finder = Symfony\CS\Finder\DefaultFinder::create()
4+
->in(array(__DIR__ . '/lib', __DIR__ . '/tests'));
5+
6+
return Symfony\CS\Config\Config::create()
7+
->fixers(array(
8+
'duplicate_semicolon',
9+
'extra_empty_lines',
10+
'multiline_array_trailing_comma',
11+
'namespace_no_leading_whitespace',
12+
'new_with_braces',
13+
'no_blank_lines_after_class_opening',
14+
'no_empty_lines_after_phpdocs',
15+
'object_operator',
16+
'operators_spaces',
17+
'trim_array_spaces',
18+
'phpdoc_indent',
19+
'phpdoc_no_access',
20+
'phpdoc_no_empty_return',
21+
'phpdoc_no_package',
22+
'phpdoc_scalar',
23+
'phpdoc_trim',
24+
'phpdoc_types',
25+
'phpdoc_order',
26+
'unused_use',
27+
'ordered_use',
28+
'remove_leading_slash_use',
29+
'remove_lines_between_uses',
30+
'function_typehint_space',
31+
'self_accessor',
32+
'single_array_no_trailing_comma',
33+
'single_blank_line_before_namespace',
34+
'single_quote',
35+
'spaces_cast',
36+
'whitespacy_lines',
37+
'newline_after_open_tag',
38+
))
39+
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
40+
->setUsingCache(true)
41+
->finder($finder);

.travis.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ php:
1010
- 7
1111
- hhvm
1212

13+
matrix:
14+
include:
15+
# Add PHP 7 build to check codestyle only in PHP 7 build
16+
- php: 7
17+
env: CHECK_CODESTYLE=1
18+
1319
env:
1420
global:
1521
- DISPLAY=:99.0
@@ -19,18 +25,21 @@ cache:
1925
- $HOME/.composer/cache
2026

2127
before_install:
22-
- composer self-update
28+
- travis_retry composer self-update
2329

2430
install:
25-
- composer install --no-interaction --prefer-source
31+
- travis_retry composer install --no-interaction --prefer-source
2632

2733
before_script:
28-
- sh -e /etc/init.d/xvfb start
29-
- wget -q -t 3 http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar
30-
- java -jar selenium-server-standalone-2.45.0.jar -log selenium.log &
31-
- until $(echo | nc localhost 4444); do sleep 1; echo waiting for selenium-server...; done;
32-
33-
script: ./vendor/bin/phpunit
34+
- if [ -z "$CHECK_CODESTYLE" ]; then sh -e /etc/init.d/xvfb start; fi
35+
- if [ -z "$CHECK_CODESTYLE" ]; then wget -q -t 3 http://selenium-release.storage.googleapis.com/2.45/selenium-server-standalone-2.45.0.jar; fi
36+
- if [ -z "$CHECK_CODESTYLE" ]; then java -jar selenium-server-standalone-2.45.0.jar -log selenium.log; fi &
37+
- if [ -z "$CHECK_CODESTYLE" ]; then until $(echo | nc localhost 4444); do sleep 1; echo waiting for selenium-server...; done; fi
38+
39+
script:
40+
- if [ -n "$CHECK_CODESTYLE" ]; then ./vendor/bin/php-cs-fixer fix --diff --dry-run; fi
41+
- if [ -n "$CHECK_CODESTYLE" ]; then ./vendor/bin/phpcs --standard=PSR2 ./lib/ ./tests/; fi
42+
- if [ -z "$CHECK_CODESTYLE" ]; then ./vendor/bin/phpunit; fi
3443

3544
after_script:
3645
- cat selenium.log

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/).
33

44
## Unreleased
55
- Fixed FirefoxProfile to support installation of extensions with custom namespace prefix in their manifest file
6+
- Comply codestyle with [PSR-2](http://www.php-fig.org/psr/psr-2/)
67

78
## 1.1.2 - 2016-06-04
89
- Added ext-curl to composer.json

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ send a pull request (see bellow) with your contribution.
99

1010
1. Fork the project on GitHub
1111
2. Implement your code changes into separate branch
12-
3. Make sure all PHPUnit tests passes (see below). We also have Travis CI build which will automatically run tests on your pull request).
12+
3. Make sure all PHPUnit tests passes and code-style matches PSR-2 (see below). We also have Travis CI build which will automatically run tests on your pull request.
1313
4. When implementing notable change, fix or a new feature, add record to Unreleased section of [CHANGELOG.md](CHANGELOG.md)
1414
5. Submit your [pull request](https://github.com/facebook/php-webdriver/pulls) against community branch
1515

@@ -34,3 +34,10 @@ For the functional tests you must first download and start the selenium server,
3434

3535
java -jar selenium-server-standalone-2.48.2.jar -log selenium.log &
3636
./vendor/bin/phpunit --testsuite functional
37+
38+
### Check coding style
39+
40+
Your code-style should comply with [PSR-2](http://www.php-fig.org/psr/psr-2/). To make sure your code matches this requirement run:
41+
42+
./vendor/bin/php-cs-fixer fix --diff --dry-run
43+
./vendor/bin/phpcs --standard=PSR2 ./lib/ ./tests/

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"ext-curl": "*"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "4.6.*"
18+
"phpunit/phpunit": "4.6.* || ~5.0",
19+
"friendsofphp/php-cs-fixer": "^1.11",
20+
"squizlabs/php_codesniffer": "^2.6"
1921
},
2022
"suggest": {
2123
"phpdocumentor/phpdocumentor": "2.*"

lib/Chrome/ChromeDriver.php

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,72 @@
1515

1616
namespace Facebook\WebDriver\Chrome;
1717

18+
use Facebook\WebDriver\Exception\WebDriverException;
1819
use Facebook\WebDriver\Remote\DesiredCapabilities;
1920
use Facebook\WebDriver\Remote\DriverCommand;
20-
use Facebook\WebDriver\Remote\Service\DriverCommandExecutor;
21-
use Facebook\WebDriver\Exception\WebDriverException;
2221
use Facebook\WebDriver\Remote\RemoteWebDriver;
22+
use Facebook\WebDriver\Remote\Service\DriverCommandExecutor;
2323
use Facebook\WebDriver\Remote\WebDriverCommand;
2424

25-
class ChromeDriver extends RemoteWebDriver {
25+
class ChromeDriver extends RemoteWebDriver
26+
{
27+
public static function start(DesiredCapabilities $desired_capabilities = null, ChromeDriverService $service = null)
28+
{
29+
if ($desired_capabilities === null) {
30+
$desired_capabilities = DesiredCapabilities::chrome();
31+
}
32+
if ($service === null) {
33+
$service = ChromeDriverService::createDefaultService();
34+
}
35+
$executor = new DriverCommandExecutor($service);
36+
$driver = new static();
37+
$driver->setCommandExecutor($executor)
38+
->startSession($desired_capabilities);
2639

27-
public static function start(
28-
DesiredCapabilities $desired_capabilities = null,
29-
ChromeDriverService $service = null
30-
) {
31-
if ($desired_capabilities === null) {
32-
$desired_capabilities = DesiredCapabilities::chrome();
40+
return $driver;
3341
}
34-
if ($service === null) {
35-
$service = ChromeDriverService::createDefaultService();
36-
}
37-
$executor = new DriverCommandExecutor($service);
38-
$driver = new static();
39-
$driver->setCommandExecutor($executor)
40-
->startSession($desired_capabilities);
41-
return $driver;
42-
}
4342

44-
public function startSession($desired_capabilities) {
45-
$command = new WebDriverCommand(
46-
null,
47-
DriverCommand::NEW_SESSION,
48-
array(
49-
'desiredCapabilities' => $desired_capabilities->toArray(),
50-
)
51-
);
52-
$response = $this->executor->execute($command);
53-
$this->setSessionID($response->getSessionID());
54-
}
43+
public function startSession($desired_capabilities)
44+
{
45+
$command = new WebDriverCommand(
46+
null,
47+
DriverCommand::NEW_SESSION,
48+
array(
49+
'desiredCapabilities' => $desired_capabilities->toArray(),
50+
)
51+
);
52+
$response = $this->executor->execute($command);
53+
$this->setSessionID($response->getSessionID());
54+
}
5555

56-
/**
57-
* Always throws an exception. Use ChromeDriver::start() instead.
58-
*
59-
* @throws WebDriverException
60-
*/
61-
public static function create(
62-
$url = 'http://localhost:4444/wd/hub',
63-
$desired_capabilities = null,
64-
$connection_timeout_in_ms = null,
65-
$request_timeout_in_ms = null,
66-
$http_proxy = null,
67-
$http_proxy_port = null
68-
) {
69-
throw new WebDriverException('Please use ChromeDriver::start() instead.');
70-
}
56+
/**
57+
* Always throws an exception. Use ChromeDriver::start() instead.
58+
*
59+
* @throws WebDriverException
60+
*/
61+
public static function create(
62+
$url = 'http://localhost:4444/wd/hub',
63+
$desired_capabilities = null,
64+
$connection_timeout_in_ms = null,
65+
$request_timeout_in_ms = null,
66+
$http_proxy = null,
67+
$http_proxy_port = null
68+
) {
69+
throw new WebDriverException('Please use ChromeDriver::start() instead.');
70+
}
7171

72-
/**
73-
* Always throws an exception. Use ChromeDriver::start() instead.
74-
*
75-
* @param string $session_id The existing session id
76-
* @param string $url The url of the remote server
77-
*
78-
* @throws WebDriverException
79-
*/
80-
public static function createBySessionID(
81-
$session_id,
82-
$url = 'http://localhost:4444/wd/hub'
83-
) {
84-
throw new WebDriverException('Please use ChromeDriver::start() instead.');
85-
}
72+
/**
73+
* Always throws an exception. Use ChromeDriver::start() instead.
74+
*
75+
* @param string $session_id The existing session id
76+
* @param string $url The url of the remote server
77+
*
78+
* @throws WebDriverException
79+
*/
80+
public static function createBySessionID(
81+
$session_id,
82+
$url = 'http://localhost:4444/wd/hub'
83+
) {
84+
throw new WebDriverException('Please use ChromeDriver::start() instead.');
85+
}
8686
}

lib/Chrome/ChromeDriverService.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717

1818
use Facebook\WebDriver\Remote\Service\DriverService;
1919

20-
class ChromeDriverService extends DriverService {
20+
class ChromeDriverService extends DriverService
21+
{
22+
// The environment variable storing the path to the chrome driver executable.
23+
const CHROME_DRIVER_EXE_PROPERTY = 'webdriver.chrome.driver';
2124

22-
// The environment variable storing the path to the chrome driver executable.
23-
const CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
24-
25-
public static function createDefaultService() {
26-
$exe = getenv(self::CHROME_DRIVER_EXE_PROPERTY);
27-
$port = 9515; // TODO: Get another port if the default port is used.
28-
$args = array("--port=$port");
29-
$service = new ChromeDriverService($exe, $port, $args);
30-
return $service;
31-
}
25+
public static function createDefaultService()
26+
{
27+
$exe = getenv(self::CHROME_DRIVER_EXE_PROPERTY);
28+
$port = 9515; // TODO: Get another port if the default port is used.
29+
$args = array("--port=$port");
30+
$service = new self($exe, $port, $args);
3231

32+
return $service;
33+
}
3334
}

0 commit comments

Comments
 (0)