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

testFromApiThrowsCareerjetExceptionWhenLocationIsNotPresent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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