Skip to content

Commit 5b0feb7

Browse files
committed
Implement changes based on CR
1 parent 5e629f0 commit 5b0feb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+319
-143
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"phpstan/phpstan-doctrine": "^1.5",
4343
"phpstan/phpstan-symfony": "^1.4",
4444
"phpstan/phpstan-webmozart-assert": "^1.2",
45-
"phpunit/phpunit": "^9.5",
45+
"phpunit/phpunit": "^10.5",
4646
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
4747
"sylius-labs/coding-standard": "^4.4",
4848
"sylius/test-application": "^2.0.0@alpha",

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<phpunit
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.1/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
66
colors="true"
77
bootstrap="vendor/sylius/test-application/config/bootstrap.php"
88
>

tests/Application/src/Kernel.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Sylius\InvoicingPlugin\Application;
6+
7+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
8+
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
9+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
10+
use Symfony\Component\Config\Loader\LoaderInterface;
11+
use Symfony\Component\DependencyInjection\ContainerBuilder;
12+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
13+
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
14+
15+
final class Kernel extends BaseKernel
16+
{
17+
use MicroKernelTrait;
18+
19+
public function registerBundles(): iterable
20+
{
21+
$contents = require $this->getProjectDir() . '/tests/TestApplication/bundles.php';
22+
23+
foreach ($contents as $class => $envs) {
24+
if ($envs[$this->environment] ?? $envs['all'] ?? false) {
25+
yield new $class();
26+
}
27+
}
28+
}
29+
30+
public function getProjectDir(): string
31+
{
32+
return \dirname(__DIR__, 3);
33+
}
34+
35+
protected function configureContainer(ContainerConfigurator $container): void
36+
{
37+
$container->import('../TestApplication/config/config.yaml');
38+
39+
if (is_file(\dirname(__DIR__) . '/TestApplication/config/services_test.php')) {
40+
$container->import('../TestApplication/config/services_test.php');
41+
}
42+
}
43+
44+
protected function configureRoutes(RoutingConfigurator $routes): void
45+
{
46+
$routes->import('../TestApplication/config/routes.yaml');
47+
}
48+
}

tests/Unit/Command/SendInvoiceEmailTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
namespace Tests\Sylius\InvoicingPlugin\Unit\Command;
1515

16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\TestCase;
1718
use Sylius\InvoicingPlugin\Command\SendInvoiceEmail;
1819

1920
final class SendInvoiceEmailTest extends TestCase
2021
{
21-
/** @test */
22+
#[Test]
2223
public function it_represents_an_intention_to_send_email_containing_invoice(): void
2324
{
2425
$command = new SendInvoiceEmail('0000001');

tests/Unit/CommandHandler/SendInvoiceEmailHandlerTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Tests\Sylius\InvoicingPlugin\Unit\CommandHandler;
1515

16+
use PHPUnit\Framework\Attributes\Test;
1617
use PHPUnit\Framework\MockObject\MockObject;
1718
use PHPUnit\Framework\TestCase;
1819
use Sylius\Component\Core\Model\CustomerInterface;
@@ -48,7 +49,7 @@ protected function setUp(): void
4849
);
4950
}
5051

51-
/** @test */
52+
#[Test]
5253
public function it_requests_an_email_with_an_invoice_to_be_sent(): void
5354
{
5455
$invoice = $this->createMock(InvoiceInterface::class);
@@ -85,7 +86,7 @@ public function it_requests_an_email_with_an_invoice_to_be_sent(): void
8586
($this->handler)(new SendInvoiceEmail('0000001'));
8687
}
8788

88-
/** @test */
89+
#[Test]
8990
public function it_does_not_request_an_email_to_be_sent_if_order_was_not_found(): void
9091
{
9192
$this->orderRepository
@@ -105,7 +106,7 @@ public function it_does_not_request_an_email_to_be_sent_if_order_was_not_found()
105106
($this->handler)(new SendInvoiceEmail('0000001'));
106107
}
107108

108-
/** @test */
109+
#[Test]
109110
public function it_does_not_request_an_email_to_be_sent_if_customer_was_not_found(): void
110111
{
111112
$order = $this->createMock(OrderInterface::class);
@@ -132,7 +133,7 @@ public function it_does_not_request_an_email_to_be_sent_if_customer_was_not_foun
132133
($this->handler)(new SendInvoiceEmail('0000001'));
133134
}
134135

