Completed
Pull Request — master (#2)
by
unknown
05:39
created

VatNumberChecksControllerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 1
b 0
f 0
dl 0
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testCheck() 0 8 1
1
<?php
2
namespace VatNumberCheck\Test\TestCase\Controller;
3
4
use Cake\TestSuite\IntegrationTestTrait;
5
use Cake\TestSuite\TestCase;
6
use VatNumberCheck\Controller\VatNumberChecksController;
7
use VatNumberCheck\Utility\VatNumberCheck;
8
use VatNumberCheck\Test\TestApp;
9
/**
10
 * VatNumberChecksController Test Case.
11
 *
12
 * @property \VatNumberCheck\Controller\VatNumberChecksController $VatNumberChecks
13
 */
14
class VatNumberChecksControllerTest extends TestCase
15
{
16
	use IntegrationTestTrait;
0 ignored issues
show
Bug introduced by
The trait Cake\TestSuite\IntegrationTestTrait requires the property $viewVars which is not provided by VatNumberCheck\Test\Test...berChecksControllerTest.
Loading history...
17
18
/**
19
 * Fixtures
20
 *
21
 * @var array
22
 */
23
	public $fixtures = [];
24
25
/**
26
 * setUp method
27
 *
28
 * @return void
29
 */
30
	public function setUp() {
31
		$this->useHttpServer(true);
32
		$VatNumberChecks = new VatNumberCheck();
0 ignored issues
show
Unused Code introduced by
The assignment to $VatNumberChecks is dead and can be removed.
Loading history...
33
	}
34
/**
35
 * Tests `/vat_number_check/vat_number_checks/check.json`.
36
 *
37
 * @return void
38
 */
39
	public function testCheck() {
40
		$url = '/vat_number_check/vat_number_checks/check.json';
41
		// Post request, correct vat
42
		$data = ['vatNumber' => 'NL820345672B01'];
43
44
		$this->get('url');
45
		$actual = $this->post($url, $data);
0 ignored issues
show
Unused Code introduced by
The assignment to $actual is dead and can be removed.
Loading history...
Bug introduced by
Are you sure the assignment to $actual is correct as $this->post($url, $data) targeting VatNumberCheck\Test\Test...sControllerTest::post() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
46
		$expected = array_merge($data, ['status' => 'ok']);
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is dead and can be removed.
Loading history...
47
		// // Test response body
48
		// $this->assertSame($expected, json_decode($actual, true));
49
		// $actual = $VatNumberChecks->response->statusCode();
50
		// $expected = 200;
51
		// // Test response code
52
		// $this->assertSame($expected, $actual);
53
		// // Get request
54
		// $VatNumberChecks = $this->_getMock();
55
		// $data = ['vatNumber' => ''];
56
		// $actual = $this->get($url, ['return' => 'contents']);
57
		// $expected = array_merge($data, ['status' => 'failure']);
58
		// $this->assertSame($expected, json_decode($actual, true));
59
		// // Post request, incorrect vat
60
		// $VatNumberChecks = $this->_getMock();
61
		// $data = ['vatNumber' => 'NL820345672B02'];
62
		// $actual = $this->get($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
63
		// $expected = array_merge($data, ['status' => 'failure']);
64
		// $this->assertSame($expected, json_decode($actual, true));
65
		// // Post request, correct vat, timeout
66
		// $VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks', [
67
		// 	'models' => [
68
		// 		'VatNumberCheck.VatNumberCheck' => ['check']
69
		// 	]
70
		// ]);
71
		// $VatNumberChecks->VatNumberCheck->setDataSource('vatNumberCheckWebservice');
72
		// $VatNumberChecks->VatNumberCheck->expects($this->any())
73
		// 	->method('check')->will($this->throwException(new Exception()));
74
		// $data = ['vatNumber' => 'NL820345672B01'];
75
		// $actual = $this->get($url, ['return' => 'contents', 'data' => $data, 'method' => 'post']);
76
		// $expected = array_merge($data, ['status' => 'failure']);
77
		// // Test response body
78
		// $this->assertSame($expected, json_decode($actual, true));
79
		// $actual = $VatNumberChecks->response->statusCode();
80
		// $expected = 503;
81
		// // Test response code
82
		// $this->assertSame($expected, $actual);
83
	}
84
}