Skip to content

Commit a0bcdcb

Browse files
committed
Testing multiple target PHP versions via docker
1 parent d83f8a5 commit a0bcdcb

File tree

11 files changed

+522
-226
lines changed

11 files changed

+522
-226
lines changed

.github/workflows/phpunit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: Run test suite
5050
run: |
5151
mkdir -p build/logs
52-
./vendor/bin/phpunit --coverage-clover build/logs/clover.xml
52+
composer test-for-ci
5353
5454
- name: Send to coveralls
5555
env:

Dockerfile-dev

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM php:8.1-cli
2+
3+
RUN apt-get update && apt-get install -y \
4+
libffi-dev \
5+
libzip-dev \
6+
&& docker-php-ext-install ffi \
7+
&& docker-php-ext-install pcntl \
8+
&& docker-php-ext-install zip \
9+
&& pecl install pcov \
10+
&& docker-php-ext-enable pcov \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
RUN apt-get update -y \
14+
&& apt-get install -y ca-certificates curl gnupg \
15+
&& install -m 0755 -d /etc/apt/keyrings \
16+
&& curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \
17+
&& chmod a+r /etc/apt/keyrings/docker.gpg \
18+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(. /etc/os-release && echo $VERSION_CODENAME) stable" \
19+
| tee /etc/apt/sources.list.d/docker.list > /dev/null \
20+
&& apt-get update -y \
21+
&& apt-get install -y docker-ce-cli \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
COPY --from=composer /usr/bin/composer /usr/bin/composer
25+
26+
WORKDIR /app
27+
COPY . .
28+
29+
RUN composer install
30+
31+
CMD ["php", "vendor/bin/phpunit", "--colors=always", "--testdox", "--coverage-text", "--coverage-clover=coverage.xml", "--coverage-html=coverage"]

