ContactInfoLoopTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\ContactInfoLoop;
18
use Dealer\Model\DealerContactInfo;
19
use Dealer\Model\Dealer;
20
use Dealer\Model\DealerContact;
21
use Dealer\Service\ContactInfoService;
22
use Dealer\Service\ContactService;
23
use Dealer\Service\DealerService;
24
use Dealer\Test\PhpUnit\Base\AbstractPropelTest;
25
use Propel\Runtime\Util\PropelModelPager;
26
use Symfony\Component\DependencyInjection\ContainerBuilder;
27
use Symfony\Component\EventDispatcher\EventDispatcher;
28
29
class ContactInfoLoopTest extends AbstractPropelTest
30
{
31
    /** @var  ContactInfoLoop $loop */
32
    protected $loop;
33
34
    /** @var  Dealer $dealer */
35
    protected $dealer;
36
37
    /** @var  DealerContact $dealer */
38
    protected $contact;
39
40
    /** @var  DealerContactInfo $dealer */
41
    protected $contactInfo;
42
43
    /**
44
     * @inheritDoc
45
     */
46
    protected function buildContainer(ContainerBuilder $container)
47
    {
48
49
    }
50
51
    /**
52
     * Expected possible values for the order loop argument.
53
     * @var array
54
     */
55
    protected static $VALID_ORDER = [
56
        'id',
57
        'id-reverse',
58
        'value',
59
        'value-reverse',
60
    ];
61
62
    public function setUp()
63
    {
64
        $this->loop = new ContactInfoLoop($this->container);
65
66
        $this->mockEventDispatcher = $this->getMockBuilder(EventDispatcher::class)
67
            ->setMethods(['dispatch'])
68
            ->getMock();
69
70
        /* Create Test Dealer */
71
        $dealerService = new DealerService();
72
        $dealerService->setDispatcher($this->mockEventDispatcher);
73
        $this->dealer = $dealerService->createFromArray($this->dataDealerRequire(), "fr_FR");
74
75
        /* Create Test Contact */
76
        $contactService = new ContactService();
77
        $contactService->setDispatcher($this->mockEventDispatcher);
78
        $this->contact = $contactService->createFromArray($this->dataContactRequire(), "fr_FR");
79
80
        /* Create Test Contact Info */
81
        $contactInfoService = new ContactInfoService();
82
        $contactInfoService->setDispatcher($this->mockEventDispatcher);
83
        $this->contactInfo = $contactInfoService->createFromArray($this->dataContactInfoRequire(), "fr_FR");
84
    }
85
86
    /**
87
     * @covers \Dealer\Loop\ContactInfoLoop::initializeArgs()
88
     */
89
    public function testHasNoMandatoryArguments()
90
    {
91
        $this->loop->initializeArgs([]);
92
    }
93
94
    /**
95
     * @covers \Dealer\Loop\ContactInfoLoop::initializeArgs()
96
     */
97
    public function testAcceptsAllOrderArguments()
98
    {
99
        foreach (static::$VALID_ORDER as $order) {
100
            $this->loop->initializeArgs(["order" => $order]);
101
        }
102
    }
103
104
    /**
105
     * @covers \Dealer\Loop\ContactInfoLoop::initializeArgs()
106
     */
107
    public function testAcceptsAllArguments()
108
    {
109
        $this->loop->initializeArgs($this->getTestArg());
110
    }
111
112
    /**
113
     * @covers \Dealer\Loop\ContactInfoLoop::buildModelCriteria()
114
     * @covers \Dealer\Loop\ContactInfoLoop::exec()
115
     * @covers \Dealer\Loop\ContactInfoLoop::parseResults()
116
     */
117
    public function testHasExpectedOutput()
118
    {
119
        $this->loop->initializeArgs($this->getTestArg());
120
        $loopResult = $this->loop->exec(
121
            new PropelModelPager($this->loop->buildModelCriteria())
122
        );
123
124
        $this->assertEquals(1, $loopResult->getCount());
125
        $loopResult->rewind();
126
        $loopResultRow = $loopResult->current();
127
        $this->assertEquals($this->contactInfo->getId(), $loopResultRow->get("ID"));
128
        $this->assertEquals($this->contactInfo->getContactId(), $loopResultRow->get("CONTACT_ID"));
129
        $this->assertEquals($this->contactInfo->getContactType(), $loopResultRow->get("CONTACT_TYPE"));
130
        $this->assertEquals($this->contactInfo->getContactTypeId(), $loopResultRow->get("CONTACT_TYPE_ID"));
131
        $this->assertEquals($this->contactInfo->getValue(), $loopResultRow->get("VALUE"));
132
    }
133
134
135
    protected function getTestArg()
136
    {
137
        return [
138
            "id" => $this->contactInfo->getId(),
139
            "contact_id" => $this->contactInfo->getContactId(),
140
        ];
141
    }
142
143
    protected function dataContactInfoRequire()
144
    {
145
        return [
146
            "value" => "email",
147
            "type" => 0,
148
            "contact_id" => $this->contact->getId(),
149
        ];
150
    }
151
152
    protected function dataContactRequire()
153
    {
154
        return [
155
            "label" => "Openstudio",
156
            "dealer_id" => $this->dealer->getId()
157
        ];
158
    }
159
160
    protected function dataDealerRequire()
161
    {
162
        return [
163
            "title" => "Openstudio",
164
            "address1" => "5 rue jean rochon",
165
            "zipcode" => "63000",
166
            "city" => "test",
167
            "country_id" => "64",
168
        ];
169
    }
170
}
171