Skip to content

Commit 8d99e3e

Browse files
author
Willem Stuursma-Ruwen
authored
Merge pull request #116 from archin-software/bug/consumer-attribute-default
Twinfield expects string representation of boolean ("true"/"false")
2 parents 3c823f4 + 5170ba6 commit 8d99e3e

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

src/CustomerAddress.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,19 @@ public function setType($type)
5353
return $this;
5454
}
5555

56-
public function getDefault()
56+
/**
57+
* @return bool
58+
*/
59+
public function getDefault() : bool
5760
{
5861
return $this->default;
5962
}
6063

61-
public function setDefault($default)
64+
/**
65+
* @param bool $default
66+
* @return $this
67+
*/
68+
public function setDefault(bool $default)
6269
{
6370
$this->default = $default;
6471
return $this;

src/CustomerBank.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,19 @@ public function setID($ID)
3939
return $this;
4040
}
4141

42-
public function getDefault()
42+
/**
43+
* @return bool
44+
*/
45+
public function getDefault() : bool
4346
{
4447
return $this->default;
4548
}
4649

47-
public function setDefault($default)
50+
/**
51+
* @param bool $default
52+
* @return $this
53+
*/
54+
public function setDefault(bool $default)
4855
{
4956
$this->default = $default;
5057
return $this;

src/DomDocuments/CustomersDocument.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace PhpTwinfield\DomDocuments;
33

44
use PhpTwinfield\Customer;
5+
use PhpTwinfield\CustomerAddress;
56
use PhpTwinfield\CustomerBank;
67
use PhpTwinfield\Util;
78

@@ -201,14 +202,15 @@ public function addCustomer(Customer $customer): void
201202
$customerEl->appendChild($addressesElement);
202203

203204
// Go through each address assigned to the customer
205+
/** @var CustomerAddress $address */
204206
foreach ($addresses as $address) {
205207

206208
// Makes new address element
207209
$addressElement = $this->createElement('address');
208210
$addressesElement->appendChild($addressElement);
209211

210212
// Set attributes
211-
$addressElement->setAttribute('default', $address->getDefault());
213+
$addressElement->setAttribute('default', Util::formatBoolean($address->getDefault()));
212214
$addressElement->setAttribute('type', $address->getType());
213215

214216
// Go through each address element and use the assigned method
@@ -257,7 +259,7 @@ public function addCustomer(Customer $customer): void
257259
$banksElement->appendChild($bankElement);
258260

259261
// Set attributes
260-
$bankElement->setAttribute('default', $bank->getDefault());
262+
$bankElement->setAttribute('default', Util::formatBoolean($bank->getDefault()));
261263

262264
// Go through each bank element and use the assigned method
263265
foreach ($bankTags as $tag => $method) {

src/Mappers/CustomerMapper.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
use PhpTwinfield\Customer;
55
use PhpTwinfield\CustomerAddress;
66
use PhpTwinfield\CustomerBank;
7+
use PhpTwinfield\Exception;
78
use PhpTwinfield\Response\Response;
9+
use PhpTwinfield\Util;
810

911
/**
1012
* Maps a response DOMDocument to the corresponding entity.
@@ -22,6 +24,7 @@ class CustomerMapper extends BaseMapper
2224
* @access public
2325
* @param \PhpTwinfield\Response\Response $response
2426
* @return Customer
27+
* @throws Exception
2528
*/
2629
public static function map(Response $response)
2730
{
@@ -180,7 +183,7 @@ public static function map(Response $response)
180183
$temp_address
181184
->setID($addressDOM->getAttribute('id'))
182185
->setType($addressDOM->getAttribute('type'))
183-
->setDefault($addressDOM->getAttribute('default'));
186+
->setDefault(Util::parseBoolean($addressDOM->getAttribute('default')));
184187

185188
// Loop through the element tags. Determine if it exists and set it if it does
186189
foreach ($addressTags as $tag => $method) {
@@ -233,7 +236,7 @@ public static function map(Response $response)
233236
// Set the attributes ( id, default )
234237
$temp_bank
235238
->setID($bankDOM->getAttribute('id'))
236-
->setDefault($bankDOM->getAttribute('default'));
239+
->setDefault(Util::parseBoolean($bankDOM->getAttribute('default')));
237240

238241
// Loop through the element tags. Determine if it exists and set it if it does
239242
foreach ($bankTags as $tag => $method) {

tests/IntegrationTests/CustomerIntegrationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testGetCustomerWorks()
7878

7979
$this->assertSame('1', $address->getID());
8080
$this->assertSame('invoice', $address->getType());
81-
$this->assertSame('true', $address->getDefault());
81+
$this->assertSame(true, $address->getDefault());
8282
$this->assertSame('Customer 0', $address->getName());
8383
$this->assertSame('NL', $address->getCountry());
8484
$this->assertSame('Place', $address->getCity());
@@ -103,7 +103,7 @@ public function testGetCustomerWorks()
103103
$bank = $banks['-1'];
104104

105105
$this->assertSame('-1', $bank->getID());
106-
$this->assertSame('true', $bank->getDefault());
106+
$this->assertSame(true, $bank->getDefault());
107107
$this->assertSame('Customer 1', $bank->getAscription());
108108
$this->assertSame('123456789', $bank->getAccountnumber());
109109
$this->assertSame('ABN Amro', $bank->getBankname());
@@ -178,7 +178,7 @@ public function testSendCustomerWorks()
178178
$address = new CustomerAddress();
179179
$address->setID('1');
180180
$address->setType('invoice');
181-
$address->setDefault('true');
181+
$address->setDefault(true);
182182
$address->setName('Customer 0');
183183
$address->setCountry('NL');
184184
$address->setCity('Place');
@@ -192,7 +192,7 @@ public function testSendCustomerWorks()
192192
$customer->addAddress($address);
193193

194194
$bank = new CustomerBank();
195-
$bank->setDefault('true');
195+
$bank->setDefault(true);
196196
$bank->setAscription('Customer 1');
197197
$bank->setAccountnumber('123456789');
198198
$bank->setAddressField2('');

tests/UnitTests/DomDocuments/CustomersDocumentUnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function testXmlIsCreatedPerSpec()
127127
<comment>comment comment</comment>
128128
</creditmanagement>
129129
<addresses>
130-
<address default="1" type="invoice">
130+
<address default="true" type="invoice">
131131
<name>My Address</name>
132132
<contact>My Contact</contact>
133133
<country>nl</country>
@@ -145,7 +145,7 @@ public function testXmlIsCreatedPerSpec()
145145
</address>
146146
</addresses>
147147
<banks>
148-
<bank default="1">
148+
<bank default="true">
149149
<ascription>ascriptor</ascription>
150150
<accountnumber>account number</accountnumber>
151151
<bankname>bank name</bankname>

0 commit comments

Comments
 (0)