From e0e0f974f416acc5055382ceeb76e10d00fcf206 Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Thu, 21 Dec 2023 22:32:57 +0100 Subject: [PATCH] add unit tests --- .../Bundles/Exchange/ExchangeFactoryTest.php | 78 +++++++++++++++++++ .../Utils/Fakes/FakeExchangeFormat.php | 39 ++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/phpunit/Bundles/Exchange/ExchangeFactoryTest.php create mode 100644 tests/phpunit/Utils/Fakes/FakeExchangeFormat.php diff --git a/tests/phpunit/Bundles/Exchange/ExchangeFactoryTest.php b/tests/phpunit/Bundles/Exchange/ExchangeFactoryTest.php new file mode 100644 index 00000000..502c8127 --- /dev/null +++ b/tests/phpunit/Bundles/Exchange/ExchangeFactoryTest.php @@ -0,0 +1,78 @@ +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('', []); + } + +} diff --git a/tests/phpunit/Utils/Fakes/FakeExchangeFormat.php b/tests/phpunit/Utils/Fakes/FakeExchangeFormat.php new file mode 100644 index 00000000..196c016e --- /dev/null +++ b/tests/phpunit/Utils/Fakes/FakeExchangeFormat.php @@ -0,0 +1,39 @@ +