These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * (c) Christian Gripp <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Core23\FacebookBundle\Tests\Block\Service; |
||
13 | |||
14 | use Core23\FacebookBundle\Block\Service\PageFeedBlockService; |
||
15 | use Facebook\Authentication\AccessToken; |
||
16 | use Facebook\Exceptions\FacebookSDKException; |
||
17 | use Facebook\Facebook; |
||
18 | use Facebook\FacebookApp; |
||
19 | use Facebook\FacebookResponse; |
||
20 | use Facebook\GraphNodes\GraphEdge; |
||
21 | use Sonata\AdminBundle\Form\FormMapper; |
||
22 | use Sonata\BlockBundle\Block\BlockContext; |
||
23 | use Sonata\BlockBundle\Model\Block; |
||
24 | use Sonata\BlockBundle\Model\BlockInterface; |
||
25 | use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase; |
||
26 | |||
27 | final class PageFeedBlockServiceTest extends AbstractBlockServiceTestCase |
||
28 | { |
||
29 | private $facebook; |
||
30 | |||
31 | protected function setUp(): void |
||
32 | { |
||
33 | parent::setUp(); |
||
34 | |||
35 | $this->facebook = $this->createMock(Facebook::class); |
||
36 | } |
||
37 | |||
38 | public function testExecute(): void |
||
39 | { |
||
40 | $token = $this->createMock(AccessToken::class); |
||
41 | |||
42 | $app = $this->createMock(FacebookApp::class); |
||
43 | $app->expects(static::once())->method('getAccessToken') |
||
44 | ->willReturn($token) |
||
45 | ; |
||
46 | |||
47 | $this->facebook->expects(static::once())->method('getApp') |
||
48 | ->willReturn($app) |
||
49 | ; |
||
50 | |||
51 | $feedResponse = [ |
||
52 | ['foo' => 'bar'], |
||
53 | ]; |
||
54 | |||
55 | $edge = $this->createMock(GraphEdge::class); |
||
56 | $edge->expects(static::once())->method('asArray') |
||
57 | ->willReturn($feedResponse) |
||
58 | ; |
||
59 | |||
60 | $response = $this->createMock(FacebookResponse::class); |
||
61 | $response->expects(static::once())->method('getGraphEdge') |
||
62 | ->willReturn($edge) |
||
63 | ; |
||
64 | |||
65 | $this->facebook->method('get') |
||
66 | ->with(static::equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), static::equalTo($token)) |
||
67 | ->willReturn($response) |
||
68 | ; |
||
69 | |||
70 | $block = new Block(); |
||
71 | |||
72 | $blockContext = new BlockContext($block, [ |
||
73 | 'title' => null, |
||
74 | 'translation_domain' => null, |
||
75 | 'template' => '@Core23Facebook/Block/block_page_feed.html.twig', |
||
76 | 'id' => '0815', |
||
77 | 'fields' => 'type,message,description,permalink_url,picture,created_time', |
||
78 | ]); |
||
79 | |||
80 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
0 ignored issues
–
show
|
|||
81 | $blockService->execute($blockContext); |
||
82 | |||
83 | static::assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view); |
||
84 | |||
85 | static::assertSame($blockContext, $this->templating->parameters['context']); |
||
86 | static::assertInternalType('array', $this->templating->parameters['settings']); |
||
0 ignored issues
–
show
The method
PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.
Loading history...
|
|||
87 | static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
||
88 | |||
89 | static::assertSame($feedResponse, $this->templating->parameters['feed']); |
||
90 | } |
||
91 | |||
92 | public function testExecuteThrowsFacebookException(): void |
||
93 | { |
||
94 | $token = $this->createMock(AccessToken::class); |
||
95 | |||
96 | $app = $this->createMock(FacebookApp::class); |
||
97 | $app->expects(static::once())->method('getAccessToken') |
||
98 | ->willReturn($token) |
||
99 | ; |
||
100 | |||
101 | $this->facebook->expects(static::once())->method('getApp') |
||
102 | ->willReturn($app) |
||
103 | ; |
||
104 | |||
105 | $this->facebook->method('get') |
||
106 | ->with(static::equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), static::equalTo($token)) |
||
107 | ->willThrowException(new FacebookSDKException()) |
||
108 | ; |
||
109 | |||
110 | $block = new Block(); |
||
111 | |||
112 | $blockContext = new BlockContext($block, [ |
||
113 | 'title' => null, |
||
114 | 'translation_domain' => null, |
||
115 | 'template' => '@Core23Facebook/Block/block_page_feed.html.twig', |
||
116 | 'id' => '0815', |
||
117 | 'fields' => 'type,message,description,permalink_url,picture,created_time', |
||
118 | ]); |
||
119 | |||
120 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
0 ignored issues
–
show
$this->facebook is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Facebook\Facebook> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
121 | $blockService->execute($blockContext); |
||
122 | |||
123 | static::assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view); |
||
124 | |||
125 | static::assertSame($blockContext, $this->templating->parameters['context']); |
||
126 | static::assertInternalType('array', $this->templating->parameters['settings']); |
||
0 ignored issues
–
show
The method
PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.
Loading history...
|
|||
127 | static::assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
||
128 | |||
129 | static::assertSame([], $this->templating->parameters['feed']); |
||
130 | } |
||
131 | |||
132 | public function testDefaultSettings(): void |
||
133 | { |
||
134 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
0 ignored issues
–
show
$this->facebook is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Facebook\Facebook> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
135 | $blockContext = $this->getBlockContext($blockService); |
||
136 | |||
137 | $this->assertSettings([ |
||
138 | 'title' => null, |
||
139 | 'translation_domain' => null, |
||
140 | 'icon' => 'fa fa-facebook-official', |
||
141 | 'class' => null, |
||
142 | 'id' => null, |
||
143 | 'limit' => 10, |
||
144 | 'fields' => 'type,message,description,permalink_url,picture,created_time', |
||
145 | 'template' => '@Core23Facebook/Block/block_page_feed.html.twig', |
||
146 | ], $blockContext); |
||
147 | } |
||
148 | |||
149 | public function testGetBlockMetadata(): void |
||
150 | { |
||
151 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
0 ignored issues
–
show
$this->facebook is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Facebook\Facebook> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
152 | |||
153 | $metadata = $blockService->getBlockMetadata('description'); |
||
154 | |||
155 | static::assertSame('block.service', $metadata->getTitle()); |
||
156 | static::assertSame('description', $metadata->getDescription()); |
||
157 | static::assertNotNull($metadata->getImage()); |
||
158 | static::assertStringStartsWith('data:image/png;base64,', $metadata->getImage() ?? ''); |
||
159 | static::assertSame('Core23FacebookBundle', $metadata->getDomain()); |
||
160 | static::assertSame([ |
||
161 | 'class' => 'fa fa-facebook-official', |
||
162 | ], $metadata->getOptions()); |
||
163 | } |
||
164 | |||
165 | public function testBuildEditForm(): void |
||
166 | { |
||
167 | $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
||
0 ignored issues
–
show
$this->facebook is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Facebook\Facebook> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
168 | |||
169 | $block = new Block(); |
||
170 | |||
171 | $formMapper = $this->createMock(FormMapper::class); |
||
172 | $formMapper->expects(static::once())->method('add'); |
||
173 | |||
174 | $blockService->buildEditForm($formMapper, $block); |
||
0 ignored issues
–
show
$formMapper is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Sonata\AdminBundle\Form\FormMapper> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
175 | } |
||
176 | } |
||
177 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: