These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of the phpunit-mink library. |
||
4 | * For the full copyright and license information, please view |
||
5 | * the LICENSE file that was distributed with this source code. |
||
6 | * |
||
7 | * @copyright Alexander Obuhovich <[email protected]> |
||
8 | * @link https://github.com/aik099/phpunit-mink |
||
9 | */ |
||
10 | |||
11 | |||
12 | namespace aik099\PHPUnit\MinkDriver; |
||
13 | |||
14 | |||
15 | use aik099\PHPUnit\BrowserConfiguration\BrowserConfiguration; |
||
16 | use Behat\Mink\Driver\DriverInterface; |
||
17 | |||
18 | class PhantomJsDriverFactory implements IMinkDriverFactory |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * Returns driver name, that can be used in browser configuration. |
||
23 | * |
||
24 | * @return string |
||
25 | */ |
||
26 | 11 | public function getDriverName() |
|
27 | { |
||
28 | 11 | return 'phantomjs'; |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * Returns default values for browser configuration. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | 1 | public function getDriverDefaults() |
|
37 | { |
||
38 | return array( |
||
39 | 1 | 'host' => 'localhost', |
|
40 | 1 | 'driver' => 'phantomjs', |
|
41 | 1 | 'driverOptions' => array(), |
|
42 | 1 | 'browserName' => 'phantomjs', |
|
43 | 1 | 'port' => 8510, |
|
44 | 1 | ); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Returns a new driver instance according to the browser configuration. |
||
49 | * |
||
50 | * @param BrowserConfiguration $browser The browser configuration. |
||
51 | * |
||
52 | * @return DriverInterface |
||
53 | */ |
||
0 ignored issues
–
show
Coding Style
Documentation
introduced
by
Loading history...
|
|||
54 | 1 | public function createDriver(BrowserConfiguration $browser) |
|
55 | { |
||
56 | 1 | if ( !class_exists('Zumba\Mink\Driver\PhantomJSDriver') ) { |
|
57 | 1 | throw new \RuntimeException( |
|
58 | 'Install MinkPhantomJSDriver in order to use phantomjs driver.' |
||
59 | 1 | ); |
|
60 | } |
||
61 | |||
62 | return new \Zumba\Mink\Driver\PhantomJSDriver(sprintf( |
||
0 ignored issues
–
show
The return type of
return new \Zumba\Mink\D...r->getPort(), '/api')); (Zumba\Mink\Driver\PhantomJSDriver ) is incompatible with the return type declared by the interface aik099\PHPUnit\MinkDrive...erFactory::createDriver of type Behat\Mink\Driver\DriverInterface .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function
Loading history...
|
|||
63 | 'http://%s:%s%s', |
||
64 | $browser->getHost(), |
||
65 | $browser->getPort(), |
||
66 | '/api' |
||
67 | )); |
||
68 | } |
||
69 | |||
70 | } |
||
71 |