2017 © Pedro Peláez
 

library test-util

PHPUnit test case utilities

image

atanvarno/test-util

PHPUnit test case utilities

  • Friday, May 19, 2017
  • by atanvarno
  • Repository
  • 0 Watchers
  • 0 Stars
  • 50 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Atanvarno\PHPUnit

Software License Latest Version, (*1)

Utility traits for PHPUnit test cases for interacting with protected and private methods and properties., (*2)

Requirements

PHP >= 7.0 is required, but the latest stable version of PHP is recommended., (*3)

Installation

$ composer require atanvarno/test-util:^0.1.0

Basic Usage

class YourTest extends \PHPUnit\Framework\TestCase
{
    // Include the traits
    use Atanvarno\PHPUnit\{CallProtectedMethodTrait, SetProtectedPropertyTrait};

    // Write your tests
    public function testYourMethod()
    {
        $testObject = new SomeClass();

        // Set an inaccessible property
        $this->setProtectedProperty($testObject, 'propertyName', 'value');

        // Call an inaccessible method
        $result = $this->callProtectedMethod(
            $testObject,
            'methodName',
            ['argument 1', 'argument 2', '...']
        );

        // Do your assertations
        // ...
    }
}

Atanvarno\PHPUnit\CallProtectedMethodTrait

Provides means to call a protected or private method of an object for test purposes., (*4)

public function callProtectedMethod($object, string $method, array $arguments = [])

Calls a protected or private method and returns its result., (*5)

Parameters

  • object $object, (*6)

    Required. The instance containing the method to call., (*7)

  • string $method, (*8)

    Required. The method name., (*9)

  • mixed[] $arguments, (*10)

    Optional. Defaults to []. Arguments to pass to the method., (*11)

Throws

Returns

  • mixed, (*14)

    The return value of the method call., (*15)

Atanvarno\PHPUnit\SetProtectedPropertyTrait

Provides means to set a protected or private property of an object for test purposes., (*16)

public function setProtectedProperty($object, string $property, $value)

Sets a protected or private property., (*17)

Parameters

  • object $object, (*18)

    Required. The instance containing the property to set., (*19)

  • string $property, (*20)

    Required. The property name., (*21)

  • mixed $value, (*22)

    Required. The value to set., (*23)

Throws

Returns

  • void

The Versions

19/05 2017

dev-master

9999999-dev https://github.com/atanvarno69/test-util

PHPUnit test case utilities

  Sources   Download

MIT

The Requires

  • php ^7.0

 

test phpunit utility utilities

06/05 2017

0.1.0

0.1.0.0 https://github.com/atanvarno69/test-util

PHPUnit test case utilities

  Sources   Download

MIT

The Requires

  • php ^7.0

 

test phpunit utility utilities