Completed
Branch master (886cf7)
by Jan
07:19
created

PageRequestTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 2
cbo 7
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 24
cts 24
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testPageRequestExtension() 0 34 1
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),
0 ignored issues
show
Documentation introduced by
$this->createMock(\Shopw...ntityRepository::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Shopware\Core\Fra...RM\RepositoryInterface>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56 1
            $this->createMock(EntityRepository::class),
0 ignored issues
show
Documentation introduced by
$this->createMock(\Shopw...ntityRepository::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Shopware\Core\Fra...RM\RepositoryInterface>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57 1
            $customerRepository
0 ignored issues
show
Documentation introduced by
$customerRepository is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Shopware\Core\Fra...RM\RepositoryInterface>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
        );
59
60 1
        $service->saveEmail($pageRequest, $checkoutContext);
61 1
    }
62
}
63
64
class MyCustomExtension extends Struct
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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