Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
76 | public function testCreate() |
||
77 | { |
||
78 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
||
79 | $bugReportDecoded = json_decode($bugReport, true); |
||
80 | $this->configRequest(array('input' => $bugReport)); |
||
81 | $this->post('/incidents/create'); |
||
82 | |||
83 | $report = $this->Reports->find('all', |
||
84 | array('order' => 'Reports.created desc'))->all()->first(); |
||
85 | $subject = 'A new report has been submitted ' |
||
86 | . 'on the Error Reporting Server: ' |
||
87 | . $report['id']; |
||
88 | |||
89 | // Test notification email |
||
90 | $emailContent = Configure::read('test_transport_email'); |
||
91 | |||
92 | $this->assertEquals('[email protected]', $emailContent['headers']['From']); |
||
93 | $this->assertEquals('[email protected]', $emailContent['headers']['To']); |
||
94 | $this->assertEquals($subject, $emailContent['headers']['Subject']); |
||
95 | |||
96 | $this->post('/incidents/create'); |
||
97 | |||
98 | $report = $this->Reports->find('all', |
||
99 | array('order' => 'Reports.created desc'))->all()->first(); |
||
100 | //$report = $report->hydrate(false)->toArray(); |
||
101 | $this->Reports->id = $report['id']; |
||
102 | $incidents = $this->Reports->getIncidents(); |
||
103 | $incidents = $incidents->hydrate(false)->toArray(); |
||
104 | $this->assertEquals(2, count($incidents)); |
||
105 | $this->assertEquals($bugReportDecoded['exception']['message'], |
||
106 | $report['error_message']); |
||
107 | $this->assertEquals($bugReportDecoded['exception']['name'], |
||
108 | $report['error_name']); |
||
109 | $this->assertEquals($bugReportDecoded['pma_version'], |
||
110 | $report['pma_version']); |
||
111 | $this->configRequest(array('input' => array())); |
||
112 | $this->post('/incidents/create'); |
||
113 | $result = json_decode($this->_response->body(), true); |
||
114 | $this->assertEquals(false, $result['success']); |
||
115 | |||
116 | |||
117 | |||
118 | // Test invalid Notification email configuration |
||
119 | Configure::write('NotificationEmailsTo', ''); |
||
120 | |||
121 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
122 | $bugReportDecoded = json_decode($bugReport, true); |
||
123 | $this->configRequest(array('input' => $bugReport)); |
||
124 | $this->post('/incidents/create'); |
||
125 | |||
126 | $report = $this->Reports->find('all', |
||
127 | array('order' => 'Reports.created desc'))->all()->first(); |
||
128 | $subject = 'A new report has been submitted ' |
||
129 | . 'on the Error Reporting Server: ' |
||
130 | . $report['id']; |
||
131 | |||
132 | $emailContent = Configure::read('test_transport_email'); |
||
133 | |||
134 | // Since no email sent |
||
135 | $this->assertEquals(null, $emailContent); |
||
136 | |||
137 | } |
||
138 | } |
||
139 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: