Conditions | 1 |
Paths | 1 |
Total Lines | 76 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | 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 |
||
94 | public function testCreate(): void |
||
95 | { |
||
96 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_js.json'); |
||
97 | $bugReportDecoded = json_decode($bugReport, true); |
||
98 | $this->configRequest(['input' => $bugReport]); |
||
99 | $this->post('/incidents/create'); |
||
100 | |||
101 | $report = $this->Reports->find( |
||
102 | 'all', |
||
103 | ['order' => 'Reports.created desc'] |
||
104 | )->all()->first(); |
||
105 | $subject = 'A new report has been submitted ' |
||
106 | . 'on the Error Reporting Server: ' |
||
107 | . $report['id']; |
||
108 | $this->assertEquals('4.5.4.1', $report['pma_version']); |
||
109 | |||
110 | //FIXME: test email sending |
||
111 | // Test notification email |
||
112 | //$emailContent = Configure::read('test_transport_email'); |
||
113 | |||
114 | //$this->assertEquals(Configure::read('NotificationEmailsFrom'), $emailContent['headers']['From']); |
||
115 | //$this->assertEquals(Configure::read('NotificationEmailsTo'), $emailContent['headers']['To']); |
||
116 | //$this->assertEquals($subject, $emailContent['headers']['Subject']); |
||
117 | |||
118 | //Configure::write('test_transport_email', null); |
||
119 | |||
120 | $this->post('/incidents/create'); |
||
121 | |||
122 | $report = $this->Reports->find( |
||
123 | 'all', |
||
124 | ['order' => 'Reports.created desc'] |
||
125 | )->all()->first(); |
||
126 | $this->Reports->id = $report['id']; |
||
127 | $incidents = $this->Reports->getIncidents(); |
||
128 | $incidents = $incidents->enableHydration(false)->toArray(); |
||
129 | $this->assertEquals(2, count($incidents)); |
||
130 | $this->assertEquals( |
||
131 | $bugReportDecoded['exception']['message'], |
||
132 | $report['error_message'] |
||
133 | ); |
||
134 | $this->assertEquals( |
||
135 | $bugReportDecoded['exception']['name'], |
||
136 | $report['error_name'] |
||
137 | ); |
||
138 | $this->assertEquals( |
||
139 | IncidentsTable::getStrippedPmaVersion($bugReportDecoded['pma_version']), |
||
140 | $report['pma_version'] |
||
141 | ); |
||
142 | |||
143 | $this->configRequest(['input' => '']); |
||
144 | $this->post('/incidents/create'); |
||
145 | $result = json_decode($this->_response->getBody(), true); |
||
146 | $this->assertNotNull($result); |
||
147 | $this->assertEquals(false, $result['success']); |
||
148 | |||
149 | // Test invalid Notification email configuration |
||
150 | Configure::write('NotificationEmailsTo', ''); |
||
151 | |||
152 | $bugReport = file_get_contents(TESTS . 'Fixture' . DS . 'report_php.json'); |
||
153 | $bugReportDecoded = json_decode($bugReport, true); |
||
154 | $this->configRequest(['input' => $bugReport]); |
||
155 | $this->post('/incidents/create'); |
||
156 | |||
157 | $report = $this->Reports->find( |
||
158 | 'all', |
||
159 | ['order' => 'Reports.created desc'] |
||
160 | )->all()->first(); |
||
161 | $subject = 'A new report has been submitted ' |
||
162 | . 'on the Error Reporting Server: ' |
||
163 | . $report['id']; |
||
164 | $this->assertEquals('4.5.4.1', $report['pma_version']); |
||
165 | |||
166 | $emailContent = Configure::read('test_transport_email'); |
||
167 | |||
168 | // Since no email sent |
||
169 | $this->assertEquals(null, $emailContent); |
||
170 | } |
||
172 |