AresTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 8
Bugs 1 Features 0
Metric Value
wmc 11
c 8
b 1
f 0
lcom 1
cbo 4
dl 0
loc 87
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testFindByIdentificationNumber() 0 12 1
A testFindByIdentificationNumberWithLeadingZeros() 0 5 1
A testFindByIdentificationNumberException() 0 4 1
A testFindByEmptyStringException() 0 4 1
A testGetCompanyPeople() 0 11 2
A testBalancer() 0 15 2
A isTravis() 0 8 2
1
<?php
2
3
namespace Defr\Ares\Tests;
4
5
use Defr\Ares;
6
use PHPUnit_Framework_TestCase;
7
8
final class AresTest extends PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @var Ares
12
     */
13
    private $ares;
14
15
    protected function setUp()
16
    {
17
        $this->ares = new Ares();
18
    }
19
20
    public function testFindByIdentificationNumber()
21
    {
22
        $record = $this->ares->findByIdentificationNumber(73263753);
23
        $this->assertSame('Dennis Fridrich', $record->getCompanyName());
24
        $this->assertSame('CZ8508095453', $record->getTaxId());
25
        $this->assertSame('73263753', $record->getCompanyId());
26
        $this->assertEmpty($record->getStreet());
27
        $this->assertSame('15', $record->getStreetHouseNumber());
28
        $this->assertEmpty($record->getStreetOrientationNumber());
29
        $this->assertSame('Petrovice - Obděnice', $record->getTown());
30
        $this->assertSame('26255', $record->getZip());
31
    }
32
33
    public function testFindByIdentificationNumberWithLeadingZeros()
34
    {
35
        $record = $this->ares->findByIdentificationNumber('00006947');
36
        $this->assertSame('00006947', $record->getCompanyId());
37
    }
38
39
    /**
40
     * @expectedException \Defr\Ares\AresException
41
     */
42
    public function testFindByIdentificationNumberException()
43
    {
44
        $this->ares->findByIdentificationNumber('A1234');
45
    }
46
47
    /**
48
     * @expectedException \Defr\Ares\AresException
49
     */
50
    public function testFindByEmptyStringException()
51
    {
52
        $this->ares->findByIdentificationNumber('');
53
    }
54
55
    public function testGetCompanyPeople()
56
    {
57
        if ($this->isTravis()) {
58
            $this->markTestSkipped('Travis cannot connect to Justice.cz');
59
        }
60
61
        $record = $this->ares->findByIdentificationNumber(27791394);
62
        $companyPeople
63
            = $record->getCompanyPeople();
64
        $this->assertCount(2, $companyPeople);
65
    }
66
67
    public function testBalancer()
68
    {
69
        $ares = new Ares();
70
        $ares->setBalancer('http://some.loadbalancer.domain');
71
        try {
72
            $ares->findByIdentificationNumber(26168685);
73
        } catch (Ares\AresException $e) {
74
            throw $e;
75
        }
76
        $this->assertEquals(
77
            'http://some.loadbalancer.domain'
78
            .'?url=http%3A%2F%2Fwwwinfo.mfcr.cz%2Fcgi-bin%2Fares%2Fdarv_bas.cgi%3Fico%3D26168685',
79
            $ares->getLastUrl()
80
        );
81
    }
82
83
    /**
84
     * @return bool
85
     */
86
    private function isTravis()
87
    {
88
        if (getenv('TRAVIS_PHP_VERSION')) {
89
            return true;
90
        }
91
92
        return false;
93
    }
94
}
95