Oefenweb /
cakephp-vat-number-check
| 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
Loading history...
|
|||
| 9 | class VatNumberChecksControllerTest extends ControllerTestCase { |
||
|
0 ignored issues
–
show
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. 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
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. 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 |