Skip to content

Commit 7abf07d

Browse files
committed
Fix tests (#21)
1 parent c1d91c7 commit 7abf07d

8 files changed

Lines changed: 166 additions & 142 deletions

File tree

composer.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,6 @@
8181
}
8282
}
8383
},
84-
"repositories": {
85-
"sandwich/vies-bundle": {
86-
"type": "git",
87-
"url": "https://github.com/mmenozzi/ViesBundle.git"
88-
}
89-
},
9084
"autoload": {
9185
"psr-4": {
9286
"Webgriffe\\SyliusItalianInvoiceableOrderPlugin\\": "src/"
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
@invoiceable_address_book
22
Feature: Having new invoiceable addresses saved in the address book after checkout
3-
In order to ease my address management
4-
As a Customer
5-
I want new invoiceable addresses provided during checkout to be saved in my address book
3+
In order to ease my address management
4+
As a Customer
5+
I want new invoiceable addresses provided during checkout to be saved in my address book
66

7-
Background:
8-
Given the store operates on a single channel in "Italy"
9-
And the store has a product "Lannister Coat" priced at "$19.99"
10-
And the store ships everywhere for free
11-
And the store allows paying with "Cash on Delivery"
12-
And I am a logged in customer
13-
And I added product "Lannister Coat" to the cart
7+
Background:
8+
Given the store operates on a single channel in "Italy"
9+
And the store has a product "Lannister Coat" priced at "$19.99"
10+
And the store ships everywhere for free
11+
And the store allows paying with "Cash on Delivery"
12+
And I am a logged in customer
13+
And I added product "Lannister Coat" to the cart
1414

15-
@ui
16-
Scenario: Invoiceable address already existent in my book don't get saved again
17-
Given I have an address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
18-
And this address has also all the invoiceable information valid for an italian company
19-
And I am at the checkout addressing step
20-
When I specify the billing address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
21-
And I specify the same invoiceable information of the address I have in my address book
22-
And I complete the addressing step
23-
And I proceed with "Free" shipping method and "Cash on Delivery" payment
24-
And I confirm my order
25-
And I should see the thank you page
26-
Then I should have a single address in my address book
15+
@ui
16+
Scenario: Invoiceable address already existent in my book don't get saved again
17+
Given I have an address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
18+
And this address has also all the invoiceable information valid for an italian company
19+
And I am at the checkout addressing step
20+
When I specify the billing address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
21+
And I specify the same invoiceable information of the address I have in my address book
22+
And I complete the addressing step
23+
And I proceed with "Free" shipping method and "Cash on Delivery" payment
24+
And I confirm my order
25+
And I should see the thank you page
26+
Then I should have a single address in my address book
2727

28-
@ui
29-
Scenario: Different invoiceable address information provided during checkout are saved in my book as new address
30-
Given I have an address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
31-
And this address has also all the invoiceable information valid for an italian company
32-
And I am at the checkout addressing step
33-
When I specify the billing address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
34-
And I specify the same invoiceable information of the address I have in my address book
35-
But I specify a different SDI code from that of the address I have in the address book
36-
And I complete the addressing step
37-
And I proceed with "Free" shipping method and "Cash on Delivery" payment
38-
And I confirm my order
39-
And I should see the thank you page
40-
Then I should have 2 addresses in my address book
28+
@ui
29+
Scenario: Different invoiceable address information provided during checkout are saved in my book as new address
30+
Given I have an address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
31+
And this address has also all the invoiceable information valid for an italian company
32+
And I am at the checkout addressing step
33+
When I specify the billing address for the company "GoT SpA" - "Jon Snow" - "Viale Italia", "42100", "Reggio Emilia" - "Italy"
34+
And I specify the same invoiceable information of the address I have in my address book
35+
But I specify a different SDI code from that of the address I have in the address book
36+
And I complete the addressing step
37+
And I proceed with "Free" shipping method and "Cash on Delivery" payment
38+
And I confirm my order
39+
And I should see the thank you page
40+
Then I should have 2 addresses in my address book
Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,89 @@
11
@applying_taxes
22
Feature: Apply correct taxes based on order address
3-
In order to pay proper amount when buying goods
4-
As a Customer or Visitor
5-
I want to have correct taxes applied to my order
3+
In order to pay proper amount when buying goods
4+
As a Customer or Visitor
5+
I want to have correct taxes applied to my order
66

7-
Background:
8-
Given the store operates on a single channel worldwide
9-
And the store uses the "Italian tax calculation strategy" tax calculation strategy
10-
And there is a tax zone "EU" containing all European Union countries
11-
And there is a tax zone "Extra EU" containing all countries outside the European Union
12-
And there is a shipping zone "Global" containing all countries of the world
13-
And the store ships everywhere for Free
14-
And the store allows paying Offline
15-
And the store has "IVA 22%" tax rate of 22% for "IVA Ordinaria" within the "EU" zone
16-
And the store has a product "PHP T-Shirt" priced at "$100.00"
17-
And it belongs to "IVA Ordinaria" tax category
7+
Background:
8+
Given the store operates on a single channel worldwide
9+
And the store uses the "Italian tax calculation strategy" tax calculation strategy
10+
And there is a tax zone "EU" containing all European Union countries
11+
And there is a tax zone "Extra EU" containing all countries outside the European Union
12+
And there is a shipping zone "Global" containing all countries of the world
13+
And the store ships everywhere for Free
14+
And the store allows paying Offline
15+
And the store has "IVA 22%" tax rate of 22% for "IVA Ordinaria" within the "EU" zone
16+
And the store has a product "PHP T-Shirt" priced at "$100.00"
17+
And it belongs to "IVA Ordinaria" tax category
1818

19-
@ui
20-
Scenario: Paying taxes while ordering as an italian individual
21-
Given I added product "PHP T-Shirt" to the cart
22-
And I am at the checkout addressing step
23-
And I specify the email as "italian-individual@email.com"
24-
And I specify a valid italian individual billing address
25-
And I complete the addressing step
26-
And I proceed with "Free" shipping method and "Offline" payment
27-
Then I should be on the checkout complete step
28-
And my order total should be "$122.00"
29-
And my tax total should be "$22.00"
19+
@ui
20+
Scenario: Paying taxes while ordering as an italian individual
21+
Given I added product "PHP T-Shirt" to the cart
22+
And I am at the checkout addressing step
23+
And I specify the email as "italian-individual@email.com"
24+
And I specify a valid italian individual billing address
25+
And I complete the addressing step
26+
And I proceed with "Free" shipping method and "Offline" payment
27+
Then I should be on the checkout complete step
28+
And my order total should be "$122.00"
29+
And my tax total should be "$22.00"
3030

31-
@ui
32-
Scenario: Paying taxes while ordering as an italian company
33-
Given I added product "PHP T-Shirt" to the cart
34-
And I am at the checkout addressing step
35-
And I specify the email as "italian-company@email.com"
36-
And I specify a valid italian company billing address
37-
And I complete the addressing step
38-
And I proceed with "Free" shipping method and "Offline" payment
39-
Then I should be on the checkout complete step
40-
And my order total should be "$122.00"
41-
And my tax total should be "$22.00"
31+
@ui
32+
Scenario: Paying taxes while ordering as an italian company
33+
Given I added product "PHP T-Shirt" to the cart
34+
And I am at the checkout addressing step
35+
And I specify the email as "italian-company@email.com"
36+
And I specify a valid italian company billing address
37+
And I complete the addressing step
38+
And I proceed with "Free" shipping method and "Offline" payment
39+
Then I should be on the checkout complete step
40+
And my order total should be "$122.00"
41+
And my tax total should be "$22.00"
4242

43-
@ui
44-
Scenario: Paying taxes while ordering as an EU individual
45-
Given I added product "PHP T-Shirt" to the cart
46-
And I am at the checkout addressing step
47-
And I specify the email as "german-individual@email.com"
48-
And I specify a valid german individual billing address
49-
And I complete the addressing step
50-
And I proceed with "Free" shipping method and "Offline" payment
51-
Then I should be on the checkout complete step
52-
And my order total should be "$122.00"
53-
And my tax total should be "$22.00"
43+
@ui
44+
Scenario: Paying taxes while ordering as an EU individual
45+
Given I added product "PHP T-Shirt" to the cart
46+
And I am at the checkout addressing step
47+
And I specify the email as "german-individual@email.com"
48+
And I specify a valid german individual billing address
49+
And I complete the addressing step
50+
And I proceed with "Free" shipping method and "Offline" payment
51+
Then I should be on the checkout complete step
52+
And my order total should be "$122.00"
53+
And my tax total should be "$22.00"
5454

55-
@ui
56-
Scenario: Not paying taxes while ordering as an EU company
57-
Given I added product "PHP T-Shirt" to the cart
58-
And I am at the checkout addressing step
59-
And I specify the email as "german-company@email.com"
60-
And I specify a valid german company billing address
61-
And I complete the addressing step
62-
And I proceed with "Free" shipping method and "Offline" payment
63-
Then I should be on the checkout complete step
64-
And my order total should be "$100.00"
65-
And my tax total should be "$0.00"
55+
@ui
56+
Scenario: Not paying taxes while ordering as an EU company
57+
Given I added product "PHP T-Shirt" to the cart
58+
And I am at the checkout addressing step
59+
And I specify the email as "german-company@email.com"
60+
And I specify a valid german company billing address
61+
And I complete the addressing step
62+
And I proceed with "Free" shipping method and "Offline" payment
63+
Then I should be on the checkout complete step
64+
And my order total should be "$100.00"
65+
And my tax total should be "$0.00"
6666

67-
@ui
68-
Scenario: Not paying taxes while ordering as an extra EU individual
69-
Given I added product "PHP T-Shirt" to the cart
70-
And I am at the checkout addressing step
71-
And I specify the email as "usa-individual@email.com"
72-
And I specify a valid US individual billing address
73-
And I complete the addressing step
74-
And I proceed with "Free" shipping method and "Offline" payment
75-
Then I should be on the checkout complete step
76-
And my order total should be "$100.00"
77-
And my tax total should be "$0.00"
67+
@ui
68+
Scenario: Not paying taxes while ordering as an extra EU individual
69+
Given I added product "PHP T-Shirt" to the cart
70+
And I am at the checkout addressing step
71+
And I specify the email as "usa-individual@email.com"
72+
And I specify a valid US individual billing address
73+
And I complete the addressing step
74+
And I proceed with "Free" shipping method and "Offline" payment
75+
Then I should be on the checkout complete step
76+
And my order total should be "$100.00"
77+
And my tax total should be "$0.00"
7878

79-
@ui
80-
Scenario: Not paying taxes while ordering as an extra EU company
81-
Given I added product "PHP T-Shirt" to the cart
82-
And I am at the checkout addressing step
83-
And I specify the email as "usa-company@email.com"
84-
And I specify a valid US company billing address
85-
And I complete the addressing step
86-
And I proceed with "Free" shipping method and "Offline" payment
87-
Then I should be on the checkout complete step
88-
And my order total should be "$100.00"
89-
And my tax total should be "$0.00"
79+
@ui
80+
Scenario: Not paying taxes while ordering as an extra EU company
81+
Given I added product "PHP T-Shirt" to the cart
82+
And I am at the checkout addressing step
83+
And I specify the email as "usa-company@email.com"
84+
And I specify a valid US company billing address
85+
And I complete the addressing step
86+
And I proceed with "Free" shipping method and "Offline" payment
87+
Then I should be on the checkout complete step
88+
And my order total should be "$100.00"
89+
And my tax total should be "$0.00"

src/Taxation/ItalianTaxCalculationStrategy.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,20 @@
1414

1515
final class ItalianTaxCalculationStrategy implements TaxCalculationStrategyInterface
1616
{
17-
private string $type;
18-
19-
/** @var OrderTaxesApplicatorInterface[] */
20-
private array $applicators;
21-
22-
private string $euTaxZoneCode;
17+
/** @var iterable<OrderTaxesApplicatorInterface> */
18+
private iterable $applicators;
2319

2420
/**
25-
* @param OrderTaxesApplicatorInterface[] $applicators
21+
* @param iterable<OrderTaxesApplicatorInterface>|iterable $applicators
2622
*/
27-
public function __construct(string $type, array $applicators, string $euTaxZoneCode)
28-
{
29-
$this->assertApplicatorsHaveCorrectType($applicators);
23+
public function __construct(
24+
private string $type,
25+
iterable $applicators,
26+
private string $euTaxZoneCode,
27+
) {
28+
Assert::allIsInstanceOf($applicators, OrderTaxesApplicatorInterface::class);
3029

31-
$this->type = $type;
3230
$this->applicators = $applicators;
33-
$this->euTaxZoneCode = $euTaxZoneCode;
3431
}
3532

3633
#[\Override]
@@ -62,15 +59,6 @@ public function supports(OrderInterface $order, ZoneInterface $zone): bool
6259
return $channel->getTaxCalculationStrategy() === $this->type;
6360
}
6461

65-
private function assertApplicatorsHaveCorrectType(array $applicators): void
66-
{
67-
Assert::allIsInstanceOf(
68-
$applicators,
69-
OrderTaxesApplicatorInterface::class,
70-
'Order taxes applicator should have type "%2$s". Got: %s',
71-
);
72-
}
73-
7462
private function shouldSkipTaxesApplication(OrderInterface $order, ZoneInterface $zone): bool
7563
{
7664
if ($this->euTaxZoneCode === '') {

src/Validator/Constraints/EuropeanVatNumberValidator.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
*/
1717
final class EuropeanVatNumberValidator extends ConstraintValidator
1818
{
19+
/**
20+
* @psalm-suppress PossiblyUnusedMethod
21+
*/
1922
public function __construct(
2023
private readonly Vies $viesApi,
2124
private readonly LoggerInterface $logger,

tests/Behat/Context/Ui/Shop/Checkout/CheckoutAddressingContext.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Sylius\Behat\Service\SharedStorageInterface;
1212
use Sylius\Component\Core\Model\AddressInterface;
1313
use Tests\Webgriffe\SyliusItalianInvoiceableOrderPlugin\Behat\Page\Shop\Checkout\AddressPageInterface;
14+
use Tests\Webgriffe\SyliusItalianInvoiceableOrderPlugin\Behat\Service\InMemoryEuropeanVatNumberValidator;
1415
use Webgriffe\SyliusItalianInvoiceableOrderPlugin\Model\ItalianInvoiceableAddressInterface;
1516
use Webmozart\Assert\Assert;
1617

@@ -249,6 +250,7 @@ public function iShouldBeNotifiedThatTheBillingCompanyNameIsRequired(): void
249250
*/
250251
public function iSpecifyAnInvalidVatNumberForAGermanCompany(): void
251252
{
253+
InMemoryEuropeanVatNumberValidator::$isValid = false;
252254
$this->addressPage->specifyBillingVatNumber('DE123456789');
253255
}
254256

@@ -257,6 +259,7 @@ public function iSpecifyAnInvalidVatNumberForAGermanCompany(): void
257259
*/
258260
public function iSpecifyAValidBillingVatNumberForAGermanCompany(): void
259261
{
262+
InMemoryEuropeanVatNumberValidator::$isValid = true;
260263
// This is the real german company Hetzner (https://www.hetzner.com/) VAT number
261264
$this->addressPage->specifyBillingVatNumber('DE812871812');
262265
}

tests/Behat/Resources/services.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,9 @@
6868
<argument type="service" id="sylius.factory.zone" />
6969
<argument>%locale%</argument>
7070
</service>
71+
72+
<service id="webgriffe_sylius_italian_invoiceable_order.validator.european_vat_number" class="Tests\Webgriffe\SyliusItalianInvoiceableOrderPlugin\Behat\Service\InMemoryEuropeanVatNumberValidator">
73+
<tag name="validator.constraint_validator" alias="webgriffe_sylius_italian_invoiceable_order.european_vat_number_validator"/>
74+
</service>
7175
</services>
7276
</container>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Webgriffe\SyliusItalianInvoiceableOrderPlugin\Behat\Service;
6+
7+
use Symfony\Component\Validator\Constraint;
8+
use Symfony\Component\Validator\ConstraintValidator;
9+
use Webgriffe\SyliusItalianInvoiceableOrderPlugin\Validator\Constraints\EuropeanVatNumber;
10+
11+
final class InMemoryEuropeanVatNumberValidator extends ConstraintValidator
12+
{
13+
public static bool $isValid = true;
14+
15+
#[\Override]
16+
public function validate(mixed $value, Constraint $constraint): void
17+
{
18+
if (!is_string($value) || $value === '') {
19+
return;
20+
}
21+
22+
if (!$constraint instanceof EuropeanVatNumber) {
23+
return;
24+
}
25+
if (self::$isValid) {
26+
return;
27+
}
28+
29+
$format = $constraint->getFormat();
30+
$this->context->addViolation($constraint->message, ['%format%' => $format]);
31+
}
32+
}

0 commit comments

Comments
 (0)