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

VatNumberChecksControllerTest::_getMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
namespace VatNumberCheck\Test\TestCase\Controller;
3
use Cake\TestSuite\IntegrationTestCase;
4
use VatNumberCheck\Utility\Model\VatNumberCheck;
5
/**
6
 * VatNumberChecksController Test Case.
7
 *
8
 * @property \VatNumberCheck\Controller\VatNumberChecksController $VatNumberChecks
9
 */
10
class VatNumberChecksControllerTest extends IntegrationTestCase
0 ignored issues
show
Deprecated Code introduced by
The class Cake\TestSuite\IntegrationTestCase has been deprecated: 3.7.0 Use Cake\TestSuite\IntegrationTestTrait instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

10
class VatNumberChecksControllerTest extends /** @scrutinizer ignore-deprecated */ IntegrationTestCase
Loading history...
11
{
12
/**
13
 * Fixtures
14
 *
15
 * @var array
16
 */
17
	public $fixtures = [];
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
		// Post request, correct vat
26
		$VatNumberChecks = $this->_getMock();
27
		$data = ['vatNumber' => 'NL820345672B01'];
28
		$actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
0 ignored issues
show
Bug introduced by
The method testAction() does not exist on VatNumberCheck\Test\Test...berChecksControllerTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
		/** @scrutinizer ignore-call */ 
29
  $actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
		$expected = array_merge($data, ['status' => 'ok']);
30
		// Test response body
31
		$this->assertSame($expected, json_decode($actual, true));
32
		$actual = $VatNumberChecks->response->statusCode();
33
		$expected = 200;
34
		// Test response code
35
		$this->assertSame($expected, $actual);
36
		// Get request
37
		$VatNumberChecks = $this->_getMock();
0 ignored issues
show
Unused Code introduced by
The assignment to $VatNumberChecks is dead and can be removed.
Loading history...
38
		$data = ['vatNumber' => ''];
39
		$actual = $this->testAction($url, ['return' => 'contents']);
40
		$expected = array_merge($data, ['status' => 'failure']);
41
		$this->assertSame($expected, json_decode($actual, true));
42
		// Post request, incorrect vat
43
		$VatNumberChecks = $this->_getMock();
44
		$data = ['vatNumber' => 'NL820345672B02'];
45
		$actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
46
		$expected = array_merge($data, ['status' => 'failure']);
47
		$this->assertSame($expected, json_decode($actual, true));
48
		// Post request, correct vat, timeout
49
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks', [
0 ignored issues
show
Bug introduced by
The method generate() does not exist on VatNumberCheck\Test\Test...berChecksControllerTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
		/** @scrutinizer ignore-call */ 
50
  $VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks', [

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
			'models' => [
51
				'VatNumberCheck.VatNumberCheck' => ['check']
52
			]
53
		]);
54
		$VatNumberChecks->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
55
		$VatNumberChecks->VatNumberCheck->expects($this->any())
56
			->method('check')->will($this->throwException(new Exception()));
0 ignored issues
show
Bug introduced by
The type VatNumberCheck\Test\TestCase\Controller\Exception was not found. Did you mean Exception? If so, make sure to prefix the type with \.
Loading history...
57
		$data = ['vatNumber' => 'NL820345672B01'];
58
		$actual = $this->testAction($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
59
		$expected = array_merge($data, ['status' => 'failure']);
60
		// Test response body
61
		$this->assertSame($expected, json_decode($actual, true));
62
		$actual = $VatNumberChecks->response->statusCode();
63
		$expected = 503;
64
		// Test response code
65
		$this->assertSame($expected, $actual);
66
	}
67
/**
68
 * Gets a mocked controller instance.
69
 *
70
 * @return VatNumberChecksController
71
 */
72
	protected function _getMock() {
73
		$VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks');
74
		$VatNumberChecks->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck', true);
0 ignored issues
show
Bug introduced by
The type VatNumberCheck\Test\Test...ontroller\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...
75
		$VatNumberChecks->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
76
		return $VatNumberChecks;
77
	}
78
}