MagicIssetTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

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

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

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::assertStringMatchesFormat('%a$returnValue = $accessor();%a', $magicIsset->getBody());
0 ignored issues
show
Bug introduced by
The method assertStringMatchesFormat() does not seem to exist on object<ProxyManagerTest\...nerator\MagicIssetTest>.

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
    }
44
45
    /**
46
     * @covers \ProxyManager\ProxyGenerator\AccessInterceptorScopeLocalizer\MethodGenerator\MagicIsset::__construct
47
     */
48
    public function testBodyStructureWithInheritedMethod() : void
49
    {
50
        $reflection         = new ReflectionClass(ClassWithMagicMethods::class);
51
        $prefixInterceptors = $this->createMock(PropertyGenerator::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $prefixInterceptors 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...
52
        $suffixInterceptors = $this->createMock(PropertyGenerator::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $suffixInterceptors 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...
53
54
        $prefixInterceptors->method('getName')->willReturn('pre');
0 ignored issues
show
Bug introduced by
The method method cannot be called on $prefixInterceptors (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...
55
        $suffixInterceptors->method('getName')->willReturn('post');
0 ignored issues
show
Bug introduced by
The method method cannot be called on $suffixInterceptors (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...
56
57
        $magicIsset = new MagicIsset(
58
            $reflection,
59
            $prefixInterceptors,
0 ignored issues
show
Documentation introduced by
$prefixInterceptors 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...
60
            $suffixInterceptors
0 ignored issues
show
Documentation introduced by
$suffixInterceptors 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...
61
        );
62
63
        self::assertSame('__isset', $magicIsset->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<ProxyManagerTest\...nerator\MagicIssetTest>.

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

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...
65
        self::assertStringMatchesFormat('%a$returnValue = & parent::__isset($name);%a', $magicIsset->getBody());
0 ignored issues
show
Bug introduced by
The method assertStringMatchesFormat() does not seem to exist on object<ProxyManagerTest\...nerator\MagicIssetTest>.

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...
66
    }
67
}
68