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 ( dad8b1...dc317e )
by Christian
01:25
created

PageFeedBlockServiceTest::testBuildEditForm()   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\Facebook;
17
use Facebook\FacebookApp;
18
use Facebook\FacebookResponse;
19
use Facebook\GraphNodes\GraphEdge;
20
use Sonata\AdminBundle\Form\FormMapper;
21
use Sonata\BlockBundle\Block\BlockContext;
22
use Sonata\BlockBundle\Model\Block;
23
use Sonata\BlockBundle\Model\BlockInterface;
24
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
25
26
final class PageFeedBlockServiceTest extends AbstractBlockServiceTestCase
27
{
28
    private $facebook;
29
30
    protected function setUp(): void
31
    {
32
        parent::setUp();
33
34
        $this->facebook = $this->createMock(Facebook::class);
35
    }
36
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
91
    public function testDefaultSettings(): void
92
    {
93
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
94
        $blockContext = $this->getBlockContext($blockService);
95
96
        $this->assertSettings([
97
            'title'              => null,
98
            'translation_domain' => null,
99
            'icon'               => 'fa fa-facebook-official',
100
            'class'              => null,
101
            'id'                 => null,
102
            'limit'              => 10,
103
            'fields'             => 'type,message,description,permalink_url,picture,created_time',
104
            'template'           => '@Core23Facebook/Block/block_page_feed.html.twig',
105
        ], $blockContext);
106
    }
107
108
    public function testBuildEditForm(): void
109
    {
110
        $blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook);
111
112
        $block = new Block();
113
114
        $formMapper = $this->createMock(FormMapper::class);
115
        $formMapper->expects($this->once())->method('add');
116
117
        $blockService->buildEditForm($formMapper, $block);
118
    }
119
}
120