diff --git a/src/Bundles/Storage/StorageFactory.php b/src/Bundles/Storage/StorageFactory.php index a8a3ebe2..43eef332 100644 --- a/src/Bundles/Storage/StorageFactory.php +++ b/src/Bundles/Storage/StorageFactory.php @@ -62,11 +62,10 @@ public function registerStorage(StorageInterface $storage): void } } - $this->storages[] =$storage; + $this->storages[] = $storage; } - /** * Resets the registered storages to the default ones. * @return void @@ -103,7 +102,7 @@ public function getStorage(TranslationSet $set): StorageInterface */ public function getStorageByFormat(string $name, TranslationSet $set): StorageInterface { - if ($name === '' || $name === '0') { + if (trim($name) === '') { throw new Exception('No name provided for the Storage'); } diff --git a/tests/phpunit/Bundles/Storage/StorageFactoryTest.php b/tests/phpunit/Bundles/Storage/StorageFactoryTest.php index 6d8ce8fd..6c38ac89 100644 --- a/tests/phpunit/Bundles/Storage/StorageFactoryTest.php +++ b/tests/phpunit/Bundles/Storage/StorageFactoryTest.php @@ -2,6 +2,7 @@ namespace phpunit\Bundles\Storage; +use Exception; use PHPUnit\Framework\TestCase; use phpunit\Utils\Fakes\FakeStorage; use PHPUnuhi\Bundles\Storage\StorageFactory; @@ -70,4 +71,30 @@ public function testGetCustomStorageBySet(): void $this->assertSame($fakeStorage, $storage); } + + /** + * @testWith [""] + * [" "] + * + * @param string $emptyFormat + * @throws ConfigurationException + * @return void + */ + public function testEmptyStorageFormatThrowsException(string $emptyFormat): void + { + $this->expectException(Exception::class); + + StorageFactory::getInstance()->getStorageByFormat($emptyFormat, $this->set); + } + + /** + * @throws ConfigurationException + * @return void + */ + public function testUnknownStorageFormatThrowsException(): void + { + $this->expectException(ConfigurationException::class); + + StorageFactory::getInstance()->getStorageByFormat('unknown', $this->set); + } }