Search by

php-extended / placeholder-phpunit

anastaszor

A library that shows only the interfaces of phpunit, without requiring all the dependancies

Package info

gitlab.com/php-extended/placeholder-phpunit

Issues

pkg:composer/php-extended/placeholder-phpunit

Statistics

Installs: 94 614

Dependents: 244

Suggesters: 0

Stars: 0

10.1.2 2026-10-03 15:45 UTC

README

A library that shows only the interfaces of phpunit, without requiring all the dependancies, for IDE autocompletion purposes. Tests still requires phpunit libraries or phars to work !

coverage

Installation

The installation of this library is made via composer and the autoloading of all classes of this library is made through their autoloader.

  • Download composer.phar from their website.
  • Then run the following command to install this library as dependency :
  • php composer.phar install php-extended/placeholder-phpunit ^9

This library ^X mocks phpunit X.

What is mirrored, and what is deliberately different

The goal is that static analysers (phpstan, psalm) see the same types as with the real phpunit, so that they can analyse test code without it.

Mirrored from phpunit 10 :

  • MockObject\Stub and MockObject\MockObject are interfaces, as in phpunit. This is what makes createMock(SomeConcreteClass::class) resolve to MockObject&SomeConcreteClass : with classes, the intersection of two unrelated classes is never.
  • method() is available on both (returning an InvocationStubber on a stub, an InvocationMocker on a mock) and on InvocationMocker itself, so that expects(...)->method('x')->willReturn(...) resolves.
  • The PHPUnit\Framework\Attributes classes (DataProvider, CoversClass, Group, ...) and the constraint factories of Assert (anything(), equalTo(), isInstanceOf(), stringContains(), ...) that return a Constraint.
  • fail(), markTestIncomplete() and markTestSkipped() return never.

Deliberately different :

  • No @throws is declared on the assertions (assert*()), the mock factories (createMock(), createStub(), ...) and the invocation builders (with(), willReturn(), ...). In phpunit they throw ExpectationFailedException or MockObject\Exception, which end the test and are never handled by the test code. Declaring them makes an analyser that checks exceptions demand a @throws tag on every single test method, for no information. Only the exceptions thrown by the code under test have to be declared.
  • PlaceholderMockObject is a class that does not exist in phpunit (there, the doubles are generated at runtime) : the factory methods need to return an object that implements MockObject.
  • Constraint is a single class here, where phpunit has one class per constraint.

License

MIT (See license file).