Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Finder] Throw a dedicated exception for non-existing directory #30744

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

Merged
merged 1 commit into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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\Finder\Exception;

/**
* @author Andreas Erhard <andreas.erhard@i-med.ac.at>
*/
class DirectoryNotFoundException extends \InvalidArgumentException
{
}
5 changes: 3 additions & 2 deletions 5 src/Symfony/Component/Finder/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Finder\Comparator\DateComparator;
use Symfony\Component\Finder\Comparator\NumberComparator;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
use Symfony\Component\Finder\Iterator\CustomFilterIterator;
use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
Expand Down Expand Up @@ -585,7 +586,7 @@ public function ignoreUnreadableDirs($ignore = true)
*
* @return $this
*
* @throws \InvalidArgumentException if one of the directories does not exist
* @throws DirectoryNotFoundException if one of the directories does not exist
*/
public function in($dirs)
{
Expand All @@ -597,7 +598,7 @@ public function in($dirs)
} elseif ($glob = glob($dir, (\defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
$resolvedDirs = array_merge($resolvedDirs, array_map([$this, 'normalizeDir'], $glob));
} else {
throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
throw new DirectoryNotFoundException(sprintf('The "%s" directory does not exist.', $dir));
}
}

Expand Down
11 changes: 10 additions & 1 deletion 11 src/Symfony/Component/Finder/Tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,14 +888,23 @@ public function testIn()
}

/**
* @expectedException \InvalidArgumentException
* @expectedException \Symfony\Component\Finder\Exception\DirectoryNotFoundException
*/
public function testInWithNonExistentDirectory()
{
$finder = new Finder();
$finder->in('foobar');
}

/**
* @expectedException \InvalidArgumentException
*/
public function testInWithNonExistentDirectoryLegacyException()
{
$finder = new Finder();
$finder->in('foobar');
}

public function testInWithGlob()
{
$finder = $this->buildFinder();
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.