calgamo / test
Utility class/trait for test. Supports PHPUnit
Installs: 3 524
Dependents: 10
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1
- calgamo/exception: ~0.1
- calgamo/filesystem: ~0.6
- phpunit/phpunit: ^6.3.0
- stk2k/decoy: ~0.3
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^6.3.0
README
Description
Calgamo/Test is a library of test.
Feature
Demo
Exsample 1: get private/protected property
use Calgamo\Test\TestCase\PhpUnitTestCase; class TestTarget { private $foo; public function __construct() { $this->foo = 123; } } class MyTest extends PhpUnitTestCase { public function testGetPrivateProperty() { $object = new TestTarget(); // get private property from object $value = $this->getPrivatePropertyWithoutException($object, 'foo'); // assert $this->assertSame(123, $value); } }
Exsample 2: call private/protected method
class TestTarget { /** @noinspection PhpUnusedPrivateMethodInspection */ private function sayHello() { return 'Hello'; } } class MyTest extends PhpUnitTestCase { public function testCallPrivateMethod() { $object = new TestTarget(); // call private method $ret = $this->callPrivateMethodWithoutException($object, 'sayHello'); // assert if result is not right $this->assertSame('Hello', $ret); } }
Exsample 3: call private/protected static method
class TestTarget { /** @noinspection PhpUnusedPrivateMethodInspection */ private static function sayBye() { return 'Bye'; } } class MyTest extends PhpUnitTestCase { public function testCallPrivateMethod() { // call private static method $ret = $this->callPrivateStaticMethodWithoutException(TestTarget::class, 'sayBye'); // assert if result is not right $this->assertSame('Bye', $ret); } }
Exsample 4: callback if exception is thrown in specified callback
class TestTarget { /** * @throws \Exception */ public function doSomething() { throw new \Exception('Emergency'); } } class MyTest extends PhpUnitTestCase { public function testCallbackIfExceptionIsThrown() { $this->callbackIfExceptionIsThrown( function(){ (new TestTarget)->doSomething(); }, function(\Throwable $e){ $this->fail('something wrong: ' . $e->getMessage()); }); } }
Usage
Requirement
PHP 7.1 or later
Installing calgamo/test
The recommended way to install calgamo/test is through Composer.
composer require calgamo/test
After installing, you need to require Composer's autoloader:
require 'vendor/autoload.php';
License
Author
Disclaimer
This software is no warranty.
We are not responsible for any results caused by the use of this software.
Please use the responsibility of the your self.