Skip to content

Commit dd19c1f

Browse files
committed
fix: fragile failing tests
1 parent 2d7c789 commit dd19c1f

File tree

5 files changed

+37
-5
lines changed

5 files changed

+37
-5
lines changed

src/bridge/symfony/postgresql-bundle/tests/Flow/Bridge/Symfony/PostgreSqlBundle/Tests/Context/FilesystemContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public function __construct(string $prefix = 'flow_test_')
1818
{
1919
$this->filesystem = native_local_filesystem();
20-
$this->workDir = path($this->filesystem->getSystemTmpDir()->path() . '/' . $prefix . \bin2hex(\random_bytes(4)));
20+
$this->workDir = path(\dirname(__DIR__, 7) . '/var/tests/' . $prefix . \bin2hex(\random_bytes(4)));
2121
$this->filesystem->writeTo(path($this->workDir->path() . '/.keep'))->append('')->close();
2222
}
2323

src/bridge/symfony/postgresql-bundle/tests/Flow/Bridge/Symfony/PostgreSqlBundle/Tests/Fixtures/TestKernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ public function addTestExtensionConfig(string $extension, array $config) : void
6969
#[\Override]
7070
public function getCacheDir() : string
7171
{
72-
return \sys_get_temp_dir() . '/flow_postgresql_bundle_test/' . $this->environment . '/' . $this->testId . '/cache';
72+
return \dirname(__DIR__, 7) . '/var/tests/kernel/' . $this->environment . '/' . $this->testId . '/cache';
7373
}
7474

7575
#[\Override]
7676
public function getLogDir() : string
7777
{
78-
return \sys_get_temp_dir() . '/flow_postgresql_bundle_test/' . $this->environment . '/' . $this->testId . '/log';
78+
return \dirname(__DIR__, 7) . '/var/tests/kernel/' . $this->environment . '/' . $this->testId . '/log';
7979
}
8080

8181
#[\Override]

src/bridge/symfony/postgresql-bundle/tests/Flow/Bridge/Symfony/PostgreSqlBundle/Tests/Integration/Command/CommandTestContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct()
3131
$this->symfonyContext = new SymfonyContext();
3232
$this->filesystem = native_local_filesystem();
3333
$this->testDsn = \getenv('PGSQL_DATABASE_URL') ?: 'postgresql://postgres:postgres@localhost:5432/postgres';
34-
$this->migrationsDir = \sys_get_temp_dir() . '/flow_test_migrations_' . \bin2hex(\random_bytes(4));
34+
$this->migrationsDir = \dirname(__DIR__, 8) . '/var/tests/flow_test_migrations_' . \bin2hex(\random_bytes(4));
3535
\mkdir($this->migrationsDir, 0755, true);
3636

3737
$client = PgSqlClient::connect((new DsnParser())->parse($this->testDsn));

src/lib/filesystem/src/Flow/Filesystem/Local/NativeLocalFilesystem.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ public function status(Path $path) : ?FileStatus
140140
{
141141
$this->protocol()->validateScheme($path);
142142

143-
if (!$path->isPattern() && \file_exists($path->path())) {
143+
if (!$path->isPattern()) {
144+
if (!\file_exists($path->path())) {
145+
return null;
146+
}
147+
144148
return new FileStatus(
145149
$path,
146150
\is_file($path->path())

src/lib/filesystem/tests/Flow/Filesystem/Tests/Integration/OS/Unix/NativeLocalFilesystemTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,34 @@ public function test_file_status_on_pattern_unix_uri_format() : void
4747
$fs->rm(path(__DIR__ . '/../var/some_path_to'));
4848
}
4949

50+
public function test_status_on_non_existent_path_does_not_walk_parent_directory() : void
51+
{
52+
if (!\function_exists('chmod')) {
53+
self::markTestSkipped('chmod functionality not available');
54+
}
55+
56+
if (\function_exists('posix_geteuid') && \posix_geteuid() === 0) {
57+
self::markTestSkipped('Cannot test permission restrictions as root');
58+
}
59+
60+
$parent = \sys_get_temp_dir() . '/flow_status_regression_' . \bin2hex(\random_bytes(4));
61+
$unreadable = $parent . '/unreadable_sibling';
62+
63+
\mkdir($parent, 0755, true);
64+
\mkdir($unreadable, 0755);
65+
\chmod($unreadable, 0000);
66+
67+
try {
68+
$status = native_local_filesystem()->status(path($parent . '/does_not_exist'));
69+
70+
self::assertNull($status);
71+
} finally {
72+
\chmod($unreadable, 0755);
73+
\rmdir($unreadable);
74+
\rmdir($parent);
75+
}
76+
}
77+
5078
public function test_tmp_dir_unix_uri_format() : void
5179
{
5280
$fs = native_local_filesystem();

0 commit comments

Comments
 (0)