VatNumberCheckTest::testCheck()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
App::uses('VatNumberCheck', 'VatNumberCheck.Model');
3
4
/**
5
 * VatNumberCheck Test Case
6
 *
7
 * @property VatNumberCheck.VatNumberCheck $VatNumberCheck
8
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment VatNumberCheck.VatNumberCheck at position 0 could not be parsed: Unknown type name 'VatNumberCheck.VatNumberCheck' at position 0 in VatNumberCheck.VatNumberCheck.
Loading history...
9
class VatNumberCheckTest extends CakeTestCase {
0 ignored issues
show
Bug introduced by
The type CakeTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
/**
12
 * Fixtures
13
 *
14
 * @var array
15
 */
16
	public $fixtures = [];
17
18
/**
19
 * setUp method
20
 *
21
 * @return void
22
 */
23
	public function setUp() {
24
		parent::setUp();
25
26
		$this->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck', true);
0 ignored issues
show
Bug introduced by
The type ClassRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug Best Practice introduced by
The property VatNumberCheck does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
27
		$this->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
28
	}
29
30
/**
31
 * tearDown method
32
 *
33
 * @return void
34
 */
35
	public function tearDown() {
36
		unset($this->VatNumberCheck);
37
38
		parent::tearDown();
39
	}
40
41
/**
42
 * Tests `normalize`.
43
 *
44
 * @param string $vatNumber
45
 * @param string $expected
46
 * @return void
47
 * @dataProvider normalizeProvider
48
 */
49
	public function testNormalize(string $vatNumber, string $expected) {
50
		$actual = $this->VatNumberCheck->normalize($vatNumber);
51
		$this->assertSame($expected, $actual);
52
	}
53
54
/**
55
 * Data provider for `normalize`.
56
 *
57
 * @return array
58
 */
59
	public function normalizeProvider() : array {
60
		return [
61
			// $vatNumber, $expected
62
63
			// Correct
64
			['NL820345672B01', 'NL820345672B01'],
65
			// To upper case
66
			['NL820345672b01', 'NL820345672B01'],
67
			// Removal of non-alphanumeric
68
			['NL820345672 B01', 'NL820345672B01'],
69
			['NL820345672!B01', 'NL820345672B01'],
70
		];
71
	}
72
73
/**
74
 * Tests `check`.
75
 *
76
 * @param string $vatNumber
77
 * @param string $expected
78
 * @return void
79
 * @dataProvider checkProvider
80
 */
81
	public function testCheck(string $vatNumber, bool $expected) {
82
		$actual = $this->VatNumberCheck->check($vatNumber);
83
		$this->assertSame($expected, $actual);
84
	}
85
86
/**
87
 * Data provider for `check`.
88
 *
89
 * @return array
90
 */
91
	public function checkProvider() : array {
92
		return [
93
			// $vatNumber, $expected
94
95
			// Correct
96
			['NL820345672B01', true],
97
			['BE0475899519', true],
98
			// Incorrect vat
99
			['NL820345672B02', false],
100
			// Empty vat
101
			['', false],
102
		];
103
	}
104
}
105