Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
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 |
||
37 | public function testExecute(): void |
||
38 | { |
||
39 | $token = $this->createMock(AccessToken::class); |
||
40 | |||
41 | $app = $this->createMock(FacebookApp::class); |
||
42 | $app->expects($this->once())->method('getAccessToken') |
||
43 | ->willReturn($token) |
||
44 | ; |
||
45 | |||
46 | $this->facebook->expects($this->once())->method('getApp') |
||
47 | ->willReturn($app) |
||
48 | ; |
||
49 | |||
50 | $feedResponse = [ |
||
51 | ['foo' => 'bar'], |
||
52 | ]; |
||
53 | |||
54 | $edge = $this->createMock(GraphEdge::class); |
||
55 | $edge->expects($this->once())->method('asArray') |
||
56 | ->willReturn($feedResponse) |
||
57 | ; |
||
58 | |||
59 | $response = $this->createMock(FacebookResponse::class); |
||
60 | $response->expects($this->once())->method('getGraphEdge') |
||
61 | ->willReturn($edge) |
||
62 | ; |
||
63 | |||
64 | $this->facebook->method('get') |
||
65 | ->with($this->equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), $this->equalTo($token)) |
||
66 | ->willReturn($response) |
||
67 | ; |
||
68 | |||
69 | $block = new Block(); |
||
70 | |||
71 | $blockContext = new BlockContext($block, [ |
||
72 | 'title' => null, |
||
73 | 'translation_domain' => null, |
||
74 | 'template' => '@Core23Facebook/Block/block_page_feed.html.twig', |
||
75 | 'id' => '0815', |
||
76 | 'fields' => 'type,message,description,permalink_url,picture,created_time', |
||
77 | ]); |
||
78 | |||
79 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
80 | $blockService->execute($blockContext); |
||
81 | |||
82 | $this->assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view); |
||
83 | |||
84 | $this->assertSame($blockContext, $this->templating->parameters['context']); |
||
85 | $this->assertInternalType('array', $this->templating->parameters['settings']); |
||
86 | $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
||
87 | |||
88 | $this->assertSame($feedResponse, $this->templating->parameters['feed']); |
||
89 | } |
||
90 | |||
120 |