Skip to content

Commit 9095770

Browse files
authored
Merge pull request #215 from php-school/fix-fs-stuff
Only delete or create stuff if exists or doesn't exist already
2 parents 310b422 + 468954b commit 9095770

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/Check/DatabaseCheck.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,17 @@ function (CliExecuteEvent $e) {
138138
],
139139
function () use ($db) {
140140
unset($db);
141-
@unlink($this->userDatabasePath);
142-
@unlink($this->solutionDatabasePath);
141+
$this->unlink($this->userDatabasePath);
142+
$this->unlink($this->solutionDatabasePath);
143143
rmdir($this->databaseDirectory);
144144
}
145145
);
146146
}
147+
148+
private function unlink(string $file): void
149+
{
150+
if (file_exists($file)) {
151+
unlink($file);
152+
}
153+
}
147154
}

test/BaseTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public function getTemporaryFile(string $filename, string $content = null): stri
3131
return $file;
3232
}
3333

34-
@mkdir(dirname($file), 0777, true);
34+
if (!file_exists(dirname($file))) {
35+
mkdir(dirname($file), 0777, true);
36+
}
3537

3638
$content !== null
3739
? file_put_contents($file, $content)

test/Check/DatabaseCheckTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private function getRunnerManager(ExerciseInterface $exercise, EventDispatcher $
8989
public function testIfDatabaseFolderExistsExceptionIsThrown(): void
9090
{
9191
$eventDispatcher = new EventDispatcher(new ResultAggregator());
92-
@mkdir($this->dbDir);
92+
mkdir($this->dbDir, 0777, true);
9393
try {
9494
$this->check->attach($eventDispatcher);
9595
$this->fail('Exception was not thrown');

0 commit comments

Comments
 (0)