Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Filesystem] introduced new Exception base classes
- Loading branch information
1 parent
9f35ca5
commit 785080a
Showing
5 changed files
with
204 additions
and
36 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/Symfony/Component/Filesystem/Exception/FileNotFoundException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Filesystem\Exception; | ||
|
||
/** | ||
* Exception class thrown when a file couldn't be found | ||
* | ||
* @author Christian Gärtner <christiangaertner.film@googlemail.com> | ||
*/ | ||
class FileNotFoundException extends IOException | ||
{ | ||
public function __construct($path, $message = null, $code = 0, \Exception $previous = null) | ||
{ | ||
if ($message === null) { | ||
$message = sprintf('File "%s" could not be found', $path); | ||
} | ||
|
||
$this->setPath($path); | ||
|
||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/Symfony/Component/Filesystem/Exception/IOExceptionInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Filesystem\Exception; | ||
|
||
/** | ||
* IOException interface for file and input/output stream releated exceptions thrown by the component. | ||
* | ||
* @author Christian Gärtner <christiangaertner.film@googlemail.com> | ||
*/ | ||
interface IOExceptionInterface extends ExceptionInterface | ||
{ | ||
/** | ||
* Returns the associated path for the exception | ||
* | ||
* @return string The path. | ||
*/ | ||
public function getPath(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Filesystem\Tests; | ||
|
||
use Symfony\Component\Filesystem\Exception\IOException; | ||
use Symfony\Component\Filesystem\Exception\FileNotFoundException; | ||
|
||
/** | ||
* Test class for Filesystem. | ||
*/ | ||
class ExceptionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testSetPath() | ||
{ | ||
$e = new IOException(); | ||
$e->setPath('/foo'); | ||
$reflection = new \ReflectionProperty($e, 'path'); | ||
$reflection->setAccessible(true); | ||
|
||
$this->assertEquals('/foo', $reflection->getValue($e), 'The path should get stored in the "path" property'); | ||
} | ||
|
||
public function testGetPath() | ||
{ | ||
$e = new IOException(); | ||
$e->setPath('/foo'); | ||
$this->assertEquals('/foo', $e->getPath(), 'The pass should be returned.'); | ||
} | ||
|
||
public function testGeneratedMessage() | ||
{ | ||
$e = new FileNotFoundException('/foo'); | ||
$this->assertEquals('/foo', $e->getPath()); | ||
$this->assertEquals('File "/foo" could not be found', $e->getMessage(), 'A message should be generated.'); | ||
} | ||
|
||
public function testCustomMessage() | ||
{ | ||
$e = new FileNotFoundException('/foo', 'bar'); | ||
$this->assertEquals('bar', $e->getMessage(), 'A custom message should be possible still.'); | ||
} | ||
} |