Skip to content

Commit 803abb6

Browse files
07souravkundaclaude
andcommitted
LOC-6740: move tests to phpunit 9.6 so CI can actually install and run them
The CI job added in the previous commit went red at dependency install: Composer 2.10 refuses to install phpunit 4.8.* because every 4.8.x release carries published security advisories (PKSA-z3gr-8qht-p93v, PKSA-w57n-mhp6-c9sd). Suppressing advisories via policy.advisories.ignore-id is not an acceptable trade on a security fix, so the test dependency moves forward instead. The `php -l` step DID pass on that run — all five lib/ and tests/ files, including the 145 new lines in LocalBinary.php. - composer.json: phpunit 4.8.* -> ^9.6. require-dev only; the library's own runtime floor stays php >= 5.3.19 and is unaffected. - tests/: PHPUnit_Framework_TestCase -> PHPUnit\Framework\TestCase, setUp/tearDown given the `: void` signature phpunit 9 requires, and assertContains() on strings -> assertStringContainsString() (removed in 9). - tests/LocalTest.php: tagged test_isRunning, test_checkPid and test_multiple_binary `@group network`. All three call Local::start(), which downloads and runs the real binary and needs BROWSERSTACK_ACCESS_KEY, so they can never pass on a credential-less runner. --exclude-group network now excludes them, which is what makes the CI job meaningfully green rather than green-because-skipped. - phpunit.xml: phpunit 9 schema, bootstrap=vendor/autoload.php, and a Test.php suffix on the directory so tests/manual/ is not scanned. - workflow: install git + unzip before Composer. Neither is in the official php image and ext-zip is not built in, so Composer has no way to unpack packages without one of them. Refs LOC-6740 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d0f1b91 commit 803abb6

5 files changed

Lines changed: 49 additions & 27 deletions

File tree

.github/workflows/php.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ jobs:
1313
test:
1414
name: lint + phpunit
1515
runs-on: ubuntu-latest
16-
# phpunit 4.x (pinned in composer.json, and the API both test files use) does
17-
# not run on PHP 8. 7.4 is the newest runtime it supports.
16+
# 7.4 rather than 8.x: lib/ sets properties dynamically, which PHP 8.2
17+
# deprecates, and the library's own floor is php >= 5.3.19. phpunit 9.6
18+
# supports 7.3+.
1819
container: php:7.4-cli
1920
steps:
2021
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
@@ -29,8 +30,11 @@ jobs:
2930
php -l tests/LocalTest.php
3031
php -l tests/LocalBinaryTest.php
3132
33+
# git + unzip are not in the official php image, and Composer needs one of
34+
# them to unpack downloaded packages (ext-zip is not built in either).
3235
- name: Install dependencies
3336
run: |
37+
apt-get update -qq && apt-get install -y -qq --no-install-recommends git unzip >/dev/null
3438
curl -sS https://getcomposer.org/installer | php
3539
php composer.phar install --no-interaction --no-progress
3640

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": ">=5.3.19"
1414
},
1515
"require-dev": {
16-
"phpunit/phpunit": "4.8.*"
16+
"phpunit/phpunit": "^9.6"
1717
},
1818
"suggest": {
1919
"phpdocumentor/phpdocumentor": "2.*"

phpunit.xml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<phpunit>
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true">
26
<testsuites>
37
<testsuite name="local">
4-
<directory>tests</directory>
8+
<directory suffix="Test.php">tests</directory>
59
</testsuite>
610
</testsuites>
711
</phpunit>
8-

tests/LocalBinaryTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ public function call_verify_binary($path) {
2929
}
3030
}
3131

