Skip to content

rootworkit/phpunit-helpers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHPUnit Helpers

Helper traits for PHPUnit

"You can touch your privates and you can touch your friends' privates but you can't touch your parents' privates... unless they're protected." -Unknown

Installation

Install composer in a common location or in your project:

curl -s http://getcomposer.org/installer | php

Create the composer.json file as follows:

{
    "require": {
        "rootwork/phpunit-helpers": "dev-master"
    }
}

Run the composer installer:

php composer.phar install

Usage

namespace Test;

use Rootwork\PHPUnit\Helper\Accessor;

class MyTest extends \PHPUnit_Framework_TestCase
{
    use Accessor;

    public function testThings()
    {
        $sut = new MyThing();

        // Set a non-public property
        $this->setPropertyValue($sut, 'someNonPublicProperty', 'foo');

        // Get a non-public property
        $result = $this->getPropertyValue($sut, 'someNonPublicProperty'); // foo

        // Invoke a non-public method
        $this->invokeMethod($sut, 'someNonPublicMethod', ['foo', 'bar']);

        // Invoke a non-public method with arguments
        $this->invokeMethod($sut, 'someNonPublicMethod', ['foo', 'bar']);
    }
}

Packages

No packages published

Languages