Skip to content

Commit 42b86b7

Browse files
Merge branch '9.6' into 10.5
* 9.6: Move check whether PHAR was successfully scoped from CI pipeline configuration to build automation
2 parents c47fe00 + e563695 commit 42b86b7

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,6 @@ jobs:
409409
- name: Build PHAR
410410
run: ant phar-snapshot
411411

412-
- name: Check whether PHAR is scoped
413-
run: grep -q PHPUnitPHAR\\\\DeepCopy\\\\Exception\\\\CloneException build/artifacts/phpunit-snapshot.phar || (echo "phpunit-snapshot.phar is not scoped." && false)
414-
415412
- name: Upload PHAR
416413
uses: actions/upload-artifact@v4
417414
with:

build.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@
370370
<arg path="${basedir}/build/artifacts/phpunit-library-${_version}.phar" />
371371
</exec>
372372

373+
<exec executable="${basedir}/build/scripts/check-scoped-phar.php" taskname="check-scoped-phar" failonerror="true">
374+
<arg path="${basedir}/build/artifacts/phpunit-library-${_version}.phar" />
375+
</exec>
376+
373377
<copy file="${basedir}/build/templates/binary-phar-autoload.php.in" tofile="${basedir}/build/tmp/binary-phar-autoload.php"/>
374378
<replace file="${basedir}/build/tmp/binary-phar-autoload.php" token="X.Y.Z" value="${_version}"/>
375379

@@ -393,6 +397,10 @@
393397

394398
<chmod file="${basedir}/build/artifacts/phpunit-${_version}.phar" perm="ugo+rx"/>
395399

400+
<exec executable="${basedir}/build/scripts/check-scoped-phar.php" taskname="check-scoped-phar" failonerror="true">
401+
<arg path="${basedir}/build/artifacts/phpunit-${_version}.phar" />
402+
</exec>
403+
396404
<delete dir="${basedir}/build/tmp"/>
397405
</target>
398406

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env php
2+
<?php declare(strict_types=1);
3+
4+
/*
5+
* This file is part of PHPUnit.
6+
*
7+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
if (!isset($argv[1]) || !\file_exists($argv[1])) {
13+
\fwrite(
14+
\STDERR,
15+
\sprintf(
16+
'%s /path/to/phpunit-*.phar' . \PHP_EOL,
17+
$argv[0]
18+
)
19+
);
20+
21+
exit(1);
22+
}
23+
24+
if (!str_contains_between(\file_get_contents($argv[1]), 'PHPUnitPHAR', '$classes = [', '];') &&
25+
!str_contains_between(\file_get_contents($argv[1]), 'phpunitphar', '$classes = [', '];')) {
26+
\fwrite(\STDERR, 'PHAR is not scoped' . \PHP_EOL);
27+
28+
exit(1);
29+
}
30+
31+
\fwrite(\STDOUT, 'PHAR is scoped' . \PHP_EOL);
32+
33+
/**
34+
* @param non-empty-string $haystack
35+
* @param non-empty-string $needle
36+
* @param non-empty-string $start
37+
* @param non-empty-string $end
38+
*/
39+
function str_contains_between(string $haystack, string $needle, string $start, string $end): bool
40+
{
41+
$startLen = \strlen($start);
42+
$needleLen = \strlen($needle);
43+
$offset = 0;
44+
45+
while (($sPos = \strpos($haystack, $start, $offset)) !== false) {
46+
$afterStart = $sPos + $startLen;
47+
$ePos = \strpos($haystack, $end, $afterStart);
48+
49+
if ($ePos === false) {
50+
break;
51+
}
52+
53+
$nPos = \strpos($haystack, $needle, $afterStart);
54+
55+
if ($nPos !== false && $nPos + $needleLen <= $ePos) {
56+
return true;
57+
}
58+
59+
$offset = $sPos + 1;
60+
}
61+
62+
return false;
63+
}

0 commit comments

Comments
 (0)