-
Notifications
You must be signed in to change notification settings - Fork 290
Expand file tree
/
Copy pathAbstractElement.php
More file actions
76 lines (64 loc) · 1.99 KB
/
AbstractElement.php
File metadata and controls
76 lines (64 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Behat\Mink\Tests\Element;
use Behat\Mink\Driver\DriverInterface;
use Behat\Mink\Session;
use Behat\Mink\Selector\SelectorsHandler;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
abstract class AbstractElement extends TestCase
{
/**
* Session.
*
* @var Session
*/
protected $session;
/**
* @var DriverInterface&MockObject
*/
protected $driver;
/**
* Selectors.
*
* @var SelectorsHandler&MockObject
*/
protected $selectors;
/**
* @before
*/
protected function prepareSession()
{
$this->driver = $this->getMockBuilder('Behat\Mink\Driver\DriverInterface')->getMock();
$this->driver
->expects($this->once())
->method('setSession');
$this->selectors = $this->getMockBuilder('Behat\Mink\Selector\SelectorsHandler')->getMock();
$this->session = new Session($this->driver, $this->selectors);
}
protected function mockNamedFinder($xpath, array $results, $locator, $times = 2)
{
if (!is_array($results[0])) {
$results = array($results, array());
}
// In case of empty results, a second call will be done using the partial selector
$processedResults = array();
foreach ($results as $result) {
$processedResults[] = $result;
if (empty($result)) {
$processedResults[] = $result;
++$times;
}
}
$returnValue = call_user_func_array(array($this, 'onConsecutiveCalls'), $processedResults);
$this->driver
->expects($this->exactly($times))
->method('find')
->with('//html'.$xpath)
->will($returnValue);
$this->selectors
->expects($this->exactly($times))
->method('selectorToXpath')
->with($this->logicalOr('named_exact', 'named_partial'), $locator)
->will($this->returnValue($xpath));
}
}