Skip to content

Traits are not supported (Mockery::mock()) #78

@LastDragon-ru

Description

@LastDragon-ru

Mockery::mock() allow to add traits into mocks:

<?php declare(strict_types = 1);

class C {
    public function helloClass(): string { return 'hello class'; }
}

trait T {
    public function helloTrait(): string { return 'hello trait'; }
}

$mock = Mockery::mock(C::class, T::class);
$mock->makePartial();

\PHPStan\dumpType($mock);

echo $mock->helloTrait();

will output hello trait. Unfortunately, it is not supported by this extension (and seems phpstan also cannot create intersections with traits?) so the dumped type will be *NEVER* -> the $mock->helloTrait() actually not validated at all... :(

Mockery::mock(C::class)->helloUnknown();           // Call to an undefined method C&Mockery\MockInterface::helloUnknown()
Mockery::mock(C::class, T::class)->helloUnknown(); // nothing 

If we are on Level 10 and doing something like Mockery::mock(C::class)->getSomething()->method(); we also will get "Cannot call method method() on mixed.".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions