Skip to content

Commit 7525e85

Browse files
committed
Merge pull request #619 from LearningLocker/issue/teardown
Deletes attachments after testing.
2 parents 6e44f88 + f1c465e commit 7525e85

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

app/tests/routes/StatementAttachmentTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Tests\Routes;
22
use \Tests\StatementsTestCase as StatementsTestCase;
3+
use \Locker\Helpers\Helpers as Helpers;
34

45
class StatementAttachmentTest extends StatementsTestCase {
56
use RouteTestTrait;
@@ -104,8 +105,23 @@ public function testIndexAttachments() {
104105
$this->assertEquals($actual_hash, $expected_hash);
105106
}
106107

108+
private function deleteDirectory($dir) {
109+
array_map(function ($file) {
110+
if (is_dir($file)) {
111+
$this->deleteDirectory($file);
112+
} else {
113+
unlink($file);
114+
}
115+
}, glob($dir . '*', GLOB_MARK));
116+
if (is_dir($dir)) {
117+
rmdir($dir);
118+
}
119+
}
120+
107121
public function tearDown() {
108122
parent::tearDown();
123+
$dir = Helpers::getEnvVar('LOCAL_FILESTORE').'/'.$this->lrs->_id;
124+
$this->deleteDirectory($dir);
109125
(new \Statement)
110126
->where('lrs._id', $this->lrs->_id)
111127
->delete();

0 commit comments

Comments
 (0)