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

Social/FacebookLikeButtonBlockServiceTest.php (3 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\FacebookLikeButtonBlockService;
22
23
class FacebookLikeButtonBlockServiceTest extends AbstractBlockServiceTestCase
24
{
25
    public function testService(): void
26
    {
27
        $service = new FacebookLikeButtonBlockService(
28
            'sonata.block.service.facebook.like_button',
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
            'show_faces' => 'show_faces_setting',
38
            'share' => 'share_setting',
39
            'layout' => 'layout_setting',
40
            'colorscheme' => 'colorscheme_setting',
41
            'action' => 'action_setting',
42
        ]);
43
44
        $optionResolver = new OptionsResolver();
45
        $service->setDefaultSettings($optionResolver);
46
47
        $blockContext = new BlockContext($block, $optionResolver->resolve($block->getSettings()));
48
49
        $formMapper = $this->createMock(FormMapper::class, [], [], '', false);
0 ignored issues
show
The call to FacebookLikeButtonBlockServiceTest::createMock() has too many arguments starting with array().

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
50
        $formMapper->expects($this->exactly(2))->method('add');
51
52
        $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...
53
        $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...
54
55
        $service->execute($blockContext);
56
57
        $this->assertSame('url_setting', $this->templating->parameters['settings']['url']);
58
        $this->assertSame('width_setting', $this->templating->parameters['settings']['width']);
59
        $this->assertSame('show_faces_setting', $this->templating->parameters['settings']['show_faces']);
60
        $this->assertSame('share_setting', $this->templating->parameters['settings']['share']);
61
        $this->assertSame('layout_setting', $this->templating->parameters['settings']['layout']);
62
        $this->assertSame('colorscheme_setting', $this->templating->parameters['settings']['colorscheme']);
63
        $this->assertSame('action_setting', $this->templating->parameters['settings']['action']);
64
    }
65
}
66