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 ( c6d418...25e7de )
by
unknown
23s queued 11s
created

PageFeedBlockServiceTest::testConfigureEditForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
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 Sonata\BlockBundle\Block\BlockContext;
22
use Sonata\BlockBundle\Form\Mapper\FormMapper;
23
use Sonata\BlockBundle\Model\Block;
24
use Sonata\BlockBundle\Model\BlockInterface;
25
use Sonata\BlockBundle\Test\BlockServiceTestCase;
26
27
final class PageFeedBlockServiceTest extends BlockServiceTestCase
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);
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::assertIsArray($this->templating->parameters['settings']);
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);
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::assertIsArray($this->templating->parameters['settings']);
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);
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 testGetMetadata(): void
150
    {
151
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
152
153
        $metadata = $blockService->getMetadata();
154
155
        static::assertSame('block.service', $metadata->getTitle());
156
        static::assertNotNull($metadata->getImage());
157
        static::assertStringStartsWith('data:image/png;base64,', $metadata->getImage() ?? '');
158
        static::assertSame('Core23FacebookBundle', $metadata->getDomain());
159
        static::assertSame([
160
            'class' => 'fa fa-facebook-official',
161
        ], $metadata->getOptions());
162
    }
163
164
    public function testConfigureEditForm(): void
165
    {
166
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
167
168
        $block = new Block();
169
170
        $formMapper = $this->createMock(FormMapper::class);
171
        $formMapper->expects(static::once())->method('add');
172
173
        $blockService->configureEditForm($formMapper, $block);
174
    }
175
}
176