From d9167a9d064c92f3b8b81c283956df044c23ad4e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 29 Sep 2023 04:09:40 +0000 Subject: [PATCH] fix tests --- System/File/Storage.php | 17 +++++++++++------ tests/System/File/StorageTest.php | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/System/File/Storage.php b/System/File/Storage.php index 2bcb5fbce..56b7fb91f 100755 --- a/System/File/Storage.php +++ b/System/File/Storage.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace phpOMS\System\File; +use phpOMS\Autoloader; + /** * Filesystem class. * @@ -71,15 +73,18 @@ final class Storage throw new \Exception('Invalid type'); } } else { - $stg = $env; - $env = \ucfirst(\strtolower($env)); - /** @var StorageAbstract $env */ - $env = __NAMESPACE__ . '\\' . $env . '\\' . $env . 'Storage'; + $stg = \ucfirst(\strtolower($env)); + $stg = __NAMESPACE__ . '\\' . $stg . '\\' . $stg . 'Storage'; + if (!Autoloader::exists($stg)) { + throw new \Exception('Invalid type'); + } + + /** @var StorageAbstract $stg */ /** @var StorageAbstract $instance */ - $instance = new $env(); + $instance = new $stg(); - self::$registered[$stg] = $instance; + self::$registered[$env] = $instance; } return $instance; diff --git a/tests/System/File/StorageTest.php b/tests/System/File/StorageTest.php index 19c93bf4d..8b8decfe7 100755 --- a/tests/System/File/StorageTest.php +++ b/tests/System/File/StorageTest.php @@ -76,7 +76,7 @@ final class StorageTest extends \PHPUnit\Framework\TestCase */ public function testInvalidStorage() : void { - $this->expectException(\Error::class); + $this->expectException(\Exception::class); self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env('invalid')); }