Skip to content

Commit

Permalink
Merge pull request #224 from zetno/master-1
Browse files Browse the repository at this point in the history
Update TransactionTypeApiConnector.php
  • Loading branch information
rojtjo authored Aug 25, 2023
2 parents 9d78de5 + f2d662a commit e2b2e68
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
11 changes: 9 additions & 2 deletions src/ApiConnectors/TransactionTypeApiConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,15 @@ public function listAll(
$transactionTypes = [];
foreach ($response->data->Items->ArrayOfString as $transactionTypeArray) {
$transactionType = new TransactionType();
$transactionType->setCode($transactionTypeArray->string[0]);
$transactionType->setName($transactionTypeArray->string[1]);

if (is_array($transactionTypeArray)) {
$transactionType->setCode($transactionTypeArray[0]);
$transactionType->setName($transactionTypeArray[1]);
} else {
$transactionType->setCode($transactionTypeArray->string[0]);
$transactionType->setName($transactionTypeArray->string[1]);
}

$transactionTypes[] = $transactionType;
}

Expand Down
26 changes: 21 additions & 5 deletions tests/IntegrationTests/TransactionTypesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ protected function setUp(): void
$this->transactionTypeApiConnector = new TransactionTypeApiConnector($this->connection);
}

public function testListAllWorks()
public function testListAllWithMultipleResults()
{
$response = require __DIR__ . '/resources/transactionTypesListAllResponse.php';
$response = require __DIR__ . '/resources/transactionTypesListAllWithMultipleResultsResponse.php';

$this->finderService
->expects($this->once())
Expand All @@ -47,6 +47,22 @@ public function testListAllWorks()
$this->assertSame('Verkoopfactuur', $transactionTypes[4]->getName());
}

public function testListAllWithSingleResult()
{
$response = require __DIR__ . '/resources/transactionTypesListAllWithSingleResultResponse.php';

$this->finderService
->expects($this->once())
->method("searchFinder")
->with(FinderService::TYPE_TRANSACTION_TYPES, '*', 0, 1, 100, [])
->willReturn($response);

$transactionTypes = $this->transactionTypeApiConnector->listAll();

$this->assertSame('BEGINBALANS', $transactionTypes[0]->getCode());
$this->assertSame('Beginbalans', $transactionTypes[0]->getName());
}

public function testListAllTheIcOptionCannotBeUsedInCombinationWithTheHiddenOption()
{
$this->expectException(\InvalidArgumentException::class);
Expand All @@ -56,7 +72,7 @@ public function testListAllTheIcOptionCannotBeUsedInCombinationWithTheHiddenOpti

public function testListAllWithCategory()
{
$response = require __DIR__ . '/resources/transactionTypesListAllResponse.php';
$response = require __DIR__ . '/resources/transactionTypesListAllWithMultipleResultsResponse.php';

$this->finderService
->expects($this->once())
Expand All @@ -71,7 +87,7 @@ public function testListAllWithCategory()

public function testListAllWithTheIcOption()
{
$response = require __DIR__ . '/resources/transactionTypesListAllResponse.php';
$response = require __DIR__ . '/resources/transactionTypesListAllWithMultipleResultsResponse.php';

$this->finderService
->expects($this->once())
Expand All @@ -86,7 +102,7 @@ public function testListAllWithTheIcOption()

public function testListAllWithTheHiddenOption()
{
$response = require __DIR__ . '/resources/transactionTypesListAllResponse.php';
$response = require __DIR__ . '/resources/transactionTypesListAllWithMultipleResultsResponse.php';

$this->finderService
->expects($this->once())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

return (object) array(
'SearchResult' =>
(object) array(
),
'data' =>
(object) array(
'TotalRows' => 5,
'Columns' =>
(object) array(
'string' =>
array (
0 => 'Code',
1 => 'Naam',
),
),
'Items' =>
(object) array(
'ArrayOfString' =>
array (
0 =>
array (
0 => 'BEGINBALANS',
1 => 'Beginbalans',
),
),
),
),
);

0 comments on commit e2b2e68

Please sign in to comment.