Skip to content

Commit ff32f40

Browse files
committed
fix tests
1 parent 3cda6cd commit ff32f40

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

Specs/PathResolver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ private function getSharedArtifactDirectory(string $sharedSubdirectory): ?string
9898
return null;
9999
}
100100

101-
if (!is_dir($sharedBasePath) || !is_writable($sharedBasePath)) {
101+
if (!$this->isUsableSharedBasePath($sharedBasePath)) {
102102
return null;
103103
}
104104

105105
return rtrim($sharedBasePath, '/\\') . self::SHARED_BASE_SUBDIRECTORY . ltrim(substr($sharedSubdirectory, strlen(self::SHARED_BASE_SUBDIRECTORY)), '/\\');
106106
}
107107

108+
protected function isUsableSharedBasePath(string $sharedBasePath): bool
109+
{
110+
return is_dir($sharedBasePath) && is_writable($sharedBasePath);
111+
}
112+
108113
private function getStaticContainer(): ?Container
109114
{
110115
try {

tests/Unit/Specs/PathResolverTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testReturnsPluginLocalPathsWhenCloudIsDisabled(): void
3535

3636
public function testReturnsSharedPathsWhenCloudIsEnabledAndDistributedCachePathExists(): void
3737
{
38-
$resolver = new PathResolver('/plugins/OpenApiDocs', true, $this->buildContainerStub(true, '/cache/distributed'));
38+
$resolver = $this->buildPathResolverWithSharedPathValidationResult(true, '/cache/distributed', true);
3939

4040
$this->assertSame('/cache/distributed/OpenApiDocs/specs/', $resolver->getSpecDirectory());
4141
$this->assertSame('/cache/distributed/OpenApiDocs/annotations/', $resolver->getAnnotationsDirectory());
@@ -62,7 +62,7 @@ public function testFallsBackToPluginLocalPathsWhenCloudCachePathIsEmpty(): void
6262

6363
public function testBuildsFilePathsUsingExpectedNamingConventions(): void
6464
{
65-
$resolver = new PathResolver('/plugins/OpenApiDocs', true, $this->buildContainerStub(true, '/cache/distributed/'));
65+
$resolver = $this->buildPathResolverWithSharedPathValidationResult(true, '/cache/distributed/', true);
6666

6767
$this->assertSame(
6868
'/cache/distributed/OpenApiDocs/specs/CustomAlerts_openapi_spec_v2.0.0.yaml',
@@ -101,4 +101,21 @@ private function buildContainerStub(bool $hasDistributedCachePath, string $distr
101101

102102
return $container;
103103
}
104+
105+
private function buildPathResolverWithSharedPathValidationResult(
106+
bool $hasDistributedCachePath,
107+
string $distributedCachePath,
108+
bool $isUsableSharedBasePath
109+
): PathResolver {
110+
$resolver = $this->getMockBuilder(PathResolver::class)
111+
->setConstructorArgs(['/plugins/OpenApiDocs', true, $this->buildContainerStub($hasDistributedCachePath, $distributedCachePath)])
112+
->onlyMethods(['isUsableSharedBasePath'])
113+
->getMock();
114+
115+
$resolver->method('isUsableSharedBasePath')
116+
->with(trim($distributedCachePath))
117+
->willReturn($isUsableSharedBasePath);
118+
119+
return $resolver;
120+
}
104121
}

0 commit comments

Comments
 (0)