Browse Source

added Path::__toString()

Fabian Peter Hammerle 7 years ago
parent
commit
966ebb9d30
2 changed files with 23 additions and 0 deletions
  1. 11 0
      Path.php
  2. 12 0
      tests/PathTest.php

+ 11 - 0
Path.php

@@ -19,11 +19,22 @@ class Path
      */
     protected $_extension;
 
+    /**
+     * @param string|null $path
+     */
     public function __construct($path = null)
     {
         $this->setPath($path);
     }
 
+    /**
+     * @return string
+     */
+    public function __toString()
+    {
+        return $this->path ?: '';
+    }
+
     /**
      * @return string|null
      */

+ 12 - 0
tests/PathTest.php

@@ -21,6 +21,18 @@ class PathTest extends \PHPUnit_Framework_TestCase
         $this->assertSame($expected_extension, $p->extension);
     }
 
+    /**
+     * @dataProvider pathProvider
+     */
+    public function testToString($expected_path, $dir_path, $filename, $extension)
+    {
+        $p = new Path;
+        $p->dirPath = $dir_path;
+        $p->filename = $filename;
+        $p->extension = $extension;
+        $this->assertSame($expected_path ?: '', (string)$p);
+    }
+
     public function getBasenameProvider()
     {
         return [