Conditions | 2 |
Paths | 2 |
Total Lines | 58 |
Code Lines | 38 |
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 |
||
34 | public function testLinks() |
||
35 | { |
||
36 | // Run link checker |
||
37 | $task = CheckExternalLinksTask::create(); |
||
38 | $task->setSilent(true); // Be quiet during the test! |
||
39 | $task->runLinksCheck(); |
||
40 | |||
41 | // Get all links checked |
||
42 | $status = BrokenExternalPageTrackStatus::get_latest(); |
||
43 | $this->assertEquals('Completed', $status->Status); |
||
44 | $this->assertEquals(5, $status->TotalPages); |
||
45 | $this->assertEquals(5, $status->CompletedPages); |
||
46 | |||
47 | // Check all pages have had the correct HTML adjusted |
||
48 | for ($i = 1; $i <= 5; $i++) { |
||
49 | $page = $this->objFromFixture(ExternalLinksTestPage::class, 'page'.$i); |
||
50 | $this->assertNotEmpty($page->Content); |
||
51 | $this->assertEquals( |
||
52 | $page->ExpectedContent, |
||
53 | $page->Content, |
||
54 | "Assert that the content of page{$i} has been updated" |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | // Check that the correct report of broken links is generated |
||
59 | $links = $status |
||
60 | ->BrokenLinks() |
||
61 | ->sort('Link'); |
||
62 | |||
63 | $this->assertEquals(4, $links->count()); |
||
64 | $this->assertEquals( |
||
65 | array( |
||
66 | 'http://www.broken.com', |
||
67 | 'http://www.broken.com/url/thing', |
||
68 | 'http://www.broken.com/url/thing', |
||
69 | 'http://www.nodomain.com' |
||
70 | ), |
||
71 | array_values($links->map('ID', 'Link')->toArray()) |
||
72 | ); |
||
73 | |||
74 | // Check response codes are correct |
||
75 | $expected = array( |
||
76 | 'http://www.broken.com' => 403, |
||
77 | 'http://www.broken.com/url/thing' => 404, |
||
78 | 'http://www.nodomain.com' => 0 |
||
79 | ); |
||
80 | $actual = $links->map('Link', 'HTTPCode')->toArray(); |
||
81 | $this->assertEquals($expected, $actual); |
||
82 | |||
83 | // Check response descriptions are correct |
||
84 | i18n::set_locale('en_NZ'); |
||
85 | $expected = array( |
||
86 | 'http://www.broken.com' => '403 (Forbidden)', |
||
87 | 'http://www.broken.com/url/thing' => '404 (Not Found)', |
||
88 | 'http://www.nodomain.com' => '0 (Server Not Available)' |
||
89 | ); |
||
90 | $actual = $links->map('Link', 'HTTPCodeDescription')->toArray(); |
||
91 | $this->assertEquals($expected, $actual); |
||
92 | } |
||
111 |