| Conditions | 1 |
| Paths | 1 |
| Total Lines | 74 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 9 | public function testToHtml() |
||
| 10 | { |
||
| 11 | $converter = new JsonToHtml(); |
||
| 12 | |||
| 13 | // let's try a basic json |
||
| 14 | $json = json_encode(array( |
||
| 15 | 'data' => array(array( |
||
| 16 | 'type' => 'quote', |
||
| 17 | 'data' => array( |
||
| 18 | 'text' => 'Text', |
||
| 19 | 'cite' => 'Cite' |
||
| 20 | ) |
||
| 21 | )) |
||
| 22 | )); |
||
| 23 | $html = $converter->toHtml($json); |
||
| 24 | $this->assertEquals( |
||
| 25 | $html, |
||
| 26 | "<blockquote><p>Text</p>\n<cite><p>Cite</p>\n</cite></blockquote>" |
||
| 27 | ); |
||
| 28 | |||
| 29 | // Lets convert a normal text type that uses the default converter |
||
| 30 | $json = json_encode(array( |
||
| 31 | 'data' => array(array( |
||
| 32 | 'type' => 'text', |
||
| 33 | 'data' => array( |
||
| 34 | 'text' => 'test' |
||
| 35 | ) |
||
| 36 | )) |
||
| 37 | )); |
||
| 38 | $html = $converter->toHtml($json); |
||
| 39 | $this->assertEquals($html, "<p>test</p>\n"); |
||
| 40 | |||
| 41 | // the video conversion |
||
| 42 | $json = json_encode(array( |
||
| 43 | 'data' => array(array( |
||
| 44 | 'type' => 'video', |
||
| 45 | 'data' => array( |
||
| 46 | 'source' => 'youtube', |
||
| 47 | 'remote_id' => '4BXpi7056RM' |
||
| 48 | ) |
||
| 49 | )) |
||
| 50 | )); |
||
| 51 | $html = $converter->toHtml($json); |
||
| 52 | $this->assertEquals( |
||
| 53 | $html, |
||
| 54 | "<iframe src=\"//www.youtube.com/embed/4BXpi7056RM?rel=0\" frameborder=\"0\" allowfullscreen></iframe>\n" |
||
| 55 | ); |
||
| 56 | |||
| 57 | // The heading |
||
| 58 | $json = json_encode(array( |
||
| 59 | 'data' => array(array( |
||
| 60 | 'type' => 'heading', |
||
| 61 | 'data' => array( |
||
| 62 | 'text' => 'test' |
||
| 63 | ) |
||
| 64 | )) |
||
| 65 | )); |
||
| 66 | $html = $converter->toHtml($json); |
||
| 67 | $this->assertEquals($html, "<h2>test</h2>\n"); |
||
| 68 | |||
| 69 | // images |
||
| 70 | $json = json_encode(array( |
||
| 71 | 'data' => array(array( |
||
| 72 | 'type' => 'image', |
||
| 73 | 'data' => array( |
||
| 74 | 'file' => array( |
||
| 75 | 'url' => '/frontend/files/sir-trevor/images/IMG_3867.JPG' |
||
| 76 | ) |
||
| 77 | ) |
||
| 78 | )) |
||
| 79 | )); |
||
| 80 | $html = $converter->toHtml($json); |
||
| 81 | $this->assertEquals($html, "<img src=\"/frontend/files/sir-trevor/images/IMG_3867.JPG\" />\n"); |
||
| 82 | } |
||
| 83 | } |
||
| 84 |