Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

Commit 4cef8cd

Browse files
committed
Fix customer generation
1 parent 2a435ff commit 4cef8cd

File tree

5 files changed

+92
-7
lines changed

5 files changed

+92
-7
lines changed

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@
3939
}
4040
},
4141
"scripts": {
42-
"test": [
42+
"cs": [
4343
"composer normalize --dry-run --no-interaction",
4444
"vendor/bin/ecs check src --no-interaction",
4545
"vendor/bin/phpstan analyse --no-interaction",
4646
"vendor/bin/phpunit"
4747
],
48-
"test-fix": [
48+
"cs-fix": [
4949
"composer normalize --no-interaction",
5050
"vendor/bin/ecs check src --fix --no-interaction"
51+
],
52+
"test": [
53+
"vendor/bin/phpstan analyse --no-interaction",
54+
"vendor/bin/phpunit"
5155
]
5256
}
5357
}

src/Model/Customer/Company.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ public function __construct(
1313
string $postalCode,
1414
string $cif,
1515
string $region,
16+
string $countryCode,
1617
string $businessName,
1718
string $tradeName
1819
) {
19-
parent::__construct($address, $town, $postalCode, $cif, $region);
20+
parent::__construct($address, $town, $postalCode, $cif, $region, $countryCode);
2021

2122
$this->businessType = 'company';
2223
$this->businessName = $businessName;
@@ -47,6 +48,7 @@ public static function createFromArray(array $data): Company
4748
$customer->getPostalCode(),
4849
$customer->getCif(),
4950
$customer->getRegion(),
51+
$customer->getCountryCode(),
5052
$data['business_name'],
5153
$data['tradename']
5254
);

src/Model/Customer/Customer.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@ public function getDefaultPaymentMethod(): ?string
7979

8080
public function setDefaultPaymentMethod(?string $defaultPaymentMethod): void
8181
{
82-
Assert::oneOf($defaultPaymentMethod, ['cash', 'receipt', 'wire_transfer', 'card', 'promissory_note', 'other']);
82+
Assert::oneOf($defaultPaymentMethod, [
83+
null,
84+
'cash',
85+
'receipt',
86+
'wire_transfer',
87+
'card',
88+
'promissory_note',
89+
'other',
90+
]);
8391
$this->defaultPaymentMethod = $defaultPaymentMethod;
8492
}
8593

@@ -153,7 +161,7 @@ public function setRegion(string $region): void
153161
$this->region = $region;
154162
}
155163

156-
public function getCountryCode(): ?string
164+
public function getCountryCode(): string
157165
{
158166
return $this->countryCode;
159167
}
@@ -230,7 +238,7 @@ public function getDefaultInvoiceLanguage(): ?string
230238

231239
public function setDefaultInvoiceLanguage(?string $defaultInvoiceLanguage): void
232240
{
233-
Assert::oneOf($defaultInvoiceLanguage, ['default', 'es', 'eu', 'ca', 'en']);
241+
Assert::oneOf($defaultInvoiceLanguage, [null, 'default', 'es', 'eu', 'ca', 'en']);
234242
$this->defaultInvoiceLanguage = $defaultInvoiceLanguage;
235243
}
236244

src/Model/Customer/Individual.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ public function __construct(
1010
string $postalCode,
1111
string $cif,
1212
string $region,
13+
string $countryCode,
1314
string $name,
1415
string $firstSurname
1516
) {
16-
parent::__construct($address, $town, $postalCode, $cif, $region);
17+
parent::__construct($address, $town, $postalCode, $cif, $region, $countryCode);
1718

1819
$this->businessType = 'individual';
1920
$this->setName($name);
@@ -34,6 +35,7 @@ public static function createFromArray(array $data): Individual
3435
$customer->getPostalCode(),
3536
$customer->getCif(),
3637
$customer->getRegion(),
38+
$customer->getCountryCode(),
3739
$data['name'],
3840
$data['surname_1']
3941
);
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace MarcOrtola\Cuentica\Tests\Model\Customer;
6+
7+
use MarcOrtola\Cuentica\Model\Customer\Company;
8+
use MarcOrtola\Cuentica\Model\Customer\CustomerFactory;
9+
use MarcOrtola\Cuentica\Model\Customer\Individual;
10+
use PHPStan\Testing\TestCase;
11+
12+
final class CustomerTest extends TestCase
13+
{
14+
/** @test */
15+
public function validApiArrayCustomerResponseShouldBeValidIndividualCustomer(): void
16+
{
17+
$input = [
18+
'address' => 'Street 1',
19+
'town' => 'Madrid',
20+
'postal_code' => '9100',
21+
'cif' => '',
22+
'region' => 'Texas',
23+
'country_code' => 'AR',
24+
'business_type' => 'individual',
25+
'id' => 597119,
26+
'name' => 'Steve',
27+
'surname_1' => 'Gates',
28+
'email' => 'invent@email.com',
29+
'personal_comment' => 'This is a comment.',
30+
];
31+
32+
$customer = new Individual('Street 1', 'Madrid', '9100', '', 'Texas', 'AR', 'Steve', 'Gates');
33+
$customer->setId(597119);
34+
$customer->setEmail('invent@email.com');
35+
$customer->setPersonalComment('This is a comment.');
36+
37+
$this->assertEquals($customer, CustomerFactory::createFromArray($input));
38+
}
39+
40+
/** @test */
41+
public function validApiArrayCustomerResponseShouldBeValidCompanyCustomer(): void
42+
{
43+
$input = [
44+
'address' => 'Street 1',
45+
'town' => 'Madrid',
46+
'postal_code' => '9100',
47+
'cif' => '',
48+
'region' => 'Texas',
49+
'country_code' => 'AR',
50+
'business_type' => 'company',
51+
'business_name' => 'My business name',
52+
'tradename' => 'That tradename',
53+
'id' => 597119,
54+
'name' => 'Steve',
55+
'surname_1' => 'Gates',
56+
'email' => 'invent@email.com',
57+
'personal_comment' => 'This is a comment.',
58+
];
59+
60+
$customer = new Company('Street 1', 'Madrid', '9100', '', 'Texas', 'AR', 'My business name', 'That tradename');
61+
$customer->setId(597119);
62+
$customer->setName('Steve');
63+
$customer->setFirstSurname('Gates');
64+
$customer->setEmail('invent@email.com');
65+
$customer->setPersonalComment('This is a comment.');
66+
67+
$this->assertEquals($customer, CustomerFactory::createFromArray($input));
68+
}
69+
}

0 commit comments

Comments
 (0)