2017 © Pedro Peláez
 

library phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

image

potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 22 Versions
  • 26 % Grown

The README.md

Traits for PHPUnit Testcases

![project-stage-badge] ![license-badge], (*1)

Traits that offer helper functions to be used in PHPUnit TestCases., (*2)

Introduction

This projects contains various traits that offer convenience methods for tasks that occur when creating test code., (*3)

Installation

composer require 'potherca/phpunit-testcase-traits'

Usage

Add a use statement for a desired trait to a class definition. The public API of that trait can then be used in the defined class., (*4)

For full details on how to use traits, please refer to the section on traits in the PHP manual., (*5)

PHP 5.3 compatibility

Traits were not introduced until PHP5.4 so for older versions (i.e. PHP5.3) another way to load the trait's functionality is needed. A traitShim function is provided that can be used from a magic __call method., (*6)

This is done by adding the following code to each (abstract base) test-case were a Trait is to be used(1):, (*7)


class ExampleTest extends \PHPUnit_Framework_TestCase { // .... final public function __call($name, array $parameters) { return \Potherca\PhpUnit\Shim\Util::traitShim($this, $name, $parameters); } // .... }

The public API of all traits can then be used., (*8)

In order to aid text-editors and IDEs in offering auto-completion, the following doc-block can be added to the test-case class:, (*9)

/**
 * @method array[] createDataProvider(array $subject)
 * @method \PHPUnit_Framework_MockObject_MockObject | \PHPUnit\Framework\MockObject\MockObject createObjectFromAbstractClass($className)
 * @method string getCompatibleExceptionName($exceptionName)
 * @method void setDataProviderMaximumKeyLength($length)
 * @method void setDataProviderSortByKey($sort)
 * @method void setNonPublicProperty($subject, $name, $value)
 */

(1) Alternatively, the src/Shim/function.traitShim.php could be loaded using composer's autoloader., (*10)

Available traits

  • CreateDataProviderTrait -- Create data-provider arrays.
    Creates a key/value pair from a given one-dimensional array of values, which is meant to be returned from a data-provider method in a TestCase., (*11)

  • CreateObjectFromAbstractClassTrait -- Create an object instance from an abstract class.
    Creates a concrete object whose methods can be called and, thus, be tested., (*12)

  • GetCompatibleExceptionNameTrait -- Provide names of PHP5 compatible PHPUnit_Framework_Exception for (new) PHP7 Exceptions., (*13)

  • SetNonPublicPropertyTrait -- Change the value of a non-public class properties., (*14)

Functioning usage examples are available in the example directory. All examples can be run with phpunit. Simply use the --config flag to point to the desired config file (either example-php-phpunit.xml for the traits or example-php53-phpunit.xml for the PHP5.3 compatible Trait shims)., (*15)

Colophon

The Versions

01/02 2018

dev-feature/v0.7.1/style-and-bug-fixes

dev-feature/v0.7.1/style-and-bug-fixes https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

25/01 2018

dev-master

9999999-dev https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0 GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

25/01 2018

v0.7.0

0.7.0.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

25/01 2018

dev-feature/v0.7.0/fix-argument-count-error-inconsistency

dev-feature/v0.7.0/fix-argument-count-error-inconsistency https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

25/01 2018

v0.6.1

0.6.1.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

24/01 2018

v0.6.0

0.6.0.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/01 2018

v0.5.9

0.5.9.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0-or-later

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/01 2018

v0.5.8

0.5.8.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

11/01 2018

v0.5.7

0.5.7.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

10/01 2018

v0.5.6

0.5.6.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

15/12 2017

v0.5.5

0.5.5.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

08/11 2017

v0.5.4

0.5.4.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

03/11 2017

v0.5.3

0.5.3.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

01/11 2017

v0.5.2

0.5.2.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

01/11 2017

v0.5.1

0.5.1.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

06/10 2017

v0.5.0

0.5.0.0 https://github.com/Potherca/phpunit-testcase-traits

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

04/10 2017

v0.4.1

0.4.1.0 https://gist.github.com/Potherca/c18d2772ecf2485dd4fa701e4abc7881/

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/06 2017

v0.4.0

0.4.0.0 https://gist.github.com/Potherca/c18d2772ecf2485dd4fa701e4abc7881/

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/06 2017

v0.3.0

0.3.0.0 https://gist.github.com/Potherca/c18d2772ecf2485dd4fa701e4abc7881/

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/06 2017

v0.2.0

0.2.0.0 https://gist.github.com/Potherca/c18d2772ecf2485dd4fa701e4abc7881/

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/06 2017

v0.1.0

0.1.0.0 https://gist.github.com/Potherca/c18d2772ecf2485dd4fa701e4abc7881/

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca

23/06 2017

v0.0.0

0.0.0.0 https://gist.github.com/Potherca/c18d2772ecf2485dd4fa701e4abc7881/

Traits that offer helper functions to be used in PHPUnit TestCases.

  Sources   Download

GPL-3.0

The Requires

 

phpunit testing helper trait tests traits test-case potherca