TranslatorTraitTest::testGetter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Tests\Translation;
4
5
use Loevgaard\DandomainAltapayBundle\Tests\Translation\Fixture\UsingTranslator;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerInterface;
8
use Symfony\Component\Translation\IdentityTranslator;
9
10
class TranslatorTraitTest extends TestCase
11
{
12
    public function testGetter()
13
    {
14
        /** @var ContainerInterface|\PHPUnit_Framework_MockObject_MockObject $container */
15
        $container = $this->getMockBuilder(ContainerInterface::class)
16
            ->disableOriginalConstructor()
17
            ->getMock();
18
19
        $container->method('get')->willReturn(new IdentityTranslator());
20
21
        $obj = new UsingTranslator($container);
0 ignored issues
show
Bug introduced by
It seems like $container defined by $this->getMockBuilder(\S...onstructor()->getMock() on line 15 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Loevgaard\DandomainAltap...anslator::__construct() does only seem to accept object<Symfony\Component...ion\ContainerInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
22
23
        $this->assertInstanceOf(IdentityTranslator::class, $obj->getIt());
24
    }
25
}
26