Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Traits are not supported (`Mockery::mock()`)

Open
#78 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
testing

Research direction

Start by reproducing the two Mockery::mock() examples, comparing a class-only mock with one that includes trait T. Trace how the extension handles Mockery::mock() arguments and verify that trait methods are represented while unknown methods remain rejected; the dumped type should no longer be NEVER.

Written by the indexing model from the issue text.

Description

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

Dominant language
PHP
Stars
109
Forks
25
Avg merge
1h 41m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-mockery

All issues in phpstan/phpstan-mockery

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.