Completed
Push — master ( 860366...55daec )
by Kamil
19:37
created

TestUserFactorySpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_user_provider_interface() 0 4 1
A it_creates_user_with_customer() 0 20 1
A it_creates_default_user_with_customer() 0 20 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace spec\Sylius\Bundle\CoreBundle\Test\Factory;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Core\Model\CustomerInterface;
16
use Sylius\Component\Core\Model\UserInterface;
17
use Sylius\Component\Core\Test\Factory\TestUserFactoryInterface;
18
use Sylius\Component\Resource\Factory\FactoryInterface;
19
20
/**
21
 * @author Mateusz Zalewski <[email protected]>
22
 */
23
class TestUserFactorySpec extends ObjectBehavior
24
{
25
    function let(FactoryInterface $customerFactory, FactoryInterface $userFactory)
26
    {
27
        $this->beConstructedWith($customerFactory, $userFactory);
28
    }
29
30
    function it_is_initializable()
31
    {
32
        $this->shouldHaveType('Sylius\Bundle\CoreBundle\Test\Factory\TestUserFactory');
33
    }
34
35
    function it_implements_user_provider_interface()
36
    {
37
        $this->shouldImplement(TestUserFactoryInterface::class);
38
    }
39
40
    function it_creates_user_with_customer(
41
        $customerFactory,
42
        $userFactory,
43
        CustomerInterface $customer,
44
        UserInterface $user
45
    ) {
46
        $customerFactory->createNew()->willReturn($customer);
47
        $customer->setFirstName('Oliver')->shouldBeCalled();
48
        $customer->setLastName('Queen')->shouldBeCalled();
49
50
        $userFactory->createNew()->willReturn($user);
51
52
        $user->setCustomer($customer)->shouldBeCalled();
53
        $user->setUsername('[email protected]')->shouldBeCalled();
54
        $user->setEmail('[email protected]')->shouldBeCalled();
55
        $user->setPlainPassword('a££ow')->shouldBeCalled();
56
        $user->enable()->shouldBeCalled();
57
58
        $this->create('[email protected]', 'a££ow', 'Oliver', 'Queen')->shouldReturn($user);
59
    }
60
61
    function it_creates_default_user_with_customer(
62
        $customerFactory,
63
        $userFactory,
64
        CustomerInterface $customer,
65
        UserInterface $user
66
    ) {
67
        $customerFactory->createNew()->willReturn($customer);
68
        $customer->setFirstName('John')->shouldBeCalled();
69
        $customer->setLastName('Doe')->shouldBeCalled();
70
71
        $userFactory->createNew()->willReturn($user);
72
73
        $user->setCustomer($customer)->shouldBeCalled();
74
        $user->setUsername('[email protected]')->shouldBeCalled();
75
        $user->setEmail('[email protected]')->shouldBeCalled();
76
        $user->setPlainPassword('password123')->shouldBeCalled();
77
        $user->enable()->shouldBeCalled();
78
79
        $this->createDefault()->shouldReturn($user);
80
    }
81
}
82