Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 27, 2023
1 parent f4bb274 commit 7afe5d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Bundles/Storage/StorageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}

Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/Bundles/Storage/StorageFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace phpunit\Bundles\Storage;

use Exception;
use PHPUnit\Framework\TestCase;
use phpunit\Utils\Fakes\FakeStorage;
use PHPUnuhi\Bundles\Storage\StorageFactory;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 7afe5d9

Please sign in to comment.