|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\Codeception\Helper\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Codeception\Module\PhpBrowser; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class UriTrait |
|
9
|
|
|
* @package ByTIC\Common\Tests\Helper\Traits |
|
10
|
|
|
*/ |
|
11
|
|
|
trait BrowserTrait |
|
12
|
|
|
{ |
|
13
|
|
|
use AbstractTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @param $method |
|
17
|
|
|
* @param $url |
|
18
|
|
|
* @param $post |
|
19
|
|
|
* |
|
20
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
21
|
|
|
*/ |
|
22
|
|
|
public function loadPage($method, $url, $post) |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->getBrowserModule()->_loadPage($method, $url, $post); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @return \Codeception\Module|PhpBrowser |
|
29
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function getBrowserModule() |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->getModule('PhpBrowser'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param $name |
|
39
|
|
|
* |
|
40
|
|
|
* @return mixed |
|
41
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getCurrentUriParam($name) |
|
44
|
|
|
{ |
|
45
|
|
|
$uri = $this->getCurrentUri(); |
|
46
|
|
|
$query = parse_url($uri, PHP_URL_QUERY); |
|
47
|
|
|
parse_str($query, $params); |
|
48
|
|
|
|
|
49
|
|
|
return $params[$name]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return mixed |
|
54
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getCurrentUri() |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->getBrowserModule()->_getCurrentUri(); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return mixed |
|
64
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function getCurrentUrl() |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->getBrowserModule()->client->getHistory()->current()->getUri(); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param $expected |
|
74
|
|
|
* |
|
75
|
|
|
* @throws \Codeception\Exception\ModuleException |
|
76
|
|
|
*/ |
|
77
|
|
|
public function seeFullUrlEquals($expected) |
|
78
|
|
|
{ |
|
79
|
|
|
$url = $this->getCurrentUrl(); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertEquals($expected, $url); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: