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