GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( fc38fb...ac880e )
by Christian
05:32
created

testExecuteThrowsFacebookException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 9.296
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 PHPUnit\Framework\MockObject\MockObject;
22
use Sonata\AdminBundle\Form\FormMapper;
23
use Sonata\BlockBundle\Block\BlockContext;
24
use Sonata\BlockBundle\Model\Block;
25
use Sonata\BlockBundle\Model\BlockInterface;
26
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
27
28
final class PageFeedBlockServiceTest extends AbstractBlockServiceTestCase
29
{
30
    private $facebook;
31
32
    protected function setUp(): void
33
    {
34
        parent::setUp();
35
36
        $this->facebook = $this->createMock(Facebook::class);
37
    }
38
39
    public function testExecute(): void
40
    {
41
        $token = $this->createMock(AccessToken::class);
42
43
        $app = $this->createMock(FacebookApp::class);
44
        $app->expects($this->once())->method('getAccessToken')
45
            ->willReturn($token)
46
        ;
47
48
        $this->facebook->expects($this->once())->method('getApp')
49
            ->willReturn($app)
50
        ;
51
52
        $feedResponse = [
53
            ['foo' => 'bar'],
54
        ];
55
56
        $edge = $this->createMock(GraphEdge::class);
57
        $edge->expects($this->once())->method('asArray')
58
            ->willReturn($feedResponse)
59
        ;
60
61
        $response = $this->createMock(FacebookResponse::class);
62
        $response->expects($this->once())->method('getGraphEdge')
63
            ->willReturn($edge)
64
        ;
65
66
        $this->facebook->method('get')
67
            ->with($this->equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), $this->equalTo($token))
68
            ->willReturn($response)
69
        ;
70
71
        $block = new Block();
72
73
        $blockContext = new BlockContext($block, [
74
            'title'              => null,
75
            'translation_domain' => null,
76
            'template'           => '@Core23Facebook/Block/block_page_feed.html.twig',
77
            'id'                 => '0815',
78
            'fields'             => 'type,message,description,permalink_url,picture,created_time',
79
        ]);
80
81
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
0 ignored issues
show
Documentation introduced by
$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...
82
        $blockService->execute($blockContext);
83
84
        $this->assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view);
85
86
        $this->assertSame($blockContext, $this->templating->parameters['context']);
87
        $this->assertInternalType('array', $this->templating->parameters['settings']);
0 ignored issues
show
Deprecated Code introduced by
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...
88
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
89
90
        $this->assertSame($feedResponse, $this->templating->parameters['feed']);
91
    }
92
93
    public function testExecuteThrowsFacebookException(): void
94
    {
95
        $token = $this->createMock(AccessToken::class);
96
97
        $app = $this->createMock(FacebookApp::class);
98
        $app->expects($this->once())->method('getAccessToken')
99
            ->willReturn($token)
100
        ;
101
102
        $this->facebook->expects($this->once())->method('getApp')
103
            ->willReturn($app)
104
        ;
105
106
        $this->facebook->method('get')
107
            ->with($this->equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), $this->equalTo($token))
108
            ->willThrowException(new FacebookSDKException())
109
        ;
110
111
        $block = new Block();
112
113
        $blockContext = new BlockContext($block, [
114
            'title'              => null,
115
            'translation_domain' => null,
116
            'template'           => '@Core23Facebook/Block/block_page_feed.html.twig',
117
            'id'                 => '0815',
118
            'fields'             => 'type,message,description,permalink_url,picture,created_time',
119
        ]);
120
121
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
0 ignored issues
show
Documentation introduced by
$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...
122
        $blockService->execute($blockContext);
123
124
        $this->assertSame('@Core23Facebook/Block/block_page_feed.html.twig', $this->templating->view);
125
126
        $this->assertSame($blockContext, $this->templating->parameters['context']);
127
        $this->assertInternalType('array', $this->templating->parameters['settings']);
0 ignored issues
show
Deprecated Code introduced by
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...
128
        $this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']);
129
130
        $this->assertSame([], $this->templating->parameters['feed']);
131
    }
132
133
    public function testDefaultSettings(): void
134
    {
135
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
0 ignored issues
show
Documentation introduced by
$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...
136
        $blockContext = $this->getBlockContext($blockService);
137
138
        $this->assertSettings([
139
            'title'              => null,
140
            'translation_domain' => null,
141
            'icon'               => 'fa fa-facebook-official',
142
            'class'              => null,
143
            'id'                 => null,
144
            'limit'              => 10,
145
            'fields'             => 'type,message,description,permalink_url,picture,created_time',
146
            'template'           => '@Core23Facebook/Block/block_page_feed.html.twig',
147
        ], $blockContext);
148
    }
149
150
    public function testGetBlockMetadata(): void
151
    {
152
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
0 ignored issues
show
Documentation introduced by
$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...
153
154
        $metadata = $blockService->getBlockMetadata('description');
155
156
        $this->assertSame('block.service', $metadata->getTitle());
157
        $this->assertSame('description', $metadata->getDescription());
158
        $this->assertNotNull($metadata->getImage());
159
        $this->assertStringStartsWith('data:image/png;base64,', $metadata->getImage() ?? '');
160
        $this->assertSame('Core23FacebookBundle', $metadata->getDomain());
161
        $this->assertSame([
162
            'class' => 'fa fa-facebook-official',
163
        ], $metadata->getOptions());
164
    }
165
166
    public function testBuildEditForm(): void
167
    {
168
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
0 ignored issues
show
Documentation introduced by
$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...
169
170
        $block = new Block();
171
172
        /** @var MockObject&FormMapper $formMapper */
0 ignored issues
show
Documentation introduced by
The doc-type MockObject&FormMapper could not be parsed: Unknown type name "MockObject&FormMapper" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
173
        $formMapper = $this->createMock(FormMapper::class);
174
        $formMapper->expects($this->once())->method('add');
175
176
        $blockService->buildEditForm($formMapper, $block);
0 ignored issues
show
Documentation introduced by
$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...
177
    }
178
}
179