cekurte / tdd
PHPUnit TestCase
v1.0.2
2016-04-29 19:19 UTC
Requires
- php: >=5.3
Requires (Dev)
- fabpot/php-cs-fixer: ^1.10
- phpunit/phpunit: ^4.8
This package is auto-updated.
Last update: 2024-10-16 02:11:04 UTC
README
- Just a simple extension to the PHPUnit library.
- Currently this package contains only support for one TestCase scenario ReflectionTestCase contribute with this project!
Installation
- The package is available on Packagist.
- The source files is PSR-2 compatible.
- Autoloading is PSR-4 compatible.
composer require cekurte/tdd
If you liked of this library, give me a star =).
Documentation
This library was created to permit that developers write php unit tests using a common base class, including initially the following tasks:
- Set a private, protected or public property value;
- Get a private, protected or public property value;
- Call a private, protected or public method.
Setting a property value
To set a property value (independently of your visibility) you can use the method ReflectionTestCase::propertySetValue like the following example:
<?php namespace Your\Namespace; use Cekurte\Tdd\ReflectionTestCase; class YourClassTest extends ReflectionTestCase { public function testAnything() { // Instance of a class that has one // private property named "yourPrivateProperty". $instance = new YourClass(); // Set the value "newValue" to the property // "yourPrivateProperty". $this->propertySetValue( $instance, 'yourPrivateProperty', 'newValue' ); // ... } }
Getting a property value
To get a property value (independently of your visibility) you can use the method ReflectionTestCase::propertyGetValue like the following example:
<?php namespace Your\Namespace; use Cekurte\Tdd\ReflectionTestCase; class YourClassTest extends ReflectionTestCase { public function testAnything() { // Instance of a class that has one // private property named "yourPrivateProperty". $instance = new YourClass(); // Get the value of the property // "yourPrivateProperty". $currentValue = $this->propertyGetValue( $instance, 'yourPrivateProperty' ); // ... } }
Calling a method
To call a method (independently of your visibility) you can use the method ReflectionTestCase::invokeMethod like the following example:
<?php namespace Your\Namespace; use Cekurte\Tdd\ReflectionTestCase; class YourClassTest extends ReflectionTestCase { public function testAnything() { // Instance of a class that has one // private property named "yourPrivateMethod". $instance = new YourClass(); // Call the method // "yourPrivateMethod". $valueReturned = $this->invokeMethod( $instance, 'yourPrivateMethod', ['param1', 'param2', 'paramN'] ); // ... } }
Contributing
- Give me a star =)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Make your changes
- Run the tests, adding new ones for your own code if necessary (
vendor/bin/phpunit
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request