135-
/** @test */
136+
#[Test]
136137
public function it_does_not_request_an_email_to_be_sent_if_invoice_was_not_found(): void
137138
{
138139
$order = $this->createMock(OrderInterface::class);

tests/Unit/Converter/OrderItemUnitsToLineItemsConverterTest.php

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Tests\Sylius\InvoicingPlugin\Unit\Converter;
1515

1616
use Doctrine\Common\Collections\ArrayCollection;
17+
use PHPUnit\Framework\Attributes\Test;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920
use Sylius\Component\Core\Model\OrderInterface;
@@ -51,13 +52,13 @@ protected function setUp(): void
5152
);
5253
}
5354

54-
/** @test */
55+
#[Test]
5556
public function it_implements_line_items_converter_interface(): void
5657
{
5758
self::assertInstanceOf(LineItemsConverterInterface::class, $this->converter);
5859
}
5960

60-
/** @test */
61+
#[Test]
6162
public function it_extracts_line_items_from_order_item_units(): void
6263
{
6364
$lineItem = $this->createMock(LineItemInterface::class);
@@ -104,7 +105,7 @@ public function it_extracts_line_items_from_order_item_units(): void
104105
self::assertEquals([$lineItem], $result);
105106
}
106107

107-
/** @test */
108+
#[Test]
108109
public function it_groups_the_same_line_items_during_extracting_order_item_units(): void
109110
{
110111
$mjolnirLineItem = $this->createMock(LineItemInterface::class);
@@ -121,12 +122,24 @@ public function it_groups_the_same_line_items_during_extracting_order_item_units
121122
$this->lineItemFactory
122123
->expects($this->exactly(3))
123124
->method('createWithData')
124-
->withConsecutive(
125-
['Mjolnir', 1, 5000, 5000, 5000, 500, 5500, null, 'MJOLNIR', '10%'],
126-
['Mjolnir', 1, 5000, 5000, 5000, 500, 5500, null, 'MJOLNIR', '10%'],
127-
['Stormbreaker', 1, 8000, 8000, 8000, 1600, 9600, null, 'STORMBREAKER', '20%'],
128-
)
129-
->willReturnOnConsecutiveCalls($mjolnirLineItem, $mjolnirLineItem, $stormbreakerLineItem);
125+
->willReturnCallback(function (...$args) use ($mjolnirLineItem, $stormbreakerLineItem) {
126+
static $callCount = 0;
127+
++$callCount;
128+
129+
if ($callCount === 1) {
130+
$this->assertEquals(['Mjolnir', 1, 5000, 5000, 5000, 500, 5500, null, 'MJOLNIR', '10%'], $args);
131+
132+
return $mjolnirLineItem;
133+
}
134+
if ($callCount === 2) {
135+
$this->assertEquals(['Mjolnir', 1, 5000, 5000, 5000, 500, 5500, null, 'MJOLNIR', '10%'], $args);
136+
137+
return $mjolnirLineItem;
138+
}
139+
$this->assertEquals(['Stormbreaker', 1, 8000, 8000, 8000, 1600, 9600, null, 'STORMBREAKER', '20%'], $args);
140+
141+
return $stormbreakerLineItem;
142+
});
130143

131144
$mjolnirLineItem
132145
->expects($this->exactly(2))
@@ -161,8 +174,24 @@ public function it_groups_the_same_line_items_during_extracting_order_item_units
161174
$this->unitNetPriceProvider
162175
->expects($this->exactly(3))
163176
->method('getUnitNetPrice')
164-
->withConsecutive([$firstOrderItemUnit], [$secondOrderItemUnit], [$thirdOrderItemUnit])
165-
->willReturnOnConsecutiveCalls(5000, 5000, 8000);
177+
->willReturnCallback(function ($unit) use ($firstOrderItemUnit, $secondOrderItemUnit, $thirdOrderItemUnit) {
178+
static $callCount = 0;
179+
++$callCount;
180+
181+
if ($callCount === 1) {
182+
$this->assertSame($firstOrderItemUnit, $unit);
183+
184+
return 5000;
185+
}
186+
if ($callCount === 2) {
187+
$this->assertSame($secondOrderItemUnit, $unit);
188+
189+
return 5000;
190+
}
191+
$this->assertSame($thirdOrderItemUnit, $unit);
192+
193+
return 8000;
194+
});
166195

167196
// Second order item unit setup
168197
$secondOrderItemUnit->expects(self::once())->method('getTaxTotal')->willReturn(500);
@@ -188,8 +217,24 @@ public function it_groups_the_same_line_items_during_extracting_order_item_units
188217
$this->taxRatePercentageProvider
189218
->expects($this->exactly(3))
190219
->method('provideFromAdjustable')
191-
->withConsecutive([$firstOrderItemUnit], [$secondOrderItemUnit], [$thirdOrderItemUnit])
192-
->willReturnOnConsecutiveCalls('10%', '10%', '20%');
220+
->willReturnCallback(function ($unit) use ($firstOrderItemUnit, $secondOrderItemUnit, $thirdOrderItemUnit) {
221+
static $callCount = 0;
222+
++$callCount;
223+
224+
if ($callCount === 1) {
225+
$this->assertSame($firstOrderItemUnit, $unit);
226+
227+
return '10%';
228+
}
229+
if ($callCount === 2) {
230+
$this->assertSame($secondOrderItemUnit, $unit);
231+
232+
return '10%';
233+
}
234+
$this->assertSame($thirdOrderItemUnit, $unit);
235+
236+
return '20%';
237+
});
193238

194239
$result = $this->converter->convert($order);
195240

tests/Unit/Converter/ShippingAdjustmentsToLineItemsConverterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Tests\Sylius\InvoicingPlugin\Unit\Converter;
1515

1616
use Doctrine\Common\Collections\ArrayCollection;
17+
use PHPUnit\Framework\Attributes\Test;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920
use Sylius\Component\Core\Model\AdjustmentInterface;
@@ -45,13 +46,13 @@ protected function setUp(): void
4546
);
4647
}
4748

48-
/** @test */
49+
#[Test]
4950
public function it_implements_line_items_converter_interface(): void
5051
{
5152
self::assertInstanceOf(LineItemsConverterInterface::class, $this->converter);
5253
}
5354

54-
/** @test */
55+
#[Test]
5556
public function it_extracts_line_items_from_orders_shipping_adjustments(): void
5657
{
5758
$lineItem = $this->createMock(LineItemInterface::class);

tests/Unit/Converter/TaxItemsConverterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Tests\Sylius\InvoicingPlugin\Unit\Converter;
1515

1616
use Doctrine\Common\Collections\ArrayCollection;
17+
use PHPUnit\Framework\Attributes\Test;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920
use Sylius\Component\Core\Model\AdjustmentInterface;
@@ -43,13 +44,13 @@ protected function setUp(): void
4344
);
4445
}
4546

46-
/** @test */
47+
#[Test]
4748
public function it_implements_tax_items_converter_interface(): void
4849
{
4950
self::assertInstanceOf(TaxItemsConverterInterface::class, $this->converter);
5051
}
5152

52-
/** @test */
53+
#[Test]
5354
public function it_extracts_tax_items_from_order(): void
5455
{
5556
$taxItem = $this->createMock(TaxItemInterface::class);

tests/Unit/Creator/InvoiceCreatorTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Tests\Sylius\InvoicingPlugin\Unit\Creator;
1515

1616
use Doctrine\ORM\EntityNotFoundException;
17+
use PHPUnit\Framework\Attributes\Test;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
1920
use Sylius\Component\Core\Model\OrderInterface;
@@ -60,13 +61,13 @@ protected function setUp(): void
6061
);
6162
}
6263

63-
/** @test */
64+
#[Test]
6465
public function it_implements_invoice_for_order_creator_interface(): void
6566
{
6667
self::assertInstanceOf(InvoiceCreatorInterface::class, $this->creator);
6768
}
6869

69-
/** @test */
70+
#[Test]
7071
public function it_creates_invoice_for_order(): void
7172
{
7273
$order = $this->createMock(OrderInterface::class);
@@ -111,7 +112,7 @@ public function it_creates_invoice_for_order(): void
111112
($this->creator)('0000001', $invoiceDateTime);
112113
}
113114

114-
/** @test */
115+
#[Test]
115116
public function it_creates_invoice_without_generating_pdf_file(): void
116117
{
117118
$creator = new InvoiceCreator(
@@ -161,7 +162,7 @@ public function it_creates_invoice_without_generating_pdf_file(): void
161162
$creator('0000001', $invoiceDateTime);
162163
}
163164

164-
/** @test */
165+
#[Test]
165166
public function it_removes_saved_invoice_file_if_database_update_fails(): void
166167
{
167168
$order = $this->createMock(OrderInterface::class);
@@ -212,7 +213,7 @@ public function it_removes_saved_invoice_file_if_database_update_fails(): void
212213
($this->creator)('0000001', $invoiceDateTime);
213214
}
214215

215-
/** @test */
216+
#[Test]
216217
public function it_throws_an_exception_when_invoice_was_already_created_for_given_order(): void
217218
{
218219
$order = $this->createMock(OrderInterface::class);

0 commit comments

Comments
 (0)