From c128fe023f8fae338aa08ce88b254e1fa6749308 Mon Sep 17 00:00:00 2001 From: "daan.rijpkema" Date: Sat, 30 Dec 2023 14:51:14 +0100 Subject: [PATCH] Improved tests --- tests/Unit/BluemTest.php | 71 +++++++++++++++++++++++++++++++--------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/tests/Unit/BluemTest.php b/tests/Unit/BluemTest.php index 8fd67c0..88192a8 100644 --- a/tests/Unit/BluemTest.php +++ b/tests/Unit/BluemTest.php @@ -9,41 +9,82 @@ namespace Unit; use Bluem\BluemPHP\Bluem; +use Bluem\BluemPHP\Contexts\IdentityContext; use Bluem\BluemPHP\Exceptions\InvalidBluemConfigurationException; -use Exception; +use Bluem\BluemPHP\Interfaces\BluemResponseInterface; +use Bluem\BluemPHP\Requests\BluemRequest; +use Bluem\BluemPHP\Responses\ErrorBluemResponse; use PHPUnit\Framework\TestCase; +use RuntimeException; use stdClass; class BluemTest extends TestCase { private Bluem $bluem; + /** + * @throws InvalidBluemConfigurationException + */ protected function setUp(): void { - parent::setUp(); + // Mock the configuration as needed + $mockedConfig = $this->getConfig(); + $this->bluem = new Bluem($mockedConfig); + } + - $bluem_config = $this->getConfig(); - try { - $this->bluem = new Bluem( - $bluem_config - ); - } catch (Exception $e) { - $this->fail($e->getMessage()); - } + public function testConstructorWithValidConfig(): void + { + $this->assertInstanceOf(Bluem::class, $this->bluem); + } + + public function testConstructorWithInvalidConfig(): void + { + $this->expectException(InvalidBluemConfigurationException::class); + new Bluem(null); } - protected function tearDown(): void + + public function testMandateWithValidParameters(): void { - //$this->bluem = Bluem; + // Mock the expected response + $mockedResponse = $this->createMock(BluemResponseInterface::class); + + // Test the Mandate method with valid parameters + $response = $this->bluem->Mandate('customer_id', 'order_id', 'mandate_id'); + + // Assertions + $this->assertInstanceOf(BluemResponseInterface::class, $response); } - public function testMandateRequest() + public function testMandateWithException(): void + { + $this->expectException(RuntimeException::class); + $this->bluem->Mandate('', '', ''); + } + public function testCreateMandateID(): void + { + $mandateID = $this->bluem->CreateMandateID('order_id', 'customer_id'); + $this->assertIsString($mandateID); + } + public function testPerformRequestWithInvalidXml(): void { - $result = true; - $this->assertEquals(true, $result); + // Mock a request that would generate invalid XML + $mockBluemRequest = $this->createMock(BluemRequest::class); + + $mockBluemRequest->method('XmlString') + ->willReturn('Some invalid aaXML String'); + + $mockBluemRequest->method('HttpRequestURL') + ->willReturn('https://example.com/api/request'); + $mockBluemRequest->method('RequestContext')->willReturn(new IdentityContext()); + + $result = $this->bluem->PerformRequest($mockBluemRequest); + $this->assertInstanceOf(ErrorBluemResponse::class, $result); } + // helper classes private function getConfig(): stdClass { $bluem_config = new stdClass;