Skip to content

Commit 4dba80c

Browse files
ondrejmirtesclaude
andcommitted
Fix two tests that depended on the platform and on the test order
DirectoryResultCacheValueExtensionTest built the key from __DIR__ . '/data', which a round trip through the result cache turns into backslashes on Windows. ValueDependencyCollector normalizes the directory before it creates the key, so the test now does that too. ValueDependencyCollectorTest counted all calls of the extension, which the container shares with the other tests in the class. It now counts the calls the test itself makes. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdwtgiEHwkF5BTz73jgHQQ
1 parent b46ef8c commit 4dba80c

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎tests/PHPStan/Analyser/ResultCache/DirectoryResultCacheValueExtensionTest.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PHPStan\Analyser\ResultCache;
44

5+
use PHPStan\File\FileHelper;
56
use PHPStan\Testing\PHPStanTestCase;
67
use function file_put_contents;
78
use function mkdir;
@@ -53,7 +54,9 @@ public function testValueFollowsTheMatchingFiles(): void
5354
public function testKeyIsStoredRelative(): void
5455
{
5556
$extension = self::getContainer()->getByType(DirectoryResultCacheValueExtension::class);
56-
$key = DirectoryResultCacheValueExtension::createKey(__DIR__ . '/data', '*.php');
57+
// the directory normalized like ValueDependencyCollector does it - with backslashes on Windows
58+
$directory = self::getContainer()->getByType(FileHelper::class)->normalizePath(__DIR__ . '/data');
59+
$key = DirectoryResultCacheValueExtension::createKey($directory, '*.php');
5760

5861
$this->assertSame($key, $extension->keyFromResultCache($extension->keyToResultCache($key)));
5962
}

‎tests/PHPStan/Analyser/ValueDependencyCollectorTest.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public function testDedupAndDependents(): void
1818
{
1919
$collector = self::getContainer()->getByType(ValueDependencyCollector::class);
2020
$extension = self::getContainer()->getByType(TestValueExtension::class);
21+
// the container is shared with the other tests, which ask the extension too
22+
$callsBefore = $extension->calls;
2123
$scopeFactory = self::getContainer()->getByType(ScopeFactory::class);
2224
$analysedFileScope = $scopeFactory->create(ScopeContext::create('/project/src/Analysed.php'));
2325
$otherFileScope = $scopeFactory->create(ScopeContext::create('/project/src/Other.php'));
@@ -46,7 +48,7 @@ public function testDedupAndDependents(): void
4648
],
4749
],
4850
], $collector->finishFile());
49-
$this->assertSame(2, $extension->calls);
51+
$this->assertSame($callsBefore + 2, $extension->calls);
5052
}
5153

5254
public function testFile(): void

0 commit comments

Comments
 (0)