SetProxyInitializerTest::testBodyStructure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator\LazyLoadingGhost\MethodGenerator;
6
7
use Laminas\Code\Generator\ParameterGenerator;
8
use Laminas\Code\Generator\PropertyGenerator;
9
use Laminas\Code\Generator\TypeGenerator;
10
use PHPUnit\Framework\MockObject\MockObject;
11
use PHPUnit\Framework\TestCase;
12
use ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer;
13
use function array_shift;
14
15
/**
16
 * Tests for {@see \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer}
17
 *
18
 * @group Coverage
19
 */
20
final class SetProxyInitializerTest extends TestCase
21
{
22
    /**
23
     * @covers \ProxyManager\ProxyGenerator\LazyLoadingGhost\MethodGenerator\SetProxyInitializer::__construct
24
     */
25
    public function testBodyStructure() : void
26
    {
27
        $initializer = $this->createMock(PropertyGenerator::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $initializer is correct as $this->createMock(\Lamin...opertyGenerator::class) (which targets PHPUnit\Framework\TestCase::createMock()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
28
29
        $initializer->method('getName')->willReturn('foo');
0 ignored issues
show
Bug introduced by
The method method cannot be called on $initializer (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
30
31
        $setter     = new SetProxyInitializer($initializer);
0 ignored issues
show
Documentation introduced by
$initializer is of type null, but the function expects a object<Laminas\Code\Generator\PropertyGenerator>.

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...
32
        $parameters = $setter->getParameters();
33
34
        self::assertSame('setProxyInitializer', $setter->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...etProxyInitializerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
        self::assertCount(1, $parameters);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<ProxyManagerTest\...etProxyInitializerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
37
        $initializer = array_shift($parameters);
38
39
        self::assertSame('initializer', $initializer->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...etProxyInitializerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        self::assertSame('$this->foo = $initializer;', $setter->getBody());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...etProxyInitializerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
        self::assertEquals(TypeGenerator::fromTypeString('void'), $setter->getReturnType());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ProxyManagerTest\...etProxyInitializerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
    }
43
}
44