8000 Use a dedicated exception in the file locator by leofeyer · Pull Request #19511 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Use a dedicated exception in the file locator #19511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000 Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use a dedicated exception in the file locator.
  • Loading branch information
leofeyer committed Aug 2, 2016
commit 5dce9f312b85d380e37d815da16f19a8add59954
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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\Config\Exception;

/**
* File locator exception if a file does not exist.
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class FileLocatorFileNotFoundException extends \InvalidArgumentException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not simply FileNotFoundException? The current name is verbose

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the other exception classes also use a prefix: https://github.com/symfony/symfony/tree/master/src/Symfony/Component/Config/Exception

Just wanted to keep things consistent.

{
}
6 changes: 4 additions & 2 deletions src/Symfony/Component/Config/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Config;

use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;

/**
* FileLocator uses an array of pre-defined paths to find files.
*
Expand Down Expand Up @@ -41,7 +43,7 @@ public function locate($name, $currentPath = null, $first = true)

if ($this->isAbsolutePath($name)) {
if (!file_exists($name)) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist.', $name));
}

return $name;
Expand All @@ -66,7 +68,7 @@ public function locate($name, $currentPath = null, $first = true)
}

if (!$filepaths) {
throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
throw new FileLocatorFileNotFoundException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $paths)));
}

return $filepaths;
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Config/FileLocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Config;

use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;

/**
* @author Fabien Potencier <fabien@symfony.com>
*/
Expand All @@ -25,7 +27,8 @@ interface FileLocatorInterface
*
* @return string|array The full path to the file or an array of file paths
*
* @throws \InvalidArgumentException When file is not found
* @throws \InvalidArgumentException If $name is empty
* @throws FileLocatorFileNotFoundException If a file is not found
*/
public function locate($name, $currentPath = null, $first = true);
}
5 changes: 3 additions & 2 deletions src/Symfony/Component/Config/Tests/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Config\Tests;

use Symfony\Component\Config\Exception\FileLocatorFileNotFoundException;
use Symfony\Component\Config\FileLocator;

class FileLocatorTest extends \PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -86,7 +87,7 @@ public function testLocate()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException FileLocatorFileNotFoundException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpunit doesn't handle use statements, should be Symfony\Component\Config\Exception\FileLocatorFileNotFoundException (same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the PR accordingly. However, use statements seem to work in phpunit under PHP 5.6 and PHP 7. Is this a known issue?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 7 requires a phpunit 5.* whereas phpunit 4.8 is the only option for PHP5.3 to 5.5.
Maybe phpunit 5.* handles use, but since we still support PHP 5.3, we can't use them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That cannot be true. I am using PhpUnit 4.8 with PHP 7.0.

leofeyer:core-bundle$ vendor/bin/phpunit --version
PHPUnit 4.8.27 by Sebastian Bergmann and contributors.

leofeyer:core-bundle$ php -v
PHP 7.0.9 (cli) (built: Jul 21 2016 14:50:47) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.9, Copyright (c) 1999-2016, by Zend Technologies
    with blackfire v1.11.1, https://blackfire.io, by Blackfireio Inc.

* @expectedExceptionMessage The file "foobar.xml" does not exist
*/
public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
Expand All @@ -97,7 +98,7 @@ public function testLocateThrowsAnExceptionIfTheFileDoesNotExists()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException FileLocatorFileNotFoundException
*/
public function testLocateThrowsAnExceptionIfTheFileDoesNotExistsInAbsolutePath()
{
Expand Down
0