| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 23 | public function testCheck() { |
||
| 24 | // Post request, correct vat |
||
| 25 | |||
| 26 | $VatNumberChecks = $this->generate('VatNumberCheck.VatNumberChecks'); |
||
| 27 | $VatNumberChecks->VatNumberCheck = ClassRegistry::init('VatNumberCheck.VatNumberCheck'); |
||
| 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 | } |
||
| 104 |