ContactLoopTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 122
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A buildContainer() 0 4 1
A setUp() 0 18 1
A testHasNoMandatoryArguments() 0 4 1
A testAcceptsAllOrderArguments() 0 6 2
A testAcceptsAllArguments() 0 4 1
A testHasExpectedOutput() 0 14 1
A getTestArg() 0 7 1
A dataContactRequire() 0 7 1
A dataDealerRequire() 0 10 1
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
/*************************************************************************************/
13
14
namespace Dealer\Test\Loop;
15
16
17
use Dealer\Loop\ContactLoop;
18
use Dealer\Model\Dealer;
19
use Dealer\Model\DealerContact;
20
use Dealer\Service\ContactService;
21
use Dealer\Service\DealerService;
22
use Dealer\Test\PhpUnit\Base\AbstractPropelTest;
23
use Propel\Runtime\Util\PropelModelPager;
24
use Symfony\Component\DependencyInjection\ContainerBuilder;
25
use Symfony\Component\EventDispatcher\EventDispatcher;
26
27
class ContactLoopTest extends AbstractPropelTest
28
{
29
    /** @var  ContactLoop $loop */
30
    protected $loop;
31
32
    /** @var  Dealer $dealer */
33
    protected $dealer;
34
35
    /** @var  DealerContact $dealer */
36
    protected $contact;
37
38
    /**
39
     * Expected possible values for the order loop argument.
40
     * @var array
41
     */
42
    protected static $VALID_ORDER = [
43
        'id',
44
        'id-reverse',
45
        'label',
46
        'label-reverse',
47
    ];
48
49
    /**
50
     * @inheritDoc
51
     */
52
    protected function buildContainer(ContainerBuilder $container)
53
    {
54
55
    }
56
57
    public function setUp()
58
    {
59
        $this->loop = new ContactLoop($this->container);
60
61
        $this->mockEventDispatcher = $this->getMockBuilder(EventDispatcher::class)
62
            ->setMethods(['dispatch'])
63
            ->getMock();
64
65
        /* Create Test Dealer */
66
        $dealerService = new DealerService();
67
        $dealerService->setDispatcher($this->mockEventDispatcher);
68
        $this->dealer = $dealerService->createFromArray($this->dataDealerRequire(), "fr_FR");
69
70
        /* Create Test Contact */
71
        $contactService = new ContactService();
72
        $contactService->setDispatcher($this->mockEventDispatcher);
73
        $this->contact = $contactService->createFromArray($this->dataContactRequire(),"fr_FR");
74
    }
75
76
    /**
77
     * @covers \Dealer\Loop\ContactLoop::initializeArgs()
78
     */
79
    public function testHasNoMandatoryArguments()
80
    {
81
        $this->loop->initializeArgs([]);
82
    }
83
84
    /**
85
     * @covers \Dealer\Loop\ContactLoop::initializeArgs()
86
     */
87
    public function testAcceptsAllOrderArguments()
88
    {
89
        foreach (static::$VALID_ORDER as $order) {
90
            $this->loop->initializeArgs(["order" => $order]);
91
        }
92
    }
93
94
    /**
95
     * @covers \Dealer\Loop\ContactLoop::initializeArgs()
96
     */
97
    public function testAcceptsAllArguments()
98
    {
99
        $this->loop->initializeArgs($this->getTestArg());
100
    }
101
102
    /**
103
     * @covers \Dealer\Loop\ContactLoop::buildModelCriteria()
104
     * @covers \Dealer\Loop\ContactLoop::exec()
105
     * @covers \Dealer\Loop\ContactLoop::parseResults()
106
     */
107
    public function testHasExpectedOutput()
108
    {
109
        $this->loop->initializeArgs($this->getTestArg());
110
        $loopResult = $this->loop->exec(
111
            new PropelModelPager($this->loop->buildModelCriteria())
112
        );
113
114
        $this->assertEquals(1,$loopResult->getCount());
115
        $loopResult->rewind();
116
        $loopResultRow = $loopResult->current();
117
        $this->assertEquals($this->contact->getId(), $loopResultRow->get("ID"));
118
        $this->assertEquals($this->contact->getDealerId(), $loopResultRow->get("DEALER_ID"));
119
        $this->assertEquals($this->contact->getIsDefault(), $loopResultRow->get("IS_DEFAULT"));
120
    }
121
122
    protected function getTestArg()
123
    {
124
        return [
125
            "id" => $this->contact->getId(),
126
            "dealer_id" => $this->contact->getDealerId(),
127
        ];
128
    }
129
130
    protected function dataContactRequire()
131
    {
132
        return [
133
            "label" => "Openstudio",
134
            "dealer_id" => $this->dealer->getId()
135
        ];
136
    }
137
138
    protected function dataDealerRequire()
139
    {
140
        return [
141
            "title" => "Openstudio",
142
            "address1" => "5 rue jean rochon",
143
            "zipcode" => "63000",
144
            "city" => "test",
145
            "country_id" => "64",
146
        ];
147
    }
148
}
149