Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LastDragon-ru opened this issue Jan 8, 2025 · 0 comments
Open

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

LastDragon-ru opened this issue Jan 8, 2025 · 0 comments

Comments

@LastDragon-ru
Copy link

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.".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant