|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Test; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use Shopware\Core\Checkout\Test\Cart\Common\Generator; |
|
7
|
|
|
use Shopware\Core\Framework\ORM\EntityRepository; |
|
8
|
|
|
use Shopware\Core\Framework\ORM\Event\EntityWrittenContainerEvent; |
|
9
|
|
|
use Shopware\Core\Framework\Struct\Struct; |
|
10
|
|
|
use Shopware\Storefront\Page\Account\AccountService; |
|
11
|
|
|
use Shopware\Storefront\Page\Account\EmailSaveRequest; |
|
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; |
|
13
|
|
|
|
|
14
|
|
|
class PageRequestTest extends KernelTestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var \Doctrine\DBAL\Connection |
|
18
|
|
|
*/ |
|
19
|
|
|
private $connection; |
|
20
|
|
|
|
|
21
|
1 |
|
public function setUp() |
|
22
|
|
|
{ |
|
23
|
1 |
|
self::bootKernel(); |
|
24
|
|
|
|
|
25
|
1 |
|
$this->connection = self::$container->get(Connection::class); |
|
26
|
1 |
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
public function testPageRequestExtension() |
|
29
|
|
|
{ |
|
30
|
1 |
|
$checkoutContext = Generator::createContext(); |
|
31
|
|
|
|
|
32
|
1 |
|
$extension = new MyCustomExtension('property value'); |
|
33
|
|
|
|
|
34
|
1 |
|
$pageRequest = new EmailSaveRequest(); |
|
35
|
1 |
|
$pageRequest->addExtension('customExtension', $extension); |
|
36
|
|
|
|
|
37
|
|
|
$originalData = [[ |
|
38
|
1 |
|
'id' => $checkoutContext->getCustomer()->getId(), |
|
39
|
1 |
|
'customExtension' => $extension, |
|
40
|
|
|
]]; |
|
41
|
|
|
|
|
42
|
|
|
// array merge recrusive |
|
43
|
1 |
|
$customerRepository = $this->createMock(EntityRepository::class); |
|
44
|
1 |
|
$customerRepository->expects($this->once()) |
|
45
|
1 |
|
->method('update') |
|
46
|
1 |
|
->will($this->returnCallback( |
|
47
|
|
|
function ($data) use ($originalData) { |
|
48
|
1 |
|
$this->assertEquals($originalData, $data); |
|
49
|
|
|
|
|
50
|
1 |
|
return $this->createMock(EntityWrittenContainerEvent::class); |
|
51
|
1 |
|
} |
|
52
|
|
|
)); |
|
53
|
|
|
|
|
54
|
1 |
|
$service = new AccountService( |
|
55
|
1 |
|
$this->createMock(EntityRepository::class), |
|
|
|
|
|
|
56
|
1 |
|
$this->createMock(EntityRepository::class), |
|
|
|
|
|
|
57
|
1 |
|
$customerRepository |
|
|
|
|
|
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
1 |
|
$service->saveEmail($pageRequest, $checkoutContext); |
|
61
|
1 |
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
class MyCustomExtension extends Struct |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
/** |
|
67
|
|
|
* @var string |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $myCustomProperty; |
|
70
|
|
|
|
|
71
|
1 |
|
public function __construct(string $myCustomExtension) |
|
72
|
|
|
{ |
|
73
|
1 |
|
$this->myCustomProperty = $myCustomExtension; |
|
74
|
1 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getMyCustomProperty(): string |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->myCustomProperty; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function setMyCustomProperty(string $myCustomProperty): void |
|
82
|
|
|
{ |
|
83
|
|
|
$this->myCustomProperty = $myCustomProperty; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: