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

Commit cc69cf0

Browse files
committed
Use createMock shortcut contained in new PHPUnit
1 parent cec193f commit cc69cf0

File tree

1 file changed

+14
-31
lines changed

1 file changed

+14
-31
lines changed

tests/unit/WebDriverExpectedConditionTest.php

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ class WebDriverExpectedConditionTest extends TestCase
3434

3535
protected function setUp()
3636
{
37-
// TODO: replace with createMock() once PHP 5.5 support is dropped
38-
$this->driverMock = $this
39-
->getMockBuilder(RemoteWebDriver::class)
40-
->disableOriginalConstructor()
41-
->getMock();
37+
$this->driverMock = $this->createMock(RemoteWebDriver::class);
4238
$this->wait = new WebDriverWait($this->driverMock, 1, 1);
4339
}
4440

@@ -141,7 +137,7 @@ public function testShouldDetectPresenceOfElementLocatedCondition()
141137

142138
public function testShouldDetectPresenceOfAllElementsLocatedByCondition()
143139
{
144-
$element = $this->createRemoteWebElementMock();
140+
$element = $this->createMock(RemoteWebElement::class);
145141

146142
$this->driverMock->expects($this->at(0))
147143
->method('findElements')
@@ -166,7 +162,7 @@ public function testShouldDetectVisibilityOfElementLocatedCondition()
166162
// Call #3: return Element, but isDisplayed will return false
167163
// Call #4: return Element, isDisplayed will true and condition will match
168164

169-
$element = $this->createRemoteWebElementMock();
165+
$element = $this->createMock(RemoteWebElement::class);
170166
$element->expects($this->at(0))
171167
->method('isDisplayed')
172168
->willThrowException(new StaleElementReferenceException(''));
@@ -189,9 +185,9 @@ public function testShouldDetectVisibilityOfElementLocatedCondition()
189185
public function testShouldDetectVisibilityOfAnyElementLocated()
190186
{
191187
$elementList = [
192-
$this->createRemoteWebElementMock(),
193-
$this->createRemoteWebElementMock(),
194-
$this->createRemoteWebElementMock(),
188+
$this->createMock(RemoteWebElement::class),
189+
$this->createMock(RemoteWebElement::class),
190+
$this->createMock(RemoteWebElement::class),
195191
];
196192

197193
$elementList[0]->expects($this->once())
@@ -218,7 +214,7 @@ public function testShouldDetectVisibilityOfAnyElementLocated()
218214

219215
public function testShouldDetectInvisibilityOfElementLocatedConditionOnNoSuchElementException()
220216
{
221-
$element = $this->createRemoteWebElementMock();
217+
$element = $this->createMock(RemoteWebElement::class);
222218

223219
$this->driverMock->expects($this->at(0))
224220
->method('findElement')
@@ -241,7 +237,7 @@ public function testShouldDetectInvisibilityOfElementLocatedConditionOnNoSuchEle
241237

242238
public function testShouldDetectInvisibilityOfElementLocatedConditionOnStaleElementReferenceException()
243239
{
244-
$element = $this->createRemoteWebElementMock();
240+
$element = $this->createMock(RemoteWebElement::class);
245241

246242
$this->driverMock->expects($this->exactly(2))
247243
->method('findElement')
@@ -263,7 +259,7 @@ public function testShouldDetectInvisibilityOfElementLocatedConditionOnStaleElem
263259

264260
public function testShouldDetectInvisibilityOfElementLocatedConditionWhenElementBecamesInvisible()
265261
{
266-
$element = $this->createRemoteWebElementMock();
262+
$element = $this->createMock(RemoteWebElement::class);
267263

268264
$this->driverMock->expects($this->exactly(2))
269265
->method('findElement')
@@ -285,7 +281,7 @@ public function testShouldDetectInvisibilityOfElementLocatedConditionWhenElement
285281

286282
public function testShouldDetectVisibilityOfCondition()
287283
{
288-
$element = $this->createRemoteWebElementMock();
284+
$element = $this->createMock(RemoteWebElement::class);
289285
$element->expects($this->at(0))
290286
->method('isDisplayed')
291287
->willReturn(false);
@@ -307,7 +303,7 @@ public function testShouldDetectElementTextContainsCondition()
307303
// Call #3: return Element, but getText will throw StaleElementReferenceException
308304
// Call #4: return Element, getText will return new text and condition will match
309305

310-
$element = $this->createRemoteWebElementMock();
306+
$element = $this->createMock(RemoteWebElement::class);
311307
$element->expects($this->at(0))
312308
->method('getText')
313309
->willReturn('this is an old text');
@@ -335,7 +331,7 @@ public function testShouldDetectElementTextIsCondition()
335331
// Call #3: return Element, getText will return not-matching text
336332
// Call #4: return Element, getText will return new text and condition will match
337333

338-
$element = $this->createRemoteWebElementMock();
334+
$element = $this->createMock(RemoteWebElement::class);
339335
$element->expects($this->at(0))
340336
->method('getText')
341337
->willThrowException(new StaleElementReferenceException(''));
@@ -366,7 +362,7 @@ public function testShouldDetectElementTextMatchesCondition()
366362
// Call #3: return Element, getText will return not-matching text
367363
// Call #4: return Element, getText will return matching text
368364

369-
$element = $this->createRemoteWebElementMock();
365+
$element = $this->createMock(RemoteWebElement::class);
370366

371367
$element->expects($this->at(0))
372368
->method('getText')
@@ -398,7 +394,7 @@ public function testShouldDetectElementValueContainsCondition()
398394
// Call #3: return Element, getAttribute('value') will return not-matching text
399395
// Call #4: return Element, getAttribute('value') will return matching text
400396

401-
$element = $this->createRemoteWebElementMock();
397+
$element = $this->createMock(RemoteWebElement::class);
402398

403399
$element->expects($this->at(0))
404400
->method('getAttribute')
@@ -456,17 +452,4 @@ private function setupDriverToReturnElementAfterAnException($element, $expectedN
456452
->willReturn($element);
457453
}
458454
}
459-
460-
/**
461-
* @todo Replace with createMock() once PHP 5.5 support is dropped
462-
* @return \PHPUnit_Framework_MockObject_MockObject|RemoteWebElement
463-
*/
464-
private function createRemoteWebElementMock()
465-
{
466-
return $this->getMockBuilder(RemoteWebElement::class)
467-
->disableOriginalConstructor()
468-
->disableOriginalClone()
469-
->disableArgumentCloning()
470-
->getMock();
471-
}
472455
}

0 commit comments

Comments
 (0)