rootwork/phpunit-helpers

2.0.0 2017-06-27 18:21 UTC

This package is auto-updated.

Last update: 2024-10-20 22:15:08 UTC


README

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']);
    }
}