From 509d642982c29f50a70a9ffa5aae4c77a880466e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 11 Jan 2022 10:59:57 +0100 Subject: [PATCH] tests: Introduce `TemporaryLocalFileStorageTest` refs #4630 --- .../Storage/TemporaryLocalFileStorageTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 test/php/library/Icinga/File/Storage/TemporaryLocalFileStorageTest.php diff --git a/test/php/library/Icinga/File/Storage/TemporaryLocalFileStorageTest.php b/test/php/library/Icinga/File/Storage/TemporaryLocalFileStorageTest.php new file mode 100644 index 000000000..f7ca0f45f --- /dev/null +++ b/test/php/library/Icinga/File/Storage/TemporaryLocalFileStorageTest.php @@ -0,0 +1,51 @@ +create('foo', 'bar'); + $storage->create('bar', 'foo'); + + $fooPath = $storage->resolvePath('foo'); + $barPath = $storage->resolvePath('bar'); + + $storage = null; + + $this->assertFileNotExists($fooPath); + $this->assertFileNotExists($barPath); + } + + public function testDestructorRemovesDirectories() + { + $storage = new TemporaryLocalFileStorage(); + $storage->create('foo/bar', 'raboof'); + + $dirPath = dirname($storage->resolvePath('foo/bar')); + + $storage = null; + + $this->assertDirectoryNotExists($dirPath); + } + + public function testDestructorRemovesNestedDirectories() + { + $storage = new TemporaryLocalFileStorage(); + $storage->create('a/b/c/fileA', 'foo'); + $storage->create('a/b/d/fileB', 'bar'); + $storage->create('a/e/f/g/h/fileC', 'raboof'); + + $aPath = dirname($storage->resolvePath('a/b/c/fileA'), 3); + + $storage = null; + + $this->assertDirectoryNotExists($aPath); + } +}