Skip to content

Return intersection type from Generator::getMock() #32

Closed
@Stadly

Description

@Stadly

The easiest way to create mock objects outside of a test case is through PHPUnit\Framework\MockObject\Generator::getMock(). This method does not return intersection types, like PHPUnit\Framework\MockObject\MockBuilder::getMock() and PHPUnit\Framework\TestCase::createMock() does.

Example:

interface A {}

function foo(): A
{
    $generator = new PHPUnit\Framework\MockObject\Generator();
    return $generator->getMock(A::class);
}
 ------ -------------------------------------------------------------------------
  Line   test.php
 ------ -------------------------------------------------------------------------
  5      Function foo() should return A but returns
         PHPUnit\Framework\MockObject\MockObject.
 ------ -------------------------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions