2017 © Pedro Peláez
 

library cakephp-test-utilities

Package with support traits to ease unit testing.

image

friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  • Saturday, March 24, 2018
  • by jippi
  • Repository
  • 9 Watchers
  • 10 Stars
  • 31,370 Installations
  • PHP
  • 27 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 6 Versions
  • 6 % Grown

The README.md

Test utilities

This package contains support traits to ease unit testing., (*1)

Installing via composer

You should install this package into your project using composer. To do so you can run the following command:, (*2)

composer require friendsofcake/cakephp-test-utilities

Traits

At this point there are two traits:, (*3)

  1. AccessibilityHelperTrait : Gain access protected properties and methods.
  2. CompareTrait : Assert methods, comparing to files for: HTML, JSON, XML

AccessibilityHelperTrait

This trait gains you access to protected properties and methods. You don't need of a new class with pass-through methods. It uses reflection to achieve this., (*4)

Setup

Add the trait at the top of your test case:, (*5)

``` php use \FriendsOfCake\TestUtilities\AccessibilityHelperTrait;, (*6)


Now that you have the trait you need to set which object you want to access. You can do this globally for the entire test in `setUp()` or in your test methods: ``` php $object = new ObjectIAmGoingToTest(); $this->setReflectionClassInstance($object); $this->defaultReflectionTarget = $object; // (optional)

Protected properties

You can get and set the protected properties:, (*7)

``` php $data = 'FriendsOfCake'; $this->setProtectedProperty('_myProperty', $data, $object);, (*8)

$expected = $data; $actual = $this->getProtectedProperty('_myProperty', $object); $this->assertEquals($expected, $actual);, (*9)


#### Protected methods You can directly call protected methods: ``` php $parameters = [$argument1, $argument2]; $expected = $expectedReturnValue; $actual = $this->callProtectedMethod('_myMethod', $parameters, $object); $this->assertEquals($expected, $actual);

CompareTrait

This trait helps with comparing test results as string, (*10)

Setup

Add the trait at the top of your test case and define the _compareBasePath property so the trait knows where to look for comparison files:, (*11)

``` php ... use \FriendsOfCake\TestUtilities\CompareTrait;, (*12)

class MyTest extends TestCase { use CompareTrait;, (*13)

public function setUp(): void
{
    parent::setUp();

    $this->_compareBasePath = 'comparisons/MyTest/';
}

}, (*14)


#### Usage Each of the methods acts similar to the core `assertSameAsFile` method: ```php public function testExample() { $html = '

Some html, (*15)

'; $xml = '<thing>...</thing>'; $json = ['actually' => 'this is an array']; $this->assertHtmlSameAsFile('some.html', $html); $this->assertXmlSameAsFile('some.xml', $xml); $this->assertJsonSameAsFile('some.json', $json); }

See Cake's docs for more details on usage of assertSameAsFile on which these methods are based., (*16)

The Versions

24/03 2018

dev-master

9999999-dev https://github.com/friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Graaf

test phpunit unit testing unittesting

24/03 2018

1.0.2

1.0.2.0 https://github.com/friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Graaf

test phpunit unit testing unittesting

24/03 2018

1.0.0

1.0.0.0 https://github.com/friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Graaf

test phpunit unit testing unittesting

24/03 2018

dev-ad-compare-trait

dev-ad-compare-trait https://github.com/friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Frank de Graaf

test phpunit unit testing unittesting

02/12 2015

0.0.2

0.0.2.0 https://github.com/friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Frank de Graaf

test phpunit unit testing unittesting

28/06 2015

0.0.1

0.0.1.0 https://github.com/friendsofcake/cakephp-test-utilities

Package with support traits to ease unit testing.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

by Frank de Graaf

test phpunit unit testing unittesting