From 08c6597d961b059c7c386c894f095e5c931cea63 Mon Sep 17 00:00:00 2001 From: Till Schiffler Date: Thu, 11 Mar 2021 10:04:08 +0100 Subject: [PATCH] first tests to introduce --- phpunit.xml | 26 +++++++++ tests/DirectoryTest.php | 61 +++++++++++++++++++++ tests/_fixture/deleteableFiles/somefile.txt | 0 tests/bootstrap.php | 4 ++ 4 files changed, 91 insertions(+) create mode 100644 phpunit.xml create mode 100644 tests/DirectoryTest.php create mode 100644 tests/_fixture/deleteableFiles/somefile.txt create mode 100644 tests/bootstrap.php diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..f889773 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,26 @@ + + + + + tests + + + + + + src + + + diff --git a/tests/DirectoryTest.php b/tests/DirectoryTest.php new file mode 100644 index 0000000..a22fc12 --- /dev/null +++ b/tests/DirectoryTest.php @@ -0,0 +1,61 @@ +assertInstanceOf( + Directory::class, + new Directory(__DIR__ . '/_data') + ); + } + + public function testCanBeRetrieved() + { + $directory = new Directory(__DIR__ . '/_data'); + $this->assertEquals(__DIR__ . '/_data', $directory->asString()); + } + + public function testCantBeCreatedOnEmptyArgument() + { + $this->expectException(DirectoryException::class); + new Directory(''); + } + + public function testCantBeCreatedOnNonExistingDirectory() + { + $this->expectException(DirectoryException::class); + new Directory(__DIR__ . '/DirectoryTest.php'); + } + + public function testCanGetIterator() + { + $directory = new Directory(__DIR__ . '/_data'); + $this->assertInstanceOf(\Traversable::class, $directory->getIterator()); + } + + public function testCanClear() + { + $tempDir = __DIR__ . '/_fixture/deleteableFiles'; + + //just to be sure we have a valid fixtuer setup + if (!file_exists($tempDir . '/somefile.txt')) + touch($tempDir . '/somefile.txt'); + $this->assertEquals(1, count(scandir($tempDir)) - 2); + + $directory = new Directory($tempDir); + $directory->clear(); + + $this->assertEquals(0, count(scandir($tempDir)) - 2); + } +} diff --git a/tests/_fixture/deleteableFiles/somefile.txt b/tests/_fixture/deleteableFiles/somefile.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..1ff9219 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,4 @@ +