composer.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,22 @@
4848
},
4949
"autoload-dev": {
5050
"psr-4": {
51-
"Reli\\": "tests"
51+
"Reli\\": "tests",
52+
"Reli\\Command\\": "tests/Command/CommandEnumeratorTestData"
5253
}
5354
},
5455
"bin": [
5556
"reli"
5657
],
5758
"scripts": {
5859
"test": [
59-
"phpunit"
60+
"docker-compose run reli-test"
61+
],
62+
"test-with-coverage": [
63+
"docker-compose run reli-test-with-coverage"
64+
],
65+
"test-for-ci": [
66+
"docker-compose run reli-test-for-ci"
6067
],
6168
"psalm": [
6269
"psalm.phar"

docker-compose.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
version: '3.9'
2+
services:
3+
reli-test:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile-dev
7+
pid: "host"
8+
cap_add:
9+
- SYS_PTRACE
10+
security_opt:
11+
- seccomp:unconfined
12+
volumes:
13+
- .:/app
14+
- /var/run/docker.sock:/var/run/docker.sock
15+
- /tmp/reli-test:/tmp/reli-test
16+
container_name: reli-test
17+
command: ["vendor/bin/phpunit" , "--colors=always", "--testdox"]
18+
reli-test-with-coverage:
19+
build:
20+
context: .
21+
dockerfile: Dockerfile-dev
22+
pid: "host"
23+
cap_add:
24+
- SYS_PTRACE
25+
security_opt:
26+
- seccomp:unconfined
27+
volumes:
28+
- .:/app
29+
- /var/run/docker.sock:/var/run/docker.sock
30+
- /tmp/reli-test:/tmp/reli-test
31+
- ./build:/app/build
32+
container_name: reli-test
33+
command: ["vendor/bin/phpunit" , "--colors=always", "--testdox", "--coverage-clover", "build/logs/clover.xml"]
34+
reli-test-for-ci:
35+
build:
36+
context: .
37+
dockerfile: Dockerfile-dev
38+
pid: "host"
39+
cap_add:
40+
- SYS_PTRACE
41+
security_opt:
42+
- seccomp:unconfined
43+
volumes:
44+
- .:/app
45+
- /var/run/docker.sock:/var/run/docker.sock
46+
- /tmp/reli-test:/tmp/reli-test
47+
- ./build:/app/build
48+
container_name: reli-test
49+
command: ["vendor/bin/phpunit" , "--coverage-clover", "build/logs/clover.xml"]

tests/Command/CommandEnumeratorTestData/Test1Directory/Test1Command.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Reli\Command\CommandEnumeratorTestData\Test1Directory;
14+
namespace Reli\Command\Test1Directory;
1515

16-
final class Test1Command
16+
use Symfony\Component\Console\Command\Command;
17+
18+
final class Test1Command extends Command
1719
{
1820
}

tests/Command/CommandEnumeratorTestData/Test1Directory/Test2Command.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Reli\Command\CommandEnumeratorTestData\Test1Directory;
14+
namespace Reli\Command\Test1Directory;
1515

16-
final class Test2Command
16+
use Symfony\Component\Console\Command\Command;
17+
18+
final class Test2Command extends Command
1719
{
1820
}

tests/Command/CommandEnumeratorTestData/Test2Directory/Test3Command.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Reli\Command\CommandEnumeratorTestData\Test2Directory;
14+
namespace Reli\Command\Test2Directory;
1515

16-
final class Test3Command
16+
use Symfony\Component\Console\Command\Command;
17+
18+
final class Test3Command extends Command
1719
{
1820
}

tests/Command/CommandEnumeratorTestData/Test2Directory/Test4Command.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Reli\Command\CommandEnumeratorTestData\Test2Directory;
14+
namespace Reli\Command\Test2Directory;
1515

16-
final class Test4Command
16+
use Symfony\Component\Console\Command\Command;
17+
18+
final class Test4Command extends Command
1719
{
1820
}

tests/Lib/PhpProcessReader/CallTraceReader/CallTraceReaderTest.php

+25-25
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Reli\Lib\PhpProcessReader\CallTraceReader;
1515

16+
use PHPUnit\Framework\Attributes\DataProviderExternal;
1617
use Reli\BaseTestCase;
1718
use Reli\Inspector\Settings\TargetPhpSettings\TargetPhpSettings;
1819
use Reli\Lib\ByteStream\IntegerByteSequence\LittleEndianReader;
@@ -22,13 +23,13 @@
2223
use Reli\Lib\Elf\SymbolResolver\Elf64SymbolResolverCreator;
2324
use Reli\Lib\File\CatFileReader;
2425
use Reli\Lib\PhpInternals\Opcodes\OpcodeFactory;
25-
use Reli\Lib\PhpInternals\ZendTypeReader;
2626
use Reli\Lib\PhpInternals\ZendTypeReaderCreator;
2727
use Reli\Lib\PhpProcessReader\PhpGlobalsFinder;
2828
use Reli\Lib\PhpProcessReader\PhpSymbolReaderCreator;
2929
use Reli\Lib\Process\MemoryMap\ProcessMemoryMapCreator;
3030
use Reli\Lib\Process\MemoryReader\MemoryReader;
3131
use Reli\Lib\Process\ProcessSpecifier;
32+
use Reli\TargetPhpVmProvider;
3233

3334
class CallTraceReaderTest extends BaseTestCase
3435
{
@@ -47,17 +48,16 @@ protected function tearDown(): void
4748
}
4849
}
4950

50-
public function testReadCallTrace()
51+
#[DataProviderExternal(TargetPhpVmProvider::class, 'allSupported')]
52+
public function testReadCallTrace(string $php_version, string $docker_image_name): void
5153
{
5254
$memory_reader = new MemoryReader();
5355
$executor_globals_reader = new CallTraceReader(
5456
$memory_reader,
5557
new ZendTypeReaderCreator(),
5658
new OpcodeFactory()
5759
);
58-
$tmp_file = tempnam(sys_get_temp_dir(), 'reli-prof-test');
59-
file_put_contents(
60-
$tmp_file,
60+
$target_script =
6161
<<<CODE
6262
<?php
6363
class A {
@@ -69,22 +69,18 @@ public function wait() {
6969
fputs(STDOUT, "a\n");
7070
\$object->wait();
7171
CODE
72-
);
73-
$this->child = proc_open(
74-
[
75-
PHP_BINARY,
76-
$tmp_file,
77-
],
78-
[
79-
['pipe', 'r'],
80-
['pipe', 'w'],
81-
['pipe', 'w']
82-
],
72+
;
73+
$pipes = [];
74+
[$this->child, $pid] = TargetPhpVmProvider::runScriptViaContainer(
75+
$docker_image_name,
76+
$target_script,
8377
$pipes
8478
);
8579

86-
fgets($pipes[1]);
80+
$s = fgets($pipes[1]);
81+
$this->assertSame("a\n", $s);
8782
$child_status = proc_get_status($this->child);
83+
$this->assertSame(true, $child_status['running']);
8884
$php_symbol_reader_creator = new PhpSymbolReaderCreator(
8985
$memory_reader,
9086
new ProcessModuleSymbolReaderCreator(
@@ -108,17 +104,21 @@ public function wait() {
108104

109105
/** @var int $child_status['pid'] */
110106
$executor_globals_address = $php_globals_finder->findExecutorGlobals(
111-
new ProcessSpecifier($child_status['pid']),
112-
new TargetPhpSettings()
107+
new ProcessSpecifier($pid),
108+
new TargetPhpSettings(
109+
php_version: $php_version,
110+
)
113111
);
114112
$sapi_globals_address = $php_globals_finder->findSAPIGlobals(
115-
new ProcessSpecifier($child_status['pid']),
116-
new TargetPhpSettings()
113+
new ProcessSpecifier($pid),
114+
new TargetPhpSettings(
115+
php_version: $php_version,
116+
)
117117
);
118118

119119
$call_trace = $executor_globals_reader->readCallTrace(
120-
$child_status['pid'],
121-
ZendTypeReader::V81,
120+
$pid,
121+
$php_version,
122122
$executor_globals_address,
123123
$sapi_globals_address,
124124
PHP_INT_MAX,
@@ -142,7 +142,7 @@ public function wait() {
142142
$call_trace->call_frames[1]->getFullyQualifiedFunctionName()
143143
);
144144
$this->assertSame(
145-
$tmp_file,
145+
'/source',
146146
$call_trace->call_frames[1]->file_name
147147
);
148148
$this->assertSame(
@@ -154,7 +154,7 @@ public function wait() {
154154
$call_trace->call_frames[2]->getFullyQualifiedFunctionName()
155155
);
156156
$this->assertSame(
157-
$tmp_file,
157+
'/source',
158158
$call_trace->call_frames[2]->file_name
159159
);
160160
$this->assertSame(

0 commit comments

Comments
 (0)