Skip to content

Commit a332fd1

Browse files
committed
Use PHPUnit 9 features and new configuration format
1 parent 939b77f commit a332fd1

9 files changed

+47
-50
lines changed

Diff for: .php-cs-fixer.dist.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
'ordered_class_elements' => true,
7777
'ordered_imports' => true,
7878
'php_unit_construct' => true,
79-
'php_unit_dedicate_assert' => false,
79+
'php_unit_dedicate_assert' => true,
80+
'php_unit_dedicate_assert_internal_type' => true,
8081
'php_unit_expectation' => ['target' => '8.4'],
8182
'php_unit_method_casing' => ['case' => 'camel_case'],
8283
'php_unit_mock_short_will_return' => true,

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"php-coveralls/php-coveralls": "^2.4",
2525
"php-mock/php-mock-phpunit": "^2.0",
2626
"php-parallel-lint/php-parallel-lint": "^1.2",
27-
"phpunit/phpunit": "^9",
27+
"phpunit/phpunit": "^9.3",
2828
"squizlabs/php_codesniffer": "^3.5",
2929
"symfony/var-dumper": "^5.0 || ^6.0"
3030
},

Diff for: phpunit.xml.dist

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
4-
<phpunit
5-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
7-
backupGlobals="false"
8-
colors="true"
9-
bootstrap="tests/bootstrap.php"
10-
>
11-
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
colors="true"
5+
bootstrap="tests/bootstrap.php"
6+
>
127
<testsuites>
138
<testsuite name="unit">
149
<directory>tests/unit</directory>
@@ -18,14 +13,13 @@
1813
</testsuite>
1914
</testsuites>
2015

21-
<filter>
22-
<whitelist>
16+
<coverage>
17+
<include>
2318
<directory suffix=".php">./lib</directory>
24-
</whitelist>
25-
</filter>
19+
</include>
20+
</coverage>
2621

2722
<listeners>
2823
<listener class="Facebook\WebDriver\ReportSauceLabsStatusListener"/>
2924
</listeners>
30-
3125
</phpunit>

Diff for: tests/functional/RemoteWebDriverCreateTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function testShouldStartBrowserAndCreateInstanceOfRemoteWebDriver()
3030
$this->assertInstanceOf(HttpCommandExecutor::class, $this->driver->getCommandExecutor());
3131
$this->assertNotEmpty($this->driver->getCommandExecutor()->getAddressOfRemoteServer());
3232

33-
$this->assertTrue(is_string($this->driver->getSessionID()));
33+
$this->assertIsString($this->driver->getSessionID());
3434
$this->assertNotEmpty($this->driver->getSessionID());
3535

3636
$returnedCapabilities = $this->driver->getCapabilities();

Diff for: tests/functional/RemoteWebDriverFindElementTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testShouldReturnEmptyArrayIfElementsCannotBeFound()
3434

3535
$elements = $this->driver->findElements(WebDriverBy::cssSelector('not_existing'));
3636

37-
$this->assertTrue(is_array($elements));
37+
$this->assertIsArray($elements);
3838
$this->assertCount(0, $elements);
3939
}
4040

@@ -44,7 +44,7 @@ public function testShouldFindMultipleElements()
4444

4545
$elements = $this->driver->findElements(WebDriverBy::cssSelector('ul > li'));
4646

47-
$this->assertTrue(is_array($elements));
47+
$this->assertIsArray($elements);
4848
$this->assertCount(5, $elements);
4949
$this->assertContainsOnlyInstancesOf(RemoteWebElement::class, $elements);
5050
}

Diff for: tests/functional/RemoteWebDriverTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testShouldGetSessionId()
6262

6363
$sessionId = $this->driver->getSessionID();
6464

65-
$this->assertTrue(is_string($sessionId));
65+
$this->assertIsString($sessionId);
6666
$this->assertNotEmpty($sessionId);
6767
}
6868

@@ -76,7 +76,7 @@ public function testShouldGetAllSessions()
7676

7777
$sessions = RemoteWebDriver::getAllSessions($this->serverUrl, 30000);
7878

79-
$this->assertTrue(is_array($sessions));
79+
$this->assertIsArray($sessions);
8080
$this->assertCount(1, $sessions);
8181

8282
$this->assertArrayHasKey('capabilities', $sessions[0]);
@@ -123,7 +123,7 @@ public function testShouldGetWindowHandles()
123123
$windowHandle = $this->driver->getWindowHandle();
124124
$windowHandles = $this->driver->getWindowHandles();
125125

126-
$this->assertTrue(is_string($windowHandle));
126+
$this->assertIsString($windowHandle);
127127
$this->assertNotEmpty($windowHandle);
128128
$this->assertSame([$windowHandle], $windowHandles);
129129

