VatNumberChecksControllerTest::testCheck()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 78
Code Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 40
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 78
rs 9.28

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
App::uses('VatNumberChecksController', 'VatNumberCheck.Controller');
3
4
/**
5
 * VatNumberChecksController Test Case
6
 *
7
 * @property VatNumberCheck.VatNumberChecksController $VatNumberChecks
8
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment VatNumberCheck.VatNumberChecksController at position 0 could not be parsed: Unknown type name 'VatNumberCheck.VatNumberChecksController' at position 0 in VatNumberCheck.VatNumberChecksController.
Loading history...
9
class VatNumberChecksControllerTest extends ControllerTestCase {
0 ignored issues
show
Bug introduced by
The type ControllerTestCase 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
 * testCheck method
20
 *
21
 * @return void
22
 */
23
	public function testCheck() {
24
		// Post request, correct vat
25
26
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks');
27
		$VatNumberChecks->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck');
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...
28
29
		$data = ['vatNumber' => 'NL820345672B01'];
30
31
		$result = $this->testAction(
32
			'/vat_number_check/vat_number_checks/check.json',
33
			['return' => 'contents', 'data' => $data, 'method' => 'post']
34
		);
35
		$expected = array_merge($data, ['status' => 'ok']);
36
37
		// Test response body
38
		$this->assertIdentical($expected, json_decode($result, true));
39
40
		$result = $VatNumberChecks->response->statusCode();
41
		$expected = 200;
42
43
		// Test response code
44
		$this->assertIdentical($expected, $result);
45
46
		// Get request
47
48
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks');
49
		$VatNumberChecks->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck');
50
51
		$data = ['vatNumber' => ''];
52
53
		$result = $this->testAction(
54
			'/vat_number_check/vat_number_checks/check.json',
55
			['return' => 'contents']
56
		);
57
		$expected = array_merge($data, ['status' => 'failure']);
58
59
		$this->assertIdentical($expected, json_decode($result, true));
60
61
		// Post request, incorrect vat
62
63
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks');
64
		$VatNumberChecks->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck');
65
66
		$data = ['vatNumber' => 'NL820345672B02'];
67
68
		$result = $this->testAction(
69
			'/vat_number_check/vat_number_checks/check.json',
70
			['return' => 'contents', 'data' => $data, 'method' => 'post']
71
		);
72
		$expected = array_merge($data, ['status' => 'failure']);
73
74
		$this->assertIdentical($expected, json_decode($result, true));
75
76
		// Post request, correct vat, timeout
77
78
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks', [
79
			'models' => [
80
				'VatNumberCheck.VatNumberCheck' => ['getUrlContent']
81
			]
82
		]);
83
		$VatNumberChecks->VatNumberCheck->expects($this->any())->method('getUrlContent')->will($this->returnValue(false));
84
85
		$data = ['vatNumber' => 'NL820345672B01'];
86
87
		$result = $this->testAction(
88
			'/vat_number_check/vat_number_checks/check.json',
89
			['return' => 'contents', 'data' => $data, 'method' => 'post']
90
		);
91
		$expected = array_merge($data, ['status' => 'failure']);
92
93
		// Test response body
94
		$this->assertIdentical($expected, json_decode($result, true));
95
96
		$result = $VatNumberChecks->response->statusCode();
97
		$expected = 503;
98
99
		// Test response code
100
		$this->assertIdentical($expected, $result);
101
	}
102
103
}
104