Skip to content

Commit

Permalink
TASK: Support for nested directory structures in the test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-nitsche committed Apr 20, 2023
1 parent 4612f8e commit c3eb900
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
31 changes: 23 additions & 8 deletions tests/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,38 @@ protected function getTestDirectory(): string
protected function removeTestDirectory(): void
{
if (is_dir($this->getTestDirectory())) {
$files = glob($this->getTestDirectory() . '/*');
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->getTestDirectory(), \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($iterator as $path) {
if ($path->isDir() && !$path->isLink()) {
rmdir($path->getPathname());
} else {
unlink($path->getPathname());
}
}
rmdir($this->getTestDirectory());
}
}

protected function addFileToTestDirectory(string $filename, string $content): void
protected function createDirectoryInTestDirectory(string $path): void
{
file_put_contents($this->getPathOfTestDirectoryFile($filename), $content);
mkdir($this->getPathInTestDirectory($path), 0777, true);
}

protected function getPathOfTestDirectoryFile(string $filename): string
protected function createFileInTestDirectory(string $path, string $content): void
{
return $this->getTestDirectory() . '/' . $filename;
file_put_contents($this->getPathInTestDirectory($path), $content);
}

protected function getPathInTestDirectory(string $path): string
{
return $this->getTestDirectory() . '/' . $path;
}

protected function getPathInTestDirectoryAsUrl(string $path): string
{
return 'file://' . $this->getPathInTestDirectory($path);
}
}
2 changes: 1 addition & 1 deletion tests/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function testEndToEnd(string $slackMessageStructure, array $expected): vo
$this->markTestSkipped(sprintf('Restrict end-to-end test to %s Slack message structure.', $filterSlackMessageStructure));
}

$lastExecutionFilename = $this->getPathOfTestDirectoryFile('last_execution.txt');
$lastExecutionFilename = $this->getPathInTestDirectory('last_execution.txt');
$this->assertFileDoesNotExist($lastExecutionFilename);

$connector = new Connector();
Expand Down

0 comments on commit c3eb900

Please sign in to comment.