Completed
Push — master ( f3ae79...9c48b0 )
by Daniel
02:18
created

JobWithBrazilianLocationsBuilderTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 6
Bugs 0 Features 1
Metric Value
wmc 6
c 6
b 0
f 1
lcom 1
cbo 3
dl 18
loc 108
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testFromApiThrowsCareerjetExceptionWhenLocationIsNotPresent() 0 7 1
A testLocationIsBrasil() 9 9 1
A testLocationIsStateCityComposition() 9 9 1
A testLocationsAsStateNameSetsShortStateOnJob() 0 9 1
B statesDataProvider() 0 44 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Jobles\Tests\Careerjet\Builder;
4
5
use Jobles\Careerjet\Builder\JobWithBrazilianLocationsBuilder;
6
use Jobles\Core\Job\Job;
7
8
class JobWithBrazilianLocationsBuilderTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @var \stdClass
12
     */
13
    private $apiJob;
14
15
    /**
16
     * @var Job
17
     */
18
    private $job;
19
20
    public function setUp()
21
    {
22
        $this->apiJob = new \stdClass;
23
        $this->job = new Job;
24
        $this->job->setCountry('Brazil');
25
    }
26
27
    public function testFromApiThrowsCareerjetExceptionWhenLocationIsNotPresent()
28
    {
29
        $this->expectException(\Jobles\Careerjet\Exception\CareerjetException::class);
30
        $this->expectExceptionMessage('Invalid API job');
31
32
        JobWithBrazilianLocationsBuilder::fromApi(new \stdClass, new Job);
33
    }
34
35 View Code Duplication
    public function testLocationIsBrasil()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $this->apiJob->locations = 'Brasil';
38
        $this->job = JobWithBrazilianLocationsBuilder::fromApi($this->apiJob, $this->job);
39
40
        $this->assertNull($this->job->getState());
41
        $this->assertNull($this->job->getCity());
42
        $this->assertEquals('Brazil', $this->job->getCountry());
43
    }
44
45 View Code Duplication
    public function testLocationIsStateCityComposition()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $this->apiJob->locations = 'São Paulo - SP';
48
        $this->job = JobWithBrazilianLocationsBuilder::fromApi($this->apiJob, $this->job);
49
50
        $this->assertEquals('SP', $this->job->getState());
51
        $this->assertEquals('São Paulo', $this->job->getCity());
52
        $this->assertEquals('Brazil', $this->job->getCountry());
53
    }
54
55
    /**
56
     * @dataProvider statesDataProvider
57
     * @param $stateName
58
     * @param $shortState
59
     * @throws \Jobles\Careerjet\Exception\CareerjetException
60
     */
61
    public function testLocationsAsStateNameSetsShortStateOnJob($stateName, $shortState)
62
    {
63
        $this->apiJob->locations = $stateName;
64
        $this->job = JobWithBrazilianLocationsBuilder::fromApi($this->apiJob, $this->job);
65
66
        $this->assertEquals($shortState, $this->job->getState());
67
        $this->assertNull($this->job->getCity());
68
        $this->assertEquals('Brazil', $this->job->getCountry());
69
    }
70
71
    public function statesDataProvider()
72
    {
73
        return [
74
            ['Acre', 'AC'],
75
            ['Alagoas', 'AL'],
76
            ['Amapá', 'AP'],
77
            ['Amapa', 'AP'],
78
            ['Amazonas', 'AM'],
79
            ['Bahia', 'BA'],
80
            ['Ceará', 'CE'],
81
            ['Ceara', 'CE'],
82
            ['Distrito-Federal', 'DF'],
83
            ['Distrito Federal', 'DF'],
84
            ['Espírito Santo', 'ES'],
85
            ['Espirito Santo', 'ES'],
86
            ['Goiás', 'GO'],
87
            ['Goias', 'GO'],
88
            ['Maranhão', 'MA'],
89
            ['Maranhao', 'MA'],
90
            ['Mato Grosso', 'MT'],
91
            ['Mato Grosso do Sul', 'MS'],
92
            ['Minas Gerais', 'MG'],
93
            ['Pará', 'PA'],
94
            ['Para', 'PA'],
95
            ['Paraíba', 'PB'],
96
            ['Paraiba', 'PB'],
97
            ['Paraná', 'PR'],
98
            ['Parana', 'PR'],
99
            ['Pernambuco', 'PE'],
100
            ['Piauí', 'PI'],
101
            ['Piaui', 'PI'],
102
            ['Rio de Janeiro', 'RJ'],
103
            ['Rio Grande do Norte', 'RN'],
104
            ['Rio Grande do Sul', 'RS'],
105
            ['Rondônia', 'RO'],
106
            ['Rondonia', 'RO'],
107
            ['Roraima', 'RR'],
108
            ['Santa Catarina', 'SC'],
109
            ['São Paulo', 'SP'],
110
            ['Sao Paulo', 'SP'],
111
            ['Sergipe', 'SE'],
112
            ['Tocantins', 'TO'],
113
        ];
114
    }
115
}
116