Skip to content

Commit

Permalink
Improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daanrijpkemacb committed Dec 30, 2023
1 parent 2441a00 commit c128fe0
Showing 1 changed file with 56 additions and 15 deletions.
71 changes: 56 additions & 15 deletions tests/Unit/BluemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<xmla>Some invalid aaXML String</xmla>');

$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;
Expand Down

0 comments on commit c128fe0

Please sign in to comment.