GeoDealerServiceTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 96
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A setUpBeforeClass() 0 4 1
A testUpdateFromArrayWithoutId() 0 4 1
A testUpdateFromArrayMissingElt() 0 4 1
A testUpdateFromArrayWithRequire() 0 4 1
A tearDownAfterClass() 0 4 1
A dataRequire() 0 8 1
A dataMissingID() 0 7 1
A dataMissingElt() 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\Service;
15
16
17
use Dealer\Model\Dealer;
18
use Dealer\Model\DealerQuery;
19
use Dealer\Service\DealerService;
20
use Dealer\Service\GeoDealerService;
21
use Propel\Runtime\Propel;
22
use Symfony\Component\EventDispatcher\EventDispatcher;
23
24
class GeoDealerServiceTest extends \PHPUnit_Framework_TestCase
25
{
26
    /** @var  GeoDealerService $geoService */
27
    protected $geoService;
28
29
    /** @var  Dealer $dealer */
30
    protected $dealer;
31
32
    public function setUp()
33
    {
34
        $this->geoService = new GeoDealerService();
35
36
        $this->mockEventDispatcher = $this->getMockBuilder(EventDispatcher::class)
37
            ->setMethods(['dispatch'])
38
            ->getMock();
39
40
        $dealerService = new DealerService();
41
        $dealerService->setDispatcher($this->mockEventDispatcher);
42
43
        $this->dealer = $dealerService->createFromArray($this->dataDealerRequire());
44
45
    }
46
47
    public static function setUpBeforeClass()
48
    {
49
        Propel::getConnection()->beginTransaction();
50
    }
51
52
    /**
53
     * @covers \Dealer\Service\GeoDealerService::updateFromArray()
54
     */
55
    public function testUpdateFromArrayWithoutId(){
56
        $dealer = $this->geoService->updateFromArray($this->dataMissingID());
57
        $this->assertNull($dealer);
58
    }
59
60
    /**
61
     * @covers \Dealer\Service\GeoDealerService::updateFromArray()
62
     */
63
    public function testUpdateFromArrayMissingElt(){
64
        $dealer = $this->geoService->updateFromArray($this->dataMissingElt());
65
        $this->assertEquals($dealer, DealerQuery::create()->findOneById($dealer->getId()));
66
    }
67
68
    /**
69
     * @covers \Dealer\Service\GeoDealerService::updateFromArray()
70
     */
71
    public function testUpdateFromArrayWithRequire(){
72
        $dealer = $this->geoService->updateFromArray($this->dataRequire());
73
        $this->assertEquals($dealer, DealerQuery::create()->findOneById($dealer->getId()));
74
    }
75
76
    public static function tearDownAfterClass()
77
    {
78
        Propel::getConnection()->rollBack();
79
    }
80
81
82
83
    protected function dataRequire()
84
    {
85
        return [
86
            'id' => $this->dealer->getId(),
87
            'latitude' => 5.1234,
88
            'longitude' => 0.23587
89
        ];
90
    }
91
92
    protected function dataMissingID()
93
    {
94
        return [
95
            'latitude' => 5.1234,
96
            'longitude' => 0.23587
97
        ];
98
    }
99
100
    protected function dataMissingElt()
101
    {
102
        return [
103
            'id' => $this->dealer->getId(),
104
            'longitude' => 0.23587
105
        ];
106
    }
107
108
    protected function dataDealerRequire()
109
    {
110
        return [
111
            "title" => "Openstudio",
112
            "address1" => "5 rue jean rochon",
113
            "zipcode" => "63000",
114
            "city" => "test",
115
            "country_id" => "64",
116
        ];
117
    }
118
119
}
120