Skip to content

Commit ddca757

Browse files
authored
Run the test suite on PHP 8.1 in CI (#132)
* Run the test suite on PHP 8.1 in CI composer.json allows PHP ^8.1, but the CI matrix started at 8.2 and the suite could not even compile on 8.1: two test files declared a trait constant and a readonly class (both PHP 8.2 syntax) at file level. Move those declarations into autoloaded fixtures, guard the one test that was missing a version check, and add 8.1 to the matrix. The 8.1 job turns off Composer's security blocking, because Pest 2 (the only line that supports 8.1) pins PHPUnit <= 10.5.36, which is blocked for a dev-only advisory. The Security Audit job is unchanged. * Remove dead test file and duplicated docblock - tests/SomeTest.php contained only a commented-out test. - Config::get() carried the same docblock twice.
1 parent 18629ce commit ddca757

8 files changed

Lines changed: 62 additions & 42 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
fail-fast: false
8383
matrix:
8484
os: [ubuntu-latest, windows-latest, macos-latest]
85-
php: ['8.2', '8.3', '8.4', '8.5']
85+
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
8686

8787
steps:
8888
- name: Checkout Code
@@ -99,6 +99,10 @@ jobs:
9999
uses: ramsey/composer-install@v3
100100
with:
101101
dependency-versions: ${{ matrix.php == '8.2' && 'lowest' || 'highest' }}
102+
env:
103+
# Pest 2 is the only line that runs on PHP 8.1 and it pins PHPUnit <= 10.5.36, which Composer
104+
# blocks for a dev-only advisory (CVE-2026-24765). The Security Audit job still runs unfiltered.
105+
COMPOSER_NO_SECURITY_BLOCKING: ${{ matrix.php == '8.1' && '1' || '0' }}
102106

103107
- name: Warm Up TypePHP Cache
104108
run: php bin/typephp cache:warm

‎src/Internal/Util/Config.php‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,6 @@ public static function getProjectRoot(?string $startingDir = null): string
585585
return self::$projectRoot = '.';
586586
}
587587

588-
/**
589-
* Loads and caches global configuration from 'typephp.php', 'composer.json' extra, extensions, and base defaults.
590-
*
591-
* @return array<string, mixed>
592-
*/
593588
/**
594589
* Loads and caches global configuration from 'typephp.php', 'composer.json' extra, extensions, and base defaults.
595590
*
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypePHP\Tests\Fixtures\Readonly;
6+
7+
use TypePHP\Tests\TypeChecking\Boundaries\ReadonlyAdapterInterface;
8+
9+
/**
10+
* Readonly classes need PHP 8.2+, so this lives outside the test file and is only autoloaded there.
11+
*/
12+
readonly class ReadonlyClassWithPromotedProperty
13+
{
14+
/**
15+
* @param iterable<ReadonlyAdapterInterface> $adapters
16+
*/
17+
public function __construct(public iterable $adapters)
18+
{
19+
}
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypePHP\Tests\Fixtures\Types;
6+
7+
class TraitConstContainer
8+
{
9+
/**
10+
* @param array{TraitWithConstant::TRAIT_KEY: positive-int} $payload
11+
*/
12+
public function process(array $payload): bool
13+
{
14+
return true;
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypePHP\Tests\Fixtures\Types;
6+
7+
/**
8+
* Constants in traits need PHP 8.2+, so this lives outside the test file and is only autoloaded there.
9+
*/
10+
trait TraitWithConstant
11+
{
12+
public const TRAIT_KEY = 'trait_action';
13+
}

‎tests/SomeTest.php‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎tests/TypeChecking/ArraysAndShapes/ClassConstKeyShapeTest.php‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,7 @@
44

55
use TypePHP\Tests\Fixtures\Types\ConstKeyContainer;
66
use TypePHP\Tests\Fixtures\Types\MissingConstKeyContainer;
7-
8-
trait TraitWithConstantFixture
9-
{
10-
public const TRAIT_KEY = 'trait_action';
11-
}
12-
13-
class TraitConstContainer
14-
{
15-
/**
16-
* @param array{TraitWithConstantFixture::TRAIT_KEY: positive-int} $payload
17-
*/
18-
public function process(array $payload): bool
19-
{
20-
return true;
21-
}
22-
}
7+
use TypePHP\Tests\Fixtures\Types\TraitConstContainer;
238

249
describe('Class Constant Keys in Array Shapes (array{self::CONST_KEY: T})', function () {
2510

‎tests/TypeChecking/Boundaries/PromotedReadonlyPropertyTest.php‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Closure;
88
use TypePHP\Exception\TypeError;
9+
use TypePHP\Tests\Fixtures\Readonly\ReadonlyClassWithPromotedProperty;
910

1011
interface ReadonlyAdapterInterface
1112
{
@@ -39,16 +40,6 @@ public function __construct(public readonly Closure $factory)
3940
}
4041
}
4142

42-
readonly class ReadonlyClassWithPromotedProperty
43-
{
44-
/**
45-
* @param iterable<ReadonlyAdapterInterface> $adapters
46-
*/
47-
public function __construct(public iterable $adapters)
48-
{
49-
}
50-
}
51-
5243
describe('Promoted Readonly Property Contracts', function () {
5344
test('instantiates class with promoted readonly iterable without throwing Cannot modify readonly property error', function () {
5445
$instance = new PromotedReadonlyIterable([new ReadonlyAdapterA()]);
@@ -64,6 +55,12 @@ public function __construct(public iterable $adapters)
6455
});
6556

6657
test('instantiates PHP 8.2 readonly class with promoted property without throwing Cannot modify readonly property error', function () {
58+
if (PHP_VERSION_ID < 80200) {
59+
expect(true)->toBeTrue();
60+
61+
return;
62+
}
63+
6764
$instance = new ReadonlyClassWithPromotedProperty([new ReadonlyAdapterA()]);
6865

6966
expect($instance->adapters)->toHaveCount(1);

0 commit comments

Comments
 (0)