MappingCollectorTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 108
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testGetName() 0 4 1
A testGetPriority() 0 4 1
A testCollect() 0 20 1
A testCanHide() 0 12 1
A testSerializeUnserializeAndCollectWithNoMetadataFactory() 0 22 1
1
<?php
2
3
namespace DoctrineORMModuleTest\Collector;
4
5
use PHPUnit\Framework\TestCase;
6
use DoctrineORMModule\Collector\MappingCollector;
7
8
/**
9
 * Tests for the MappingCollector
10
 *
11
 * @author  Marco Pivetta <[email protected]>
12
 * @license MIT
13
 */
14
class MappingCollectorTest extends TestCase
15
{
16
    /**
17
     * @var \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory|\PHPUnit_Framework_MockObject_MockObject
18
     */
19
    protected $metadataFactory;
20
21
    /**
22
     * @var MappingCollector
23
     */
24
    protected $collector;
25
26
    /**
27
     * @covers \DoctrineORMModule\Collector\MappingCollector::__construct
28
     */
29
    public function setUp() : void
30
    {
31
        parent::setUp();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class PHPUnit\Framework\TestCase as the method setUp() does only exist in the following sub-classes of PHPUnit\Framework\TestCase: AbstractIssue3881Test, AbstractTest, AssertionExampleTest, BankAccountTest, BankAccountWithCustomExtensionTest, BeforeAndAfterTest, BeforeClassAndAfterClassTest, BeforeClassWithOnlyDataProviderTest, ChangeCurrentWorkingDirectoryTest, ClonedDependencyTest, ConcreteTest, ConcreteWithMyCustomExtensionTest, ConsecutiveParametersTest, CoverageClassExtendedTest, CoverageClassNothingTest, CoverageClassTest, CoverageClassWithoutAnnotationsTest, CoverageCoversOverridesCoversNothingTest, CoverageFunctionParenthesesTest, CoverageFunctionParenthesesWhitespaceTest, CoverageFunctionTest, CoverageMethodNothingCoversMethod, CoverageMethodNothingTest, CoverageMethodOneLineAnnotationTest, CoverageMethodParenthesesTest, CoverageMethodParenthesesWhitespaceTest, CoverageMethodTest, CoverageNamespacedFunctionTest, CoverageNoneTest, CoverageNotPrivateTest, CoverageNotProtectedTest, CoverageNotPublicTest, CoveragePrivateTest, CoverageProtectedTest, CoveragePublicTest, DataProviderDebugTest, DataProviderDependencyTest, DataProviderFilterTest, DataProviderIncompleteTest, DataProviderSkippedTest, DataProviderTest, DataproviderExecutionOrderTest, DependencyFailureTest, DependencySuccessTest, DoNoAssertionTestCase, DoctrineORMModuleTest\Co...or\MappingCollectorTest, DoctrineORMModuleTest\Co...\SQLLoggerCollectorTest, DoctrineORMModuleTest\Form\AnnotationBuilderTest, DoctrineORMModuleTest\Fo...AnnotationsListenerTest, DoctrineORMModuleTest\Listener\CliConfiguratorTest, DoctrineORMModuleTest\Paginator\AdapterTestIgnore, DoctrineORMModuleTest\Se...onfigurationFactoryTest, DoctrineORMModuleTest\Se...ALConnectionFactoryTest, DoctrineORMModuleTest\Se...tionsCommandFactoryTest, DoctrineORMModuleTest\Se...gerCollectorFactoryTest, DoctrineORMModuleTest\Yuml\MetadataGrapherTest, DoctrineORMModuleTest\Yuml\YumlControllerTest, DoesNotPerformAssertions...erformingAssertionsTest, DummyBarTest, DummyFooTest, DuplicateKeyDataProviderTest, EmptyDataProviderTest, EmptyTestCaseTest, ExceptionInAssertPostConditionsTest, ExceptionInAssertPreConditionsTest, ExceptionInSetUpTest, ExceptionInTearDownAfterClassTest, ExceptionInTearDownTest, ExceptionInTest, ExceptionInTestDetectedInTeardown, ExceptionStackTest, ExceptionTest, Failure, FailureTest, FatalTest, Foo\DataProviderIssue2833\FirstTest, Foo\DataProviderIssue2833\SecondTest, Foo\DataProviderIssue2859\TestWithDataProviderTest, Foo\DataProviderIssue2922\FirstTest, Foo\DataProviderIssue2922\SecondHelloWorldTest, Foo_Bar_Issue684Test, Framework\Constraint\LogicalXorTest, GeneratorTest, IgnoreCodeCoverageClassTest, IncompleteTest, InheritanceA, InheritanceB, InheritedTestCase, IniTest, InvocationMockerTest, IsolationTest, Issue1021Test, Issue1149Test, Issue1216Test, Issue1265Test, Issue1330Test, Issue1335Test, Issue1337Test, Issue1348Test, Issue1351Test, Issue1374Test, Issue1437Test, Issue1468Test, Issue1471Test, Issue1472Test, Issue1570Test, Issue2085Test, Issue2137Test, Issue2145Test, Issue2158Test, Issue2366Test, Issue2380Test, Issue2382Test, Issue2435Test, Issue2725\BeforeAfterClassPidTest, Issue2731Test, Issue2811Test, Issue2830Test, Issue2972\Issue2972Test, Issue3093Test, Issue322Test, Issue3739\Issue3739Test, Issue3881Test, Issue3889Test, Issue3904Test, Issue3983Test, Issue433Test, Issue445Test, Issue498Test, Issue503Test, Issue578Test, Issue581Test, Issue74Test, Issue765Test, Issue797Test, MockBuilderTest, MockObjectTest, ModifiedConstructorTestCase, MultiDependencyTest, MultipleDataProviderTest, My\Space\ExceptionNamespaceTest, NamespaceCoverageClassExtendedTest, NamespaceCoverageClassTest, NamespaceCoverageCoversClassPublicTest, NamespaceCoverageCoversClassTest, NamespaceCoverageMethodTest, NamespaceCoverageNotPrivateTest, NamespaceCoverageNotProtectedTest, NamespaceCoverageNotPublicTest, NamespaceCoveragePrivateTest, NamespaceCoverageProtectedTest, NamespaceCoveragePublicTest, NoArgTestCaseTest, NoTestCases, NotExistingCoveredElementTest, NotPublicTestCase, NotVoidTestCase, NothingTest, NullTestResultCacheTest, NumericGroupAnnotationTest, OneTest, OneTestCase, OutputTestCase, OverrideTestCase, PHPUnit\Framework\AssertTest, PHPUnit\Framework\ConstraintTest, PHPUnit\Framework\Constraint\ArrayHasKeyTest, PHPUnit\Framework\Constraint\ArraySubsetTest, PHPUnit\Framework\Constraint\CallbackTest, PHPUnit\Framework\Constraint\ClassHasAttributeTest, PHPUnit\Framework\Constr...sHasStaticAttributeTest, PHPUnit\Framework\Constraint\ConstraintTestCase, PHPUnit\Framework\Constraint\CountTest, PHPUnit\Framework\Constraint\DirectoryExistsTest, PHPUnit\Framework\Constraint\ExceptionCodeTest, PHPUnit\Framework\Constr...eptionMessageRegExpTest, PHPUnit\Framework\Constraint\ExceptionMessageTest, PHPUnit\Framework\Constraint\ExceptionTest, PHPUnit\Framework\Constraint\FileExistsTest, PHPUnit\Framework\Constraint\GreaterThanTest, PHPUnit\Framework\Constraint\IsEmptyTest, PHPUnit\Framework\Constraint\IsEqualTest, PHPUnit\Framework\Constraint\IsIdenticalTest, PHPUnit\Framework\Constraint\IsInstanceOfTest, PHPUnit\Framework\Constraint\IsJsonTest, PHPUnit\Framework\Constraint\IsNullTest, PHPUnit\Framework\Constraint\IsReadableTest, PHPUnit\Framework\Constraint\IsTypeTest, PHPUnit\Framework\Constraint\IsWritableTest, PHPUnit\Framework\Constr...rrorMessageProviderTest, PHPUnit\Framework\Constraint\JsonMatchesTest, PHPUnit\Framework\Constraint\LessThanTest, PHPUnit\Framework\Constraint\LogicalAndTest, PHPUnit\Framework\Constraint\LogicalNotTest, PHPUnit\Framework\Constraint\LogicalOrTest, PHPUnit\Framework\Constr...\ObjectHasAttributeTest, PHPUnit\Framework\Constraint\RegularExpressionTest, PHPUnit\Framework\Constraint\SameSizeTest, PHPUnit\Framework\Constraint\StringContainsTest, PHPUnit\Framework\Constraint\StringEndsWithTest, PHPUnit\Framework\Constr...esFormatDescriptionTest, PHPUnit\Framework\Constraint\StringStartsWithTest, PHPUnit\Framework\Constr...TraversableContainsTest, PHPUnit\Framework\ExceptionTest, PHPUnit\Framework\ExceptionWrapperTest, PHPUnit\Framework\FunctionsTest, PHPUnit\Framework\IncompleteTestCase, PHPUnit\Framework\IncompleteTestCaseTest, PHPUnit\Framework\InvalidArgumentExceptionTest, PHPUnit\Framework\MockOb...\ConfigurableMethodTest, PHPUnit\Framework\MockOb...ConfigurableMethodsTest, PHPUnit\Framework\MockObject\InvocationHandlerTest, PHPUnit\Framework\MockObject\MatcherTest, PHPUnit\Framework\MockObject\MockClassTest, PHPUnit\Framework\MockObject\MockMethodTest, PHPUnit\Framework\MockObject\MockTraitTest, PHPUnit\Framework\SkippedTestCase, PHPUnit\Framework\SkippedTestCaseTest, PHPUnit\Framework\TestBuilderTest, PHPUnit\Framework\TestCaseTest, PHPUnit\Framework\TestFailureTest, PHPUnit\Framework\TestImplementorTest, PHPUnit\Framework\TestListenerTest, PHPUnit\Framework\TestSuiteIteratorTest, PHPUnit\Framework\TestSuiteTest, PHPUnit\Framework\WarningTestCase, PHPUnit\Runner\DefaultTestResultCacheTest, PHPUnit\Runner\Filter\NameFilterIteratorTest, PHPUnit\Runner\PhptTestCaseTest, PHPUnit\Runner\ResultCacheExtensionTest, PHPUnit\Runner\TestSuiteSorterTest, PHPUnit\SelfTest\Basic\SetUpBeforeClassTest, PHPUnit\SelfTest\Basic\SetUpTest, PHPUnit\SelfTest\Basic\StatusTest, PHPUnit\SelfTest\Basic\TearDownAfterClassTest, PHPUnit\StaticAnalysis\TestUsingMocks, PHPUnit\TestFixture\ActualOutputTest, PHPUnit\Test\HookTest, PHPUnit\Util\Annotation\RegistryTest, PHPUnit\Util\ColorTest, PHPUnit\Util\ConfigurationGeneratorTest, PHPUnit\Util\ConfigurationTest, PHPUnit\Util\GetoptTest, PHPUnit\Util\GlobalStateTest, PHPUnit\Util\JsonTest, PHPUnit\Util\PHP\AbstractPhpProcessTest, PHPUnit\Util\RegularExpressionTest, PHPUnit\Util\TestClassTest, PHPUnit\Util\TestDox\CliTestDoxPrinterColorTest, PHPUnit\Util\TestDox\CliTestDoxPrinterTest, PHPUnit\Util\TestDox\NamePrettifierTest, PHPUnit\Util\TestDox\ano...amePrettifierTest.php$0, PHPUnit\Util\TestDox\ano...amePrettifierTest.php$1, PHPUnit\Util\TestDox\ano...amePrettifierTest.php$2, PHPUnit\Util\TestDox\ano...amePrettifierTest.php$3, PHPUnit\Util\XDebugFilterScriptGeneratorTest, PHPUnit\Util\XmlTest, ProxyObjectTest, RequirementsClassBeforeClassHookTest, RequirementsTest, RouterTest, SeparateClassRunMethodInNewProcessTest, SeparateProcessesTest, StackTest, StopOnErrorTestSuite, StopsOnWarningTest, Success, TemplateMethodsTest, Test, Test3194, TestAutoreferenced, TestCaseWithExceptionInHook, TestDoxGroupTest, TestError, TestIncomplete, TestResultCacheTest, TestRisky, TestSkipped, TestWarning, TestWithAnnotations, TestWithDifferentDurations, TestWithDifferentNames, TestWithDifferentOutput, TestWithDifferentSizes, TestWithDifferentStatuses, TestWithTest, Test\Issue3156Test, Test\Issue3379Test, ThrowExceptionTestCase, ThrowNoExceptionTestCase, TwoTest, WasRun. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
32
33
        $this->metadataFactory = $this->createMock(\Doctrine\Common\Persistence\Mapping\ClassMetadataFactory::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->metadataFactory is correct as $this->createMock(\Doctr...MetadataFactory::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...
34
        $this->collector       = new MappingCollector($this->metadataFactory, 'test-collector');
0 ignored issues
show
Documentation introduced by
$this->metadataFactory is of type null, but the function expects a object<Doctrine\Common\P...g\ClassMetadataFactory>.

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...
35
    }
36
37
    /**
38
     * @covers \DoctrineORMModule\Collector\MappingCollector::getName
39
     */
40
    public function testGetName()
41
    {
42
        $this->assertSame('test-collector', $this->collector->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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 \DoctrineORMModule\Collector\MappingCollector::getPriority
47
     */
48
    public function testGetPriority()
49
    {
50
        $this->assertIsInt($this->collector->getPriority());
0 ignored issues
show
Bug introduced by
The method assertIsInt() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
51
    }
52
53
    /**
54
     * @covers \DoctrineORMModule\Collector\MappingCollector::collect
55
     * @covers \DoctrineORMModule\Collector\MappingCollector::getClasses
56
     */
57
    public function testCollect()
58
    {
59
        $m1 = $this->createMock(\Doctrine\Common\Persistence\Mapping\ClassMetadata::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $m1 is correct as $this->createMock(\Doctr...g\ClassMetadata::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...
60
        $m1->expects($this->any())->method('getName')->will($this->returnValue('M1'));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
Bug introduced by
The method expects cannot be called on $m1 (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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
61
        $m2 = $this->createMock(\Doctrine\Common\Persistence\Mapping\ClassMetadata::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $m2 is correct as $this->createMock(\Doctr...g\ClassMetadata::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...
62
        $m2->expects($this->any())->method('getName')->will($this->returnValue('M2'));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
Bug introduced by
The method expects cannot be called on $m2 (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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
63
        $this
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\P...g\ClassMetadataFactory>.

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
            ->metadataFactory
65
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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
            ->method('getAllMetadata')
67
            ->will($this->returnValue([$m1, $m2]));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
68
69
        $this->collector->collect($this->createMock(\Laminas\Mvc\MvcEvent::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Laminas\Mvc\MvcEvent::class) is of type null, but the function expects a object<Laminas\Mvc\MvcEvent>.

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...
70
71
        $classes = $this->collector->getClasses();
72
73
        $this->assertCount(2, $classes);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
74
        $this->assertSame($classes['M1'], $m1);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
75
        $this->assertSame($classes['M2'], $m2);
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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
    }
77
78
    /**
79
     * @covers \DoctrineORMModule\Collector\MappingCollector::canHide
80
     */
81
    public function testCanHide()
82
    {
83
        $this->assertTrue($this->collector->canHide());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
84
85
        $m1 = $this->createMock(\Doctrine\Common\Persistence\Mapping\ClassMetadata::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $m1 is correct as $this->createMock(\Doctr...g\ClassMetadata::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...
86
        $m1->expects($this->any())->method('getName')->will($this->returnValue('M1'));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
Bug introduced by
The method expects cannot be called on $m1 (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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
87
        $this->metadataFactory->expects($this->any())->method('getAllMetadata')->will($this->returnValue([$m1]));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\P...g\ClassMetadataFactory>.

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...
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
88
89
        $this->collector->collect($this->createMock(\Laminas\Mvc\MvcEvent::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Laminas\Mvc\MvcEvent::class) is of type null, but the function expects a object<Laminas\Mvc\MvcEvent>.

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...
90
91
        $this->assertFalse($this->collector->canHide());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
92
    }
93
94
    /**
95
     * @covers \DoctrineORMModule\Collector\MappingCollector::serialize
96
     * @covers \DoctrineORMModule\Collector\MappingCollector::unserialize
97
     * @covers \DoctrineORMModule\Collector\MappingCollector::collect
98
     */
99
    public function testSerializeUnserializeAndCollectWithNoMetadataFactory()
100
    {
101
        $m1 = $this->createMock(\Doctrine\Common\Persistence\Mapping\ClassMetadata::class);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $m1 is correct as $this->createMock(\Doctr...g\ClassMetadata::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...
102
        $m1->expects($this->any())->method('getName')->will($this->returnValue('M1'));
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
Bug introduced by
The method expects cannot be called on $m1 (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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
103
        $this->metadataFactory->expects($this->any())->method('getAllMetadata')->will($this->returnValue([$m1]));
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<Doctrine\Common\P...g\ClassMetadataFactory>.

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...
Bug introduced by
The method any() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
Bug introduced by
The method returnValue() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
104
105
        $this->collector->collect($this->createMock(\Laminas\Mvc\MvcEvent::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Laminas\Mvc\MvcEvent::class) is of type null, but the function expects a object<Laminas\Mvc\MvcEvent>.

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...
106
107
        /* @var $collector MappingCollector */
108
        $collector = unserialize(serialize($this->collector));
109
110
        $classes = $collector->getClasses();
111
        $this->assertCount(1, $classes);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
112
        $this->assertEquals($m1, $classes['M1']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
113
        $this->assertSame('test-collector', $collector->getName());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
114
115
        $collector->collect($this->createMock(\Laminas\Mvc\MvcEvent::class));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Laminas\Mvc\MvcEvent::class) is of type null, but the function expects a object<Laminas\Mvc\MvcEvent>.

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...
116
117
        $classes = $collector->getClasses();
118
        $this->assertCount(1, $classes);
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
119
        $this->assertEquals($m1, $classes['M1']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DoctrineORMModule...r\MappingCollectorTest>.

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...
120
    }
121
}
122