Skip to content

Commit 7285d2b

Browse files
committed
trace failing 8.2 ci test
1 parent 716fad5 commit 7285d2b

4 files changed

Lines changed: 41 additions & 26 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,7 @@ jobs:
4646
run: php bin/typephp cache:warm
4747

4848
- name: Run Runtime Type Checking Engine Suite (Pest)
49-
run: ./vendor/bin/pest tests/TypeChecking --compact
50-
51-
- name: Run Full Test Suite with Coverage (Pest)
52-
run: ./vendor/bin/pest --coverage-clover=clover.xml --compact
53-
if: matrix.os == 'ubuntu-latest' && matrix.php == '8.4'
54-
55-
- name: Run Full Test Suite (Pest)
56-
run: ./vendor/bin/pest --compact
57-
if: "! (matrix.os == 'ubuntu-latest' && matrix.php == '8.4')"
49+
run: ./vendor/bin/pest tests/TypeChecking/ArraysAndShapes/ClassConstKeyShapeTest.php tests/TypeChecking/ArraysAndShapes/OffsetAccessTest.php --verbose
5850

5951
- name: Upload Coverage to Codecov
6052
uses: codecov/codecov-action@v5

src/Internal/Checker/ParamChecker.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ public static function checkParams(
7474

7575
$contract = DocblockParser::parse($effectiveFunction);
7676

77+
if (str_contains($effectiveFunction, 'ConstKeyContainer') || str_contains($effectiveFunction, 'OffsetAccessContainer')) {
78+
fwrite(STDERR, "[PARAM_CHECKER] $effectiveFunction\n");
79+
fwrite(STDERR, " - hasParamContract: " . ($contract['hasParamContract'] ? 'true' : 'false') . "\n");
80+
fwrite(STDERR, " - types count: " . count($contract['types']) . "\n");
81+
foreach ($contract['types'] as $pName => $tNode) {
82+
fwrite(STDERR, " - param '$pName' AST class: " . get_class($tNode) . " => (string): " . (string) $tNode . "\n");
83+
}
84+
}
85+
7786
if (! $contract['hasParamContract']) {
7887
return null;
7988
}
@@ -87,8 +96,8 @@ public static function checkParams(
8796
foreach ($contract['types'] as $paramName => $typeNode) {
8897
if (\array_key_exists($paramName, $vars)) {
8998
$err = $registry->validate($vars[$paramName], $typeNode, $effectiveFunction . '(): Argument $' . $paramName);
90-
if ($err !== null) {
91-
return $err;
99+
if (str_contains($effectiveFunction, 'ConstKeyContainer') || str_contains($effectiveFunction, 'OffsetAccessContainer')) {
100+
fwrite(STDERR, " - validate result: " . ($err ? 'ERROR: ' . $err->getMessage() : 'NULL (PASSED)') . "\n");
92101
}
93102
}
94103
}

src/Internal/Io/StreamWrapper.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ public function stream_open(string $path, string $mode, int $options, ?string &$
301301
{
302302
$isInclude = ($options & self::STREAM_OPEN_FOR_INCLUDE) !== 0;
303303

304-
if (! $isInclude || ($mode !== 'r' && $mode !== 'rb' && $mode !== 'rt') || ! str_ends_with(strtolower($path), '.php') || ! Config::isEnabled()) {
305-
return $this->openDirectHandle($path, $mode, $options);
304+
if (str_contains($path, 'ConstKeyContainer') || str_contains($path, 'OffsetAccessContainer')) {
305+
fwrite(STDERR, "[STREAM_OPEN] path: $path, isInclude: " . ($isInclude ? 'yes' : 'no') . ", isEnabled: " . (Config::isEnabled() ? 'yes' : 'no') . "\n");
306306
}
307307

308308
$normalizedRaw = str_replace('\\', '/', $path);
@@ -316,14 +316,14 @@ public function stream_open(string $path, string $mode, int $options, ?string &$
316316

317317
self::unregister();
318318

319-
$exists = (bool) self::silent(static fn () => file_exists($path));
320-
$resolvedPath = $exists ? self::silent(static fn () => realpath($path)) : false;
319+
$exists = (bool) self::silent(static fn() => file_exists($path));
320+
$resolvedPath = $exists ? self::silent(static fn() => realpath($path)) : false;
321321

322322
if (! $exists || $resolvedPath === false || ! self::isApplicationFile($path, $resolvedPath)) {
323323
$target = ($resolvedPath !== false) ? $resolvedPath : $path;
324324
/** @var resource|false $handle */
325325
$handle = self::silent(
326-
fn () => ($this->context !== null)
326+
fn() => ($this->context !== null)
327327
? fopen($target, $mode, false, $this->context)
328328
: fopen($target, $mode)
329329
);
@@ -367,7 +367,7 @@ private function openDirectHandle(string $targetFile, string $mode, int $options
367367
self::unregister();
368368
/** @var resource|false $handle */
369369
$handle = self::silent(
370-
fn () => ($this->context !== null)
370+
fn() => ($this->context !== null)
371371
? fopen($targetFile, $mode, $useIncludePath, $this->context)
372372
: fopen($targetFile, $mode, $useIncludePath)
373373
);
@@ -522,7 +522,7 @@ public function url_stat(string $path, int $flags): array|false
522522

523523
self::unregister();
524524
/** @var array<int|string, int>|false $result */
525-
$result = self::silent(static fn () => $isLink ? @lstat($path) : @stat($path));
525+
$result = self::silent(static fn() => $isLink ? @lstat($path) : @stat($path));
526526
self::register();
527527

528528
if ($result !== false) {
@@ -559,11 +559,11 @@ public function stream_metadata(string $path, int $option, mixed $value): bool
559559
$valueArray = \is_array($value) ? $value : [];
560560
$time = $valueArray[0] ?? time();
561561
$atime = $valueArray[1] ?? $time;
562-
$result = (bool) self::silent(fn () => @touch($path, (int) $time, (int) $atime));
562+
$result = (bool) self::silent(fn() => @touch($path, (int) $time, (int) $atime));
563563
} elseif ($option === STREAM_META_ACCESS) {
564564
/** @var int $mode */
565565
$mode = \is_int($value) ? $value : 0777;
566-
$result = (bool) self::silent(fn () => @chmod($path, $mode));
566+
$result = (bool) self::silent(fn() => @chmod($path, $mode));
567567
}
568568
self::register();
569569

@@ -575,7 +575,7 @@ public function dir_opendir(string $path, int $options): bool
575575
self::unregister();
576576
/** @var resource|false $dh */
577577
$dh = self::silent(
578-
fn () => ($this->context !== null)
578+
fn() => ($this->context !== null)
579579
? @opendir($path, $this->context)
580580
: @opendir($path)
581581
);
@@ -702,7 +702,7 @@ public function rename(string $pathFrom, string $pathTo): bool
702702
*/
703703
private static function silent(callable $callback): mixed
704704
{
705-
set_error_handler(static fn () => true);
705+
set_error_handler(static fn() => true);
706706

707707
try {
708708
return $callback();
@@ -754,6 +754,10 @@ private static function isApplicationFile(string $path, string|false $resolvedPa
754754
*/
755755
private function openMemoryStream(string $resolvedPath): bool
756756
{
757+
if (str_contains($resolvedPath, 'ConstKeyContainer') || str_contains($resolvedPath, 'OffsetAccessContainer')) {
758+
fwrite(STDERR, "[TRANSFORM] Transforming $resolvedPath\n");
759+
}
760+
757761
$source = file_get_contents($resolvedPath);
758762
if ($source === false) {
759763
return false;
@@ -776,6 +780,10 @@ private function openMemoryStream(string $resolvedPath): bool
776780
*/
777781
private function openCachedStream(string $resolvedPath, string $mode): bool
778782
{
783+
if (str_contains($resolvedPath, 'ConstKeyContainer') || str_contains($resolvedPath, 'OffsetAccessContainer')) {
784+
fwrite(STDERR, "[TRANSFORM] Transforming $resolvedPath\n");
785+
}
786+
779787
$cachedFile = CacheManager::getCachedFilePath($resolvedPath);
780788

781789
if (! CacheManager::ensureSecureCacheDir()) {

tests/TypeChecking/ArraysAndShapes/ClassConstKeyShapeTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,14 @@ public function process(array $payload): bool
3535
test('throws TypeError when array shape item with class constant key violates type contract', function () {
3636
$container = new ConstKeyContainer();
3737

38-
expect(fn () => $container->process([
38+
fwrite(STDERR, "[TEST_START] Calling process() with invalid user_id = -5\n");
39+
$result = $container->process([
40+
'user_id' => -5,
41+
'user_role' => 'admin',
42+
]);
43+
fwrite(STDERR, "[TEST_END] process() returned without throwing! Return: " . var_export($result, true) . "\n");
44+
45+
expect(fn() => $container->process([
3946
'user_id' => -5,
4047
'user_role' => 'admin',
4148
]))->toThrow(TypeError::class, "['user_id'] must be of type positive-int");
@@ -44,9 +51,8 @@ public function process(array $payload): bool
4451
test('throws TypeError when array shape references a non-existent class constant key', function () {
4552
$container = new MissingConstKeyContainer();
4653

47-
expect(fn () => $container->process(['user_id' => 42]))
48-
->toThrow(TypeError::class, "is missing required key 'self::NON_EXISTENT_KEY'")
49-
;
54+
expect(fn() => $container->process(['user_id' => 42]))
55+
->toThrow(TypeError::class, "is missing required key 'self::NON_EXISTENT_KEY'");
5056
});
5157

5258
test('resolves PHP 8.2+ trait constants inside array shapes', function () {

0 commit comments

Comments
 (0)