mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Throw an exception when the scanner directories all does not exist. (#2043)
* Optimization when the Scanner directory all does not exist * Optimized test cases. Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
parent
3f0d876bf1
commit
c954e949c8
@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
- [#2159](https://github.com/hyperf/hyperf/pull/2159) Fixed fatal exception caused by exist file when using `gen:migration`.
|
- [#2159](https://github.com/hyperf/hyperf/pull/2159) Fixed fatal exception caused by exist file when using `gen:migration`.
|
||||||
|
|
||||||
|
## Optimized
|
||||||
|
|
||||||
|
- [#2043](https://github.com/hyperf/hyperf/pull/2043) Throw an exception when the scanner directories all does not exist.
|
||||||
|
|
||||||
# v2.0.3 - 2020-07-20
|
# v2.0.3 - 2020-07-20
|
||||||
|
|
||||||
## Added
|
## Added
|
||||||
|
@ -14,6 +14,7 @@ namespace Hyperf\Di\Annotation;
|
|||||||
use Hyperf\Config\ProviderConfig;
|
use Hyperf\Config\ProviderConfig;
|
||||||
use Hyperf\Di\BetterReflectionManager;
|
use Hyperf\Di\BetterReflectionManager;
|
||||||
use Hyperf\Di\ClassLoader;
|
use Hyperf\Di\ClassLoader;
|
||||||
|
use Hyperf\Di\Exception\DirectoryNotExistException;
|
||||||
use Hyperf\Di\MetadataCollector;
|
use Hyperf\Di\MetadataCollector;
|
||||||
use Hyperf\Utils\Filesystem\Filesystem;
|
use Hyperf\Utils\Filesystem\Filesystem;
|
||||||
use ReflectionProperty;
|
use ReflectionProperty;
|
||||||
@ -162,6 +163,7 @@ class Scanner
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Normalizes given directory names by removing directory not exist.
|
* Normalizes given directory names by removing directory not exist.
|
||||||
|
* @throws DirectoryNotExistException
|
||||||
*/
|
*/
|
||||||
public function normalizeDir(array $paths): array
|
public function normalizeDir(array $paths): array
|
||||||
{
|
{
|
||||||
@ -172,6 +174,10 @@ class Scanner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($paths && ! $result) {
|
||||||
|
throw new DirectoryNotExistException('The scanned directory does not exist');
|
||||||
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
16
src/di/src/Exception/DirectoryNotExistException.php
Normal file
16
src/di/src/Exception/DirectoryNotExistException.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
/**
|
||||||
|
* This file is part of Hyperf.
|
||||||
|
*
|
||||||
|
* @link https://www.hyperf.io
|
||||||
|
* @document https://hyperf.wiki
|
||||||
|
* @contact group@hyperf.io
|
||||||
|
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
|
||||||
|
*/
|
||||||
|
namespace Hyperf\Di\Exception;
|
||||||
|
|
||||||
|
class DirectoryNotExistException extends Exception
|
||||||
|
{
|
||||||
|
}
|
@ -16,6 +16,7 @@ use Hyperf\Di\Annotation\ScanConfig;
|
|||||||
use Hyperf\Di\Annotation\Scanner;
|
use Hyperf\Di\Annotation\Scanner;
|
||||||
use Hyperf\Di\BetterReflectionManager;
|
use Hyperf\Di\BetterReflectionManager;
|
||||||
use Hyperf\Di\ClassLoader;
|
use Hyperf\Di\ClassLoader;
|
||||||
|
use Hyperf\Di\Exception\DirectoryNotExistException;
|
||||||
use HyperfTest\Di\Stub\AnnotationCollector;
|
use HyperfTest\Di\Stub\AnnotationCollector;
|
||||||
use HyperfTest\Di\Stub\Ignore;
|
use HyperfTest\Di\Stub\Ignore;
|
||||||
use HyperfTest\Di\Stub\IgnoreDemoAnnotation;
|
use HyperfTest\Di\Stub\IgnoreDemoAnnotation;
|
||||||
@ -51,4 +52,25 @@ class AnnotationTest extends TestCase
|
|||||||
$annotations = AnnotationCollector::get(Ignore::class . '._c');
|
$annotations = AnnotationCollector::get(Ignore::class . '._c');
|
||||||
$this->assertNull($annotations);
|
$this->assertNull($annotations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testScanAnnotationsDirectoryNotExist()
|
||||||
|
{
|
||||||
|
$scanner = new Scanner($loader = Mockery::mock(ClassLoader::class), new ScanConfig(false, '/'));
|
||||||
|
$ref = new \ReflectionClass($scanner);
|
||||||
|
$method = $ref->getMethod('normalizeDir');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$this->expectException(DirectoryNotExistException::class);
|
||||||
|
$method->invokeArgs($scanner, [['/not_exists']]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testScanAnnotationsDirectoryEmpty()
|
||||||
|
{
|
||||||
|
$scanner = new Scanner($loader = Mockery::mock(ClassLoader::class), new ScanConfig(false, '/'));
|
||||||
|
$ref = new \ReflectionClass($scanner);
|
||||||
|
$method = $ref->getMethod('normalizeDir');
|
||||||
|
$method->setAccessible(true);
|
||||||
|
|
||||||
|
$this->assertSame([], $method->invokeArgs($scanner, [[]]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user