Completed
Push — master ( cdef28...4d68a4 )
by Christian
11:42
created

Block/Social/FacebookLikeBoxBlockServiceTest.php (2 issues)

Upgrade to new PHP Analysis Engine

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
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\SeoBundle\Tests\Block\Social;
15
16
use Sonata\AdminBundle\Form\FormMapper;
17
use Sonata\BlockBundle\Block\BlockContext;
18
use Sonata\BlockBundle\Model\Block;
19
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase;
20
use Sonata\BlockBundle\Util\OptionsResolver;
21
use Sonata\SeoBundle\Block\Social\FacebookLikeBoxBlockService;
22
23
class FacebookLikeBoxBlockServiceTest extends AbstractBlockServiceTestCase
24
{
25
    public function testService(): void
26
    {
27
        $service = new FacebookLikeBoxBlockService(
28
            'sonata.block.service.facebook.like_box',
29
            $this->templating
30
        );
31
32
        $block = new Block();
33
        $block->setType('core.text');
34
        $block->setSettings([
35
            'url' => 'url_setting',
36
            'width' => 'width_setting',
37
            'height' => 'height_setting',
38
            'colorscheme' => 'colorscheme_setting',
39
            'show_faces' => 'show_faces_setting',
40
            'show_header' => 'show_header_setting',
41
            'show_posts' => 'show_posts_setting',
42
            'show_border' => 'show_border_setting',
43
        ]);
44
45
        $optionResolver = new OptionsResolver();
46
        $service->setDefaultSettings($optionResolver);
47
48
        $blockContext = new BlockContext($block, $optionResolver->resolve($block->getSettings()));
49
50
        $formMapper = $this->createMock(FormMapper::class, [], [], '', false);
51
        $formMapper->expects($this->exactly(2))->method('add');
52
53
        $service->buildCreateForm($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...
54
        $service->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...
55
56
        $service->execute($blockContext);
57
58
        $this->assertSame('url_setting', $this->templating->parameters['settings']['url']);
59
        $this->assertSame('width_setting', $this->templating->parameters['settings']['width']);
60
        $this->assertSame('height_setting', $this->templating->parameters['settings']['height']);
61
        $this->assertSame('colorscheme_setting', $this->templating->parameters['settings']['colorscheme']);
62
        $this->assertSame('show_faces_setting', $this->templating->parameters['settings']['show_faces']);
63
        $this->assertSame('show_header_setting', $this->templating->parameters['settings']['show_header']);
64
        $this->assertSame('show_posts_setting', $this->templating->parameters['settings']['show_posts']);
65
        $this->assertSame('show_border_setting', $this->templating->parameters['settings']['show_border']);
66
    }
67
}
68