Completed
Pull Request — master (#2)
by
unknown
05:39
created

VatNumberCheckTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 20
c 1
b 0
f 0
dl 0
loc 94
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeProvider() 0 11 1
A setUp() 0 4 1
A testCheckInvalid() 0 3 1
A testCheck() 0 3 1
A checkProvider() 0 8 1
A tearDown() 0 4 1
A testNormalize() 0 3 1
1
<?php
2
namespace VatNumberCheck\Test\TestCase\Utility;
3
use Cake\Http\Exception\InternalErrorException;
4
use Cake\TestSuite\TestCase;
5
use InvalidArgumentException;
6
use VatNumberCheck\Utility\VatNumberCheck;
7
/**
8
 * VatNumberCheck Test Case.
9
 *
10
 * @property \VatNumberCheck\Utility\VatNumberCheck $VatNumberCheck
11
 */
12
class VatNumberCheckTest extends TestCase
13
{
14
15
/**
16
 * setUp method
17
 *
18
 * @return void
19
 */
20
    public function setUp() {
21
        parent::setUp();
22
23
        $this->VatNumberCheck = new VatNumberCheck();
24
        // $this->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
25
    }
26
27
/**
28
 * tearDown method
29
 *
30
 * @return void
31
 */
32
    public function tearDown() {
33
        unset($this->VatNumberCheck);
34
35
        parent::tearDown();
36
    }
37
38
/**
39
 * Tests `normalize`.
40
 *
41
 * @param string $vatNumber
42
 * @param string $expected
43
 * @return void
44
 * @dataProvider normalizeProvider
45
 */
46
    public function testNormalize(string $vatNumber, string $expected) {
47
        $actual = $this->VatNumberCheck->normalize($vatNumber);
48
        $this->assertSame($expected, $actual);
49
    }
50
51
/**
52
 * Data provider for `normalize`.
53
 *
54
 * @return array
55
 */
56
    public function normalizeProvider() : array {
57
        return [
58
            // $vatNumber, $expected
59
60
            // Correct
61
            ['NL820345672B01', 'NL820345672B01'],
62
            // To upper case
63
            ['NL820345672b01', 'NL820345672B01'],
64
            // Removal of non-alphanumeric
65
            ['NL820345672 B01', 'NL820345672B01'],
66
            ['NL820345672!B01', 'NL820345672B01'],
67
        ];
68
    }
69
70
/**
71
 * Tests `check`.
72
 *
73
 * @param string $vatNumber
74
 * @param string $expected
75
 * @return void
76
 * @dataProvider checkProvider
77
 */
78
    public function testCheck(string $vatNumber, bool $expected) {
79
		$actual = $this->VatNumberCheck->check($vatNumber);
80
        $this->assertSame($expected, $actual);
81
    }
82
83
/**
84
 * Data provider for `check`.
85
 *
86
 * @return array
87
 */
88
    public function checkProvider() : array {
89
        return [
90
            // $vatNumber, $expected
91
            // Correct
92
            ['NL820345672B01', true],
93
            ['BE0475899519', true],
94
            // Incorrect vat
95
            ['NL820345672B02', false],
96
        ];
97
    }
98
99
/**
100
 * Tests `check` with invalid data.
101
 *
102
 */
103
    public function testCheckInvalid() {
104
        $this->expectException(InternalErrorException::class);
105
        $this->VatNumberCheck->check('');
106
    }
107
}
108