Completed
Push — master ( 71ecac...a8b6f5 )
by Mischa ter
02:46 queued 11s
created

VatNumberChecksControllerTest::testCheck503()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 14
nc 1
nop 0
dl 0
loc 25
rs 9.7998
c 0
b 0
f 0
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
 * Tests `/vat_number_check/vat_number_checks/check.json`.
20
 *
21
 * @return void
22
 */
23
	public function testCheck() {
24
		$url = '/vat_number_check/vat_number_checks/check.json';
25
26
		// Post request, correct vat
27
28
		$VatNumberChecks = $this->_getMock();
29
30
		$data = ['vatNumber' => 'NL820345672B01'];
31
32
		$actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
33
		$expected = array_merge($data, ['status' => 'ok']);
34
35
		// Test response body
36
		$this->assertSame($expected, json_decode($actual, true));
37
38
		$actual = $VatNumberChecks->response->statusCode();
39
		$expected = 200;
40
41
		// Test response code
42
		$this->assertSame($expected, $actual);
43
44
		// Get request
45
46
		$VatNumberChecks = $this->_getMock();
0 ignored issues
show
Unused Code introduced by
The assignment to $VatNumberChecks is dead and can be removed.
Loading history...
47
48
		$data = ['vatNumber' => ''];
49
50
		$actual = $this->testAction($url, ['return' => 'contents']);
51
		$expected = array_merge($data, ['status' => 'failure']);
52
53
		$this->assertSame($expected, json_decode($actual, true));
54
55
		// Post request, incorrect vat
56
57
		$VatNumberChecks = $this->_getMock();
58
59
		$data = ['vatNumber' => 'NL820345672B02'];
60
61
		$actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
62
		$expected = array_merge($data, ['status' => 'failure']);
63
64
		$this->assertSame($expected, json_decode($actual, true));
65
	}
66
67
/**
68
 * Tests `/vat_number_check/vat_number_checks/check.json`.
69
 *
70
 *  Post request, correct vat, timeout
71
 *
72
 * @return void
73
 * @requires PHPUnit 5.7
74
 * @todo This should ever happen, right?
75
 */
76
	public function testCheck503() {
77
		$url = '/vat_number_check/vat_number_checks/check.json';
78
79
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks', [
80
			'models' => [
81
				'VatNumberCheck.VatNumberCheck' => ['check']
82
			]
83
		]);
84
		$VatNumberChecks->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
85
		$VatNumberChecks->VatNumberCheck->expects($this->any())
86
			->method('check')->will($this->throwException(new Exception()));
87
88
		$data = ['vatNumber' => 'NL820345672B01'];
89
90
		$actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
91
		$expected = array_merge($data, ['status' => 'failure']);
92
93
		// Test response body
94
		$this->assertSame($expected, json_decode($actual, true));
95
96
		$actual = $VatNumberChecks->response->statusCode();
97
		$expected = 503;
98
99
		// Test response code
100
		$this->assertSame($expected, $actual);
101
	}
102
103
/**
104
 * Gets a mocked controller instance.
105
 *
106
 * @return VatNumberChecksController
107
 */
108
	protected function _getMock() {
109
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks');
110
		$VatNumberChecks->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...
111
		$VatNumberChecks->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
112
113
		return $VatNumberChecks;
114
	}
115
}
116