Passed
Pull Request — master (#2)
by
unknown
05:11
created

VatNumberCheckTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 87
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeProvider() 0 11 1
A testCheck() 0 3 1
A checkProvider() 0 11 1
A testNormalize() 0 3 1
A setUp() 0 4 1
A tearDown() 0 4 1
1
<?php
2
namespace VatNumberCheck\Test\TestCase\Utility\Model;
3
use Cake\Network\Exception\InternalErrorException;
4
use Cake\TestSuite\TestCase;
5
use InvalidArgumentException;
6
use VatNumberCheck\Utility\Model\VatNumberCheck;
7
/**
8
 * VatNumberCheck Test Case.
9
 *
10
 * @property \VatNumberCheck\Utility\Model\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
92
			// Correct
93
			['NL820345672B01', true],
94
			['BE0475899519', true],
95
			// Incorrect vat
96
			['NL820345672B02', false],
97
			// Empty vat
98
			['', false],
99
		];
100
	}
101
}
102