32-
class LocalBinaryTest extends \PHPUnit_Framework_TestCase {
32+
class LocalBinaryTest extends \PHPUnit\Framework\TestCase {
3333

3434
private $binary;
3535
private $dir;
3636

37-
public function setUp() {
37+
protected function setUp(): void {
3838
$this->binary = new TestableLocalBinary();
3939
$this->dir = sys_get_temp_dir() . '/bs-local-binary-test-' . getmypid() . '-' . mt_rand();
4040
mkdir($this->dir, 0777, true);
4141
}
4242

43-
public function tearDown() {
43+
protected function tearDown(): void {
4444
foreach (glob($this->dir . '/*') as $file) {
4545
unlink($file);
4646
}
@@ -72,7 +72,7 @@ public function test_download_rejects_untrusted_certificate() {
7272
$this->assertNotNull($raised, 'download_binary must reject an untrusted certificate');
7373
// cURL error 60 is CURLE_PEER_FAILED_VERIFICATION — pins the failure to
7474
// certificate validation rather than any later check.
75-
$this->assertContains('cURL error 60', $raised->getMessage());
75+
$this->assertStringContainsString('cURL error 60', $raised->getMessage());
7676
$this->assertFalse(file_exists($this->dest_path()), 'no file may be left behind on failure');
7777
}
7878

tests/LocalTest.php

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88

99
require_once __DIR__ . '/../vendor/autoload.php';
1010

11-
class LocalTest extends \PHPUnit_Framework_TestCase {
11+
class LocalTest extends \PHPUnit\Framework\TestCase {
1212

1313
private $bs_local;
1414

15-
public function setUp(){
15+
protected function setUp(): void {
1616
$this->bs_local = new Local();
1717
}
1818

19-
public function tearDown(){
19+
protected function tearDown(): void {
2020
$this->bs_local->stop();
2121
}
2222

2323
public function test_verbose() {
2424
$this->bs_local->add_args('v');
25-
$this->assertContains('-v',$this->bs_local->start_command());
25+
$this->assertStringContainsString('-v',$this->bs_local->start_command());
2626
}
2727

2828
public function test_set_folder() {
2929
$this->bs_local->add_args('f', "/");
30-
$this->assertContains('-f',$this->bs_local->start_command());
31-
$this->assertContains('/',$this->bs_local->start_command());
30+
$this->assertStringContainsString('-f',$this->bs_local->start_command());
31+
$this->assertStringContainsString('/',$this->bs_local->start_command());
3232
}
3333

3434
public function test_enable_force() {
@@ -37,56 +37,61 @@ public function test_enable_force() {
3737

3838
public function test_set_local_identifier() {
3939
$this->bs_local->add_args("localIdentifier", "randomString");
40-
$this->assertContains('-localIdentifier randomString',$this->bs_local->start_command());
40+
$this->assertStringContainsString('-localIdentifier randomString',$this->bs_local->start_command());
4141
}
4242

4343
public function test_enable_only() {
4444
$this->bs_local->add_args("only");
45-
$this->assertContains('-only',$this->bs_local->start_command());
45+
$this->assertStringContainsString('-only',$this->bs_local->start_command());
4646
}
4747

4848
public function test_enable_only_automate() {
4949
$this->bs_local->add_args("onlyAutomate");
50-
$this->assertContains('-onlyAutomate', $this->bs_local->start_command());
50+
$this->assertStringContainsString('-onlyAutomate', $this->bs_local->start_command());
5151
}
5252

5353
public function test_enable_force_local() {
5454
$this->bs_local->add_args("forcelocal");
55-
$this->assertContains('-forcelocal',$this->bs_local->start_command());
55+
$this->assertStringContainsString('-forcelocal',$this->bs_local->start_command());
5656
}
5757

5858
public function test_custom_boolean_argument() {
5959
$this->bs_local->add_args("boolArg1", true);
6060
$this->bs_local->add_args("boolArg2", true);
61-
$this->assertContains('-boolArg1',$this->bs_local->start_command());
62-
$this->assertContains('-boolArg2',$this->bs_local->start_command());
61+
$this->assertStringContainsString('-boolArg1',$this->bs_local->start_command());
62+
$this->assertStringContainsString('-boolArg2',$this->bs_local->start_command());
6363
}
6464

6565
public function test_custom_keyval() {
6666
$this->bs_local->add_args("customKey1", "custom value1");
6767
$this->bs_local->add_args("customKey2", "custom value2");
68-
$this->assertContains('-customKey1 \'custom value1\'',$this->bs_local->start_command());
69-
$this->assertContains('-customKey2 \'custom value2\'',$this->bs_local->start_command());
68+
$this->assertStringContainsString('-customKey1 \'custom value1\'',$this->bs_local->start_command());
69+
$this->assertStringContainsString('-customKey2 \'custom value2\'',$this->bs_local->start_command());
7070
}
7171

7272
public function test_set_proxy() {
7373
$this->bs_local->add_args("proxyHost", "localhost");
7474
$this->bs_local->add_args("proxyPort", 8080);
7575
$this->bs_local->add_args("proxyUser", "user");
7676
$this->bs_local->add_args("proxyPass", "pass");
77-
$this->assertContains('-proxyHost localhost -proxyPort 8080 -proxyUser user -proxyPass pass',$this->bs_local->start_command());
77+
$this->assertStringContainsString('-proxyHost localhost -proxyPort 8080 -proxyUser user -proxyPass pass',$this->bs_local->start_command());
7878
}
7979

8080
public function test_enable_force_proxy() {
8181
$this->bs_local->add_args("-forceproxy");
82-
$this->assertContains('-forceproxy',$this->bs_local->start_command());
82+
$this->assertStringContainsString('-forceproxy',$this->bs_local->start_command());
8383
}
8484

8585
public function test_hosts() {
8686
$this->bs_local->add_args("-hosts", "localhost,8080,0");
87-
$this->assertContains('localhost,8080,0',$this->bs_local->start_command());
87+
$this->assertStringContainsString('localhost,8080,0',$this->bs_local->start_command());
8888
}
8989

90+
/**
91+
* Starts the real binary — needs BROWSERSTACK_ACCESS_KEY and outbound network.
92+
*
93+
* @group network
94+
*/
9095
public function test_isRunning() {
9196
$this->assertFalse($this->bs_local->isRunning());
9297
$this->bs_local->start(array('v' => true));
@@ -97,12 +102,22 @@ public function test_isRunning() {
97102
$this->assertTrue($this->bs_local->isRunning());
98103
}
99104

105+
/**
106+
* Starts the real binary — needs BROWSERSTACK_ACCESS_KEY and outbound network.
107+
*
108+
* @group network
109+
*/
100110
public function test_checkPid() {
101111
$this->assertFalse($this->bs_local->isRunning());
102112
$this->bs_local->start(array('v' => true));
103113
$this->assertTrue($this->bs_local->pid > 0);
104114
}
105115

116+
/**
117+
* Starts the real binary twice — needs BROWSERSTACK_ACCESS_KEY and outbound network.
118+
*
119+
* @group network
120+
*/
106121
public function test_multiple_binary() {
107122
$this->bs_local->start(array('v' => true));
108123
$bs_local_2 = new Local();

0 commit comments

Comments
 (0)