phpunitgoodpractices / traits
Highly opinionated PHPUnit good practices enforcer.
Installs: 233 531
Dependents: 6
Suggesters: 0
Security: 0
Stars: 22
Watchers: 3
Forks: 2
Open Issues: 4
Requires
- php: ^5.5 || ^7.0 || ^8.0
- phpunit/phpunit: ^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ~8.5 || ~9.4
Requires (Dev)
- phpspec/prophecy: ^1.10
- phpunitgoodpractices/polyfill: ^1.1
- sanmai/phpunit-legacy-adapter: ^6.1 || ^8.0
README
With great shape of PHPUnit itself and Static Code Analysers supporting it, this package is no longer needed.
PHPUnit Good Practices
Highly opinionated PHPUnit good practices enforcer.
Available traits
ExpectationViaCodeOverAnnotationTrait
Expected exception shall be set up via code, not annotations.
ExpectOverSetExceptionTrait
Expectation shall be set directly over via setter.
IdentityOverEqualityTrait
Identity assertion (===
) shall be used over equality ones (==
).
ProphecyOverMockObjectTrait
Prophecy shall be used over Mock Objects.
ProphesizeOnlyInterfaceTrait
Prophecy shall be created only for (existing) interfaces.
Example usage
<?php namespace FooProject\Tests; use PHPUnit\Framework\TestCase; use PHPUnitGoodPractices\Traits\ExpectationViaCodeOverAnnotationTrait; use PHPUnitGoodPractices\Traits\ExpectOverSetExceptionTrait; use PHPUnitGoodPractices\Traits\IdentityOverEqualityTrait; use PHPUnitGoodPractices\Traits\ProphecyOverMockObjectTrait; use PHPUnitGoodPractices\Traits\ProphesizeOnlyInterfaceTrait; final class FooTest extends TestCase { use ExpectationViaCodeOverAnnotationTrait; use ExpectOverSetExceptionTrait; use IdentityOverEqualityTrait; use ProphecyOverMockObjectTrait; use ProphesizeOnlyInterfaceTrait; public function testBar() { $this->assertEquals(123, 213); // will report non-strict assertion usage } }