avinash403/phpunit-testing-kit

Gives all the helper traits and classes that you will ever need to test a PHP application

v1.0.0 2018-05-30 18:50 UTC

This package is not auto-updated.

Last update: 2024-03-25 11:17:06 UTC


README

Collection of useful traits and classes that can be handy while testing a PHP application.

Installation by Composer

$ composer require avinash403/phpunit-testing-kit

Available Traits

Assertions

Contains some common assertions that is commonly used but PHPunit doesn't provide it.

USAGE

use TestingKit\Assertions;
use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
	use Assertions;

	public function test_exampleTest()
	{
		$this->assertAlpha('a');
	}
}

Available Assertions

	* assertAlpha
	* assertNotAlpha
	* assertNumber
	* assertNotNumber
	* assertArrayHasKeys
	* assertStringContainsSubstring
	* assertStringNotContainsSubstring

PrivateAccess

Allows testing private and protected method and properties of a class.

USAGE

use TestingKit\PrivateAccess;
use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
	use PrivateAccess;

	public function test_exampleTest_forGettingPrivateMethod()
	{
		$classObject = new Class();
		
		//getting private method
		$methodResponse = $this->getPrivateMethod($classObject, 'exampleMethod', ['some text']);
		
		$this->assertEquals($methodResponse, 'some text');
	}
}

class ExampleClass
{
	private exampleMethod($someArgument)
	{
		return $someArgument;
	}
}

Available Features

	* getPrivateMethod
	* setPrivateProperty
	* getPrivateProperty

Test

Run test by simply typing composer test from the root directory of this package.

Contribute on github

clone this repository( https://github.com/avinash403/laravel-dynamic-observer.git ), make your changes and raise a pull request to development branch