@@ -318,8 +318,8 @@ public function testShouldGetRemoteEndStatus()
318318
{
319319
$status = $this->driver->getStatus();
320320

321-
$this->assertTrue(is_bool($status->isReady()));
322-
$this->assertTrue(is_array($status->getMeta()));
321+
$this->assertIsBool($status->isReady());
322+
$this->assertIsArray($status->getMeta());
323323

324324
if (getenv('BROWSER_NAME') !== 'safari') {
325325
$this->assertNotEmpty($status->getMessage());

Diff for: tests/functional/RemoteWebElementTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public function testShouldReturnEmptyArrayIfChildElementsCannotBeFound()
453453

454454
$childElements = $element->findElements(WebDriverBy::cssSelector('not_existing'));
455455

456-
$this->assertTrue(is_array($childElements));
456+
$this->assertIsArray($childElements);
457457
$this->assertCount(0, $childElements);
458458
}
459459

@@ -465,7 +465,7 @@ public function testShouldFindMultipleChildElements()
465465
$allElements = $this->driver->findElements(WebDriverBy::cssSelector('li'));
466466
$childElements = $element->findElements(WebDriverBy::cssSelector('li'));
467467

468-
$this->assertTrue(is_array($childElements));
468+
$this->assertIsArray($childElements);
469469
$this->assertCount(5, $allElements); // there should be 5 <li> elements on page
470470
$this->assertCount(3, $childElements); // but we should find only subelements of one <ul>
471471
$this->assertContainsOnlyInstancesOf(RemoteWebElement::class, $childElements);

Diff for: tests/unit/Remote/HttpCommandExecutorTest.php

+21-20
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,32 @@ public function testShouldSendRequestToAssembledUrl(
2929
$shouldResetExpectHeader,
3030
$expectedUrl,
3131
$expectedPostData
32-
) {
33-
$curlSetoptMock = $this->getFunctionMock(__NAMESPACE__, 'curl_setopt');
34-
$curlSetoptMock->expects($this->at(0))
35-
->with($this->anything(), CURLOPT_URL, $expectedUrl);
32+
): void {
33+
$expectedCurlSetOptCalls = [
34+
[$this->anything(), CURLOPT_URL, $expectedUrl],
35+
[$this->anything()],
36+
];
3637

3738
if ($shouldResetExpectHeader) {
38-
$curlSetoptMock->expects($this->at(2))
39-
->with(
40-
$this->anything(),
41-
CURLOPT_HTTPHEADER,
42-
['Content-Type: application/json;charset=UTF-8', 'Accept: application/json', 'Expect:']
43-
);
44-
$curlSetoptMock->expects($this->at(3))
45-
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
39+
$expectedCurlSetOptCalls[] = [
40+
$this->anything(),
41+
CURLOPT_HTTPHEADER,
42+
['Content-Type: application/json;charset=UTF-8', 'Accept: application/json', 'Expect:'],
43+
];
4644
} else {
47-
$curlSetoptMock->expects($this->at(2))
48-
->with(
49-
$this->anything(),
50-
CURLOPT_HTTPHEADER,
51-
['Content-Type: application/json;charset=UTF-8', 'Accept: application/json']
52-
);
53-
$curlSetoptMock->expects($this->at(3))
54-
->with($this->anything(), CURLOPT_POSTFIELDS, $expectedPostData);
45+
$expectedCurlSetOptCalls[] = [
46+
$this->anything(),
47+
CURLOPT_HTTPHEADER,
48+
['Content-Type: application/json;charset=UTF-8', 'Accept: application/json'],
49+
];
5550
}
5651

52+
$expectedCurlSetOptCalls[] = [$this->anything(), CURLOPT_POSTFIELDS, $expectedPostData];
53+
54+
$curlSetoptMock = $this->getFunctionMock(__NAMESPACE__, 'curl_setopt');
55+
$curlSetoptMock->expects($this->exactly(4))
56+
->withConsecutive(...$expectedCurlSetOptCalls);
57+
5758
$curlExecMock = $this->getFunctionMock(__NAMESPACE__, 'curl_exec');
5859
$curlExecMock->expects($this->once())
5960
->willReturn('{}');

Diff for: tests/unit/Support/ScreenshotHelperTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99

1010
class ScreenshotHelperTest extends TestCase
1111
{
12-
public const BLACK_PIXEL = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
12+
public const BLACK_PIXEL =
13+
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=';
1314

1415
public function testShouldSavePageScreenshotToSubdirectoryIfNotExists()
1516
{
1617
$fullFilePath = sys_get_temp_dir() . '/' . uniqid('php-webdriver-', true) . '/screenshot.png';
1718
$directoryPath = dirname($fullFilePath);
18-
$this->assertDirectoryNotExists($directoryPath);
19+
$this->assertDirectoryDoesNotExist($directoryPath);
1920

2021
$executorMock = $this->createMock(RemoteExecuteMethod::class);
2122
$executorMock->expects($this->once())
@@ -53,7 +54,7 @@ public function testShouldSaveElementScreenshotToSubdirectoryIfNotExists()
5354
{
5455
$fullFilePath = sys_get_temp_dir() . '/' . uniqid('php-webdriver-', true) . '/screenshot.png';
5556
$directoryPath = dirname($fullFilePath);
56-
$this->assertDirectoryNotExists($directoryPath);
57+
$this->assertDirectoryDoesNotExist($directoryPath);
5758
$elementId = 'foo-id';
5859

5960
$executorMock = $this->createMock(RemoteExecuteMethod::class);

0 commit comments

Comments
 (0)