ExceptionTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Filesystem\Tests;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Filesystem\Exception\FileNotFoundException;
  13. use Symfony\Component\Filesystem\Exception\IOException;
  14. /**
  15. * Test class for Filesystem.
  16. */
  17. class ExceptionTest extends TestCase
  18. {
  19. public function testGetPath()
  20. {
  21. $e = new IOException('', 0, null, '/foo');
  22. $this->assertEquals('/foo', $e->getPath(), 'The pass should be returned.');
  23. }
  24. public function testGeneratedMessage()
  25. {
  26. $e = new FileNotFoundException(null, 0, null, '/foo');
  27. $this->assertEquals('/foo', $e->getPath());
  28. $this->assertEquals('File "/foo" could not be found.', $e->getMessage(), 'A message should be generated.');
  29. }
  30. public function testGeneratedMessageWithoutPath()
  31. {
  32. $e = new FileNotFoundException();
  33. $this->assertEquals('File could not be found.', $e->getMessage(), 'A message should be generated.');
  34. }
  35. public function testCustomMessage()
  36. {
  37. $e = new FileNotFoundException('bar', 0, null, '/foo');
  38. $this->assertEquals('bar', $e->getMessage(), 'A custom message should be possible still.');
  39. }
  40. }