RemoteObjectMethodTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 104
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testBodyStructureWithParameters() 0 33 1
A testBodyStructureWithArrayParameter() 0 29 1
A testBodyStructureWithoutParameters() 0 28 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProxyManagerTest\ProxyGenerator\RemoteObject\MethodGenerator;
6
7
use Laminas\Code\Generator\PropertyGenerator;
8
use Laminas\Code\Reflection\MethodReflection;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod;
12
use ProxyManagerTestAsset\BaseClass;
13
use ReflectionClass;
14
15
/**
16
 * Tests for {@see \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod}
17
 *
18
 * @group Coverage
19
 */
20
final class RemoteObjectMethodTest extends TestCase
21
{
22
    /**
23
     * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
24
     */
25
    public function testBodyStructureWithParameters() : void
26
    {
27
        $adapter = $this->createMock(PropertyGenerator::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $adapter 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
        $adapter->method('getName')->willReturn('adapter');
0 ignored issues
show
Bug introduced by
The method method cannot be called on $adapter (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...
29
30
        $reflectionMethod = new MethodReflection(
31
            BaseClass::class,
32
            'publicByReferenceParameterMethod'
33
        );
34
35
        $method = RemoteObjectMethod::generateMethod(
36
            $reflectionMethod,
37
            $adapter,
0 ignored issues
show
Documentation introduced by
$adapter 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...
38
            new ReflectionClass(PropertyGenerator::class)
39
        );
40
41
        self::assertSame('publicByReferenceParameterMethod', $method->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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
        self::assertCount(2, $method->getParameters());
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
43
        self::assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
44
            '$defaultValues = array (
45
  0 => NULL,
46
  1 => NULL,
47
);
48
$declaredParameterCount = 2;
49
50
$args = \func_get_args() + $defaultValues;
51
52
$return = $this->adapter->call(\'Laminas\\\\Code\\\\Generator\\\\PropertyGenerator\', \'publicByReferenceParameterMethod\', $args);
53
54
return $return;',
55
            $method->getBody()
56
        );
57
    }
58
59
    /**
60
     * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
61
     */
62
    public function testBodyStructureWithArrayParameter() : void
63
    {
64
        $adapter = $this->createMock(PropertyGenerator::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $adapter 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...
65
        $adapter->method('getName')->willReturn('adapter');
0 ignored issues
show
Bug introduced by
The method method cannot be called on $adapter (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...
66
67
        $reflectionMethod = new MethodReflection(BaseClass::class, 'publicArrayHintedMethod');
68
69
        $method = RemoteObjectMethod::generateMethod(
70
            $reflectionMethod,
71
            $adapter,
0 ignored issues
show
Documentation introduced by
$adapter 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...
72
            new ReflectionClass(PropertyGenerator::class)
73
        );
74
75
        self::assertSame('publicArrayHintedMethod', $method->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
76
        self::assertCount(1, $method->getParameters());
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
77
        self::assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
78
            "\$defaultValues = array (
79
  0 => NULL,
80
);
81
\$declaredParameterCount = 1;
82
83
\$args = \\func_get_args() + \$defaultValues;
84
85
\$return = \$this->adapter->call('Laminas\\\\Code\\\\Generator\\\\PropertyGenerator', 'publicArrayHintedMethod', \$args);
86
87
return \$return;",
88
            $method->getBody()
89
        );
90
    }
91
92
    /**
93
     * @covers \ProxyManager\ProxyGenerator\RemoteObject\MethodGenerator\RemoteObjectMethod
94
     */
95
    public function testBodyStructureWithoutParameters() : void
96
    {
97
        $adapter = $this->createMock(PropertyGenerator::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $adapter 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...
98
        $adapter->method('getName')->willReturn('adapter');
0 ignored issues
show
Bug introduced by
The method method cannot be called on $adapter (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...
99
100
        $reflectionMethod = new MethodReflection(BaseClass::class, 'publicMethod');
101
102
        $method = RemoteObjectMethod::generateMethod(
103
            $reflectionMethod,
104
            $adapter,
0 ignored issues
show
Documentation introduced by
$adapter 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...
105
            new ReflectionClass(PropertyGenerator::class)
106
        );
107
108
        self::assertSame('publicMethod', $method->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
109
        self::assertCount(0, $method->getParameters());
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
110
        self::assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...RemoteObjectMethodTest>.

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...
111
            "\$defaultValues = array (
112
);
113
\$declaredParameterCount = 0;
114
115
\$args = \\func_get_args() + \$defaultValues;
116
117
\$return = \$this->adapter->call('Laminas\\\\Code\\\\Generator\\\\PropertyGenerator', 'publicMethod', \$args);
118
119
return \$return;",
120
            $method->getBody()
121
        );
122
    }
123
}
124