Browse Source

add tests for isDir method

olinox14 1 year ago
parent
commit
cff37fcdf0
2 changed files with 27 additions and 1 deletions
  1. 1 1
      src/Path.php
  2. 26 0
      tests/PathTest.php

+ 1 - 1
src/Path.php

@@ -166,7 +166,7 @@ class Path
      *
      * @return bool Returns true if the path is a directory, false otherwise.
      */
-    public function isDir()
+    public function isDir(): bool
     {
         return is_dir($this->path);
     }

+ 26 - 0
tests/PathTest.php

@@ -294,4 +294,30 @@ class PathTest extends TestCase
     {
         $this->assertFalse((new Path('foo'))->isFile());
     }
+
+    public function testIsFileOnExistentDir(): void
+    {
+        mkdir(self::TEMP_TEST_DIR . "/some_dir");
+
+        $this->assertFalse((new Path('some_dir'))->isFile());
+    }
+
+    public function testIsDirOnActualDir(): void
+    {
+        mkdir(self::TEMP_TEST_DIR . "/some_dir");
+
+        $this->assertTrue((new Path('some_dir'))->isDir());
+    }
+
+    public function testIsDirOnExistentFile(): void
+    {
+        touch(self::TEMP_TEST_DIR . "/foo");
+
+        $this->assertFalse((new Path('some_dir'))->isDir());
+    }
+
+    public function testIsDirOnNonExistentDir(): void
+    {
+        $this->assertFalse((new Path('some_dir'))->isDir());
+    }
 }