maks3w / phpunit-methods-trait
Provide PHPUnit method signatures as traits for IDE autocomplete
Installs: 1 233
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: >= 7.4
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-code: ^4.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-03 08:10:34 UTC
README
Provide a PHP Trait with methods present in PHPUnit Test Framework and expected to be implemented by TestCase.
This is useful when traits are used for test reuse, and it's necessary to access to PHPUnit\Framework\TestCase methods from the trait.
Installing via Composer
You can use Composer .
composer require maks3w/phpunit-methods-trait
Usage
Example of use in a trait
use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; trait FooTrait { use \Maks3w\PhpUnitMethodsTrait\Framework\TestCaseTrait; public function testFoo() { $mockFoo = $this->getMock('Foo'); $mockFoo->expects(TestCase::any()) ->method('getFoo') ->willReturn(true) ; Assert::assertTrue($mockFoo->getFoo()); } }
FAQ
- Q: Assertion methods are not recognized. Why?
- A: Assertion methods like `assertTrue` are static methods present in `PHPUnit\Framework\Assert` just access them using static method call `PHPUnit\Framework\Assert::assertTrue(...)`
License
Code licensed under BSD 2 clauses terms & conditions.
See LICENSE.txt for more information.