Conditions | 2 |
Paths | 2 |
Total Lines | 82 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 2 | Features | 3 |
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 |
||
86 | public function testShowLog() |
||
87 | { |
||
88 | $this->checkApplication(); |
||
89 | |||
90 | // Create a new client to browse the application |
||
91 | $client = static::createClient(); |
||
92 | $client->followRedirects(); |
||
93 | |||
94 | $manager = $this->getEntityManager(); |
||
95 | $eventReop = $manager->getRepository("Azine\MailgunWebhooksBundle\Entity\MailgunEvent"); |
||
96 | |||
97 | $apiKey = $this->getContainer()->getParameter(AzineMailgunWebhooksExtension::PREFIX."_".AzineMailgunWebhooksExtension::API_KEY); |
||
98 | |||
99 | // make sure there is some data in the application |
||
100 | if (sizeof($eventReop->findAll()) < 102) { |
||
101 | TestHelper::addMailgunEvents($manager, 102, $apiKey); |
||
102 | } |
||
103 | $count = sizeof($eventReop->findAll()); |
||
104 | |||
105 | // view the list of events |
||
106 | $pageSize = 25; |
||
107 | $listUrl = substr($this->getRouter()->generate("mailgunevent_list", array('_locale' => "en", 'page' => 1, 'pageSize' => $pageSize, 'clear' => true)), 13); |
||
108 | $crawler = $this->loginUserIfRequired($client, $listUrl); |
||
109 | $this->assertEquals($pageSize+1, $crawler->filter(".eventsTable tr")->count(), "$pageSize Mailgun events (+1 header row) expected on this page ($listUrl)!"); |
||
110 | |||
111 | // view a single event |
||
112 | $link = $crawler->filter(".eventsTable tr a:first-child")->first()->link(); |
||
113 | $posLastSlash = strrpos($link->getUri(), "/"); |
||
114 | $posOfIdStart = strrpos($link->getUri(), "/", -6) +1; |
||
115 | $eventId = substr($link->getUri(), $posOfIdStart, $posLastSlash-$posOfIdStart); |
||
116 | $crawler = $client->click($link); |
||
117 | $this->assertEquals(200, $client->getResponse()->getStatusCode(), "Status 200 expected."); |
||
118 | $this->assertEquals($eventId, $crawler->filter("td")->first()->text(), "Content of first td should be the eventId ($eventId)"); |
||
119 | |||
120 | // delete the event from show-page |
||
121 | $link = $crawler->selectLink("delete")->link(); |
||
122 | $crawler = $client->click($link); |
||
123 | |||
124 | // check that it is gone from the list |
||
125 | $this->assertEquals(0, $crawler->filter("#event$eventId")->count(), "The deleted event should not be in the list anymore."); |
||
126 | |||
127 | // delete the event from list-page |
||
128 | $crawler = $client->followRedirect(); |
||
129 | $link = $crawler->filter(".eventsTable tr .deleteLink")->first()->link(); |
||
130 | $delUri = $link->getUri(); |
||
131 | $eventId = substr($delUri, strrpos($delUri, "/") + 1); |
||
132 | $crawler = $client->click($link); |
||
133 | |||
134 | // check that it is gone from the list |
||
135 | $this->assertEquals(0, $crawler->filter("#event$eventId")->count(), "The deleted event should not be in the list anymore."); |
||
136 | |||
137 | // filter the list for something |
||
138 | $crawler = $client->followRedirect(); |
||
139 | $form = $crawler->selectButton("Filter")->form(); |
||
140 | $form['filter[eventType]']->select("delivered"); |
||
141 | $crawler = $client->submit($form); |
||
142 | $this->assertEquals($crawler->filter(".eventsTable tr")->count() -1, $crawler->filter(".eventsTable a:contains('delivered')")->count(), "There should only be 'delivered' events in the list"); |
||
143 | |||
144 | // delete entry with xmlHttpRequest |
||
145 | $eventToDelete = $eventReop->findOneBy(array()); |
||
146 | $ajaxUrl = $this->getRouter()->generate("mailgunevent_delete_ajax"); |
||
147 | $client->request("POST", $ajaxUrl, array('eventId' => $eventToDelete->getId()), array(), array('HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')); |
||
148 | $this->assertEquals('{"success":true}', $client->getResponse()->getContent(), "JSON response expcted."); |
||
149 | |||
150 | // show/delete inexistent log entry |
||
151 | $inexistentEventId = md5("123invalid"); |
||
152 | $url = $this->getRouter()->generate("mailgunevent_delete", array("eventId" => $inexistentEventId)); |
||
153 | $client->request("GET", $url); |
||
154 | $this->assertEquals(404, $client->getResponse()->getStatusCode(), "404 expected for invalid eventId ($inexistentEventId)."); |
||
155 | |||
156 | $url = $this->getRouter()->generate("mailgunevent_show", array("id" => $inexistentEventId)); |
||
157 | $client->request("GET", $url); |
||
158 | $this->assertEquals(404, $client->getResponse()->getStatusCode(), "404 expected."); |
||
159 | |||
160 | // show inexistent page |
||
161 | $maxPage = floor($count/$pageSize); |
||
162 | $beyondListUrl = $this->getRouter()->generate("mailgunevent_list", array('_locale' => "en", 'page' => $maxPage + 1, 'pageSize' => $pageSize, 'clear' => true)); |
||
163 | $client->request("GET", $beyondListUrl); |
||
164 | $crawler = $client->followRedirect(); |
||
165 | $this->assertEquals(2, $crawler->filter(".pagination .disabled:contains('Next')")->count(), "Expected to be on the last page => the next button should be disabled."); |
||
166 | |||
167 | } |
||
168 | |||
268 |