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 21, 2023
1 parent ee128c3 commit e0e0f97
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/phpunit/Bundles/Exchange/ExchangeFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace phpunit\Bundles\Exchange;

use Exception;
use PHPUnit\Framework\TestCase;
use phpunit\Utils\Fakes\FakeExchangeFormat;
use phpunit\Utils\Fakes\FakeStorage;
use PHPUnuhi\Bundles\Exchange\ExchangeFactory;
use PHPUnuhi\Bundles\Storage\StorageFactory;
use PHPUnuhi\Exceptions\ConfigurationException;
use PHPUnuhi\Models\Configuration\Filter;
use PHPUnuhi\Models\Configuration\Protection;
use PHPUnuhi\Models\Translation\TranslationSet;

class ExchangeFactoryTest extends TestCase
{

/**
* @return void
*/
protected function setUp(): void
{
ExchangeFactory::getInstance()->resetExchangeFormats();
}


/**
* @return void
* @throws ConfigurationException
*/
public function testGetCustomExchangeFormat(): void
{
$custom = new FakeExchangeFormat();
ExchangeFactory::getInstance()->registerExchangeFormat($custom);

$exchange = ExchangeFactory::getInstance()->getExchange('fake', []);

$this->assertSame($custom, $exchange);
}

/**
* @return void
* @throws ConfigurationException
*/
public function testDoubleRegistrationThrowsException(): void
{
$this->expectException(Exception::class);

$custom = new FakeExchangeFormat();

ExchangeFactory::getInstance()->registerExchangeFormat($custom);
ExchangeFactory::getInstance()->registerExchangeFormat($custom);
}

/**
* @return void
* @throws ConfigurationException
*/
public function testUnknownFormatThrowsException(): void
{
$this->expectException(Exception::class);

ExchangeFactory::getInstance()->getExchange('unknown', []);
}

/**
* @return void
* @throws ConfigurationException
*/
public function testEmptyFormatThrowsException(): void
{
$this->expectException(Exception::class);

ExchangeFactory::getInstance()->getExchange('', []);
}

}
39 changes: 39 additions & 0 deletions tests/phpunit/Utils/Fakes/FakeExchangeFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace phpunit\Utils\Fakes;

use PHPUnuhi\Bundles\Exchange\ExchangeInterface;
use PHPUnuhi\Bundles\Exchange\ImportResult;
use PHPUnuhi\Models\Command\CommandOption;
use PHPUnuhi\Models\Translation\TranslationSet;

class FakeExchangeFormat implements ExchangeInterface
{

public function getName(): string
{
return 'fake';
}

public function getOptions(): array
{
// TODO: Implement getOptions() method.
}

public function setOptionValues(array $options): void
{
// TODO: Implement setOptionValues() method.
}

public function export(TranslationSet $set, string $outputDir, bool $onlyEmpty): void
{
// TODO: Implement export() method.
}

public function import(string $filename): ImportResult
{
// TODO: Implement import() method.
}


}

0 comments on commit e0e0f97

Please sign in to comment.