2017 © Pedro Peláez
 

joomla-package test

Joomla Test Helper Package

image

joomla/test

Joomla Test Helper Package

  • Tuesday, January 30, 2018
  • by mbabker
  • Repository
  • 10 Watchers
  • 2 Stars
  • 18,254 Installations
  • PHP
  • 33 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 14 Versions
  • 4 % Grown

The README.md

The Test Package

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This package is a collection of tools that make some jobs of unit testing easier., (*2)

TestCase

With version 7.0, PHPUnit added return type declarations to its TestCase class. Tests running fine PHP < 7.2 will not work on current PHP versions, because the signatures do not match., (*3)

This package provides a comatibility layer catering for that issue since version 1.4.2. Just extend your test classes from * Joomla\Test\TestCase instead of PHPUnit\Framework\TestCase and use method names * doSetUp() instead of setUp(), * doTearDown() instead of tearDown(), * doSetUpBeforeClass() instead of setUpBeforeClass() and * doTearDownAfterClass() instead of tearDownAfterClass()., (*4)

TestHelper

Joomla\Test\TestHelper is a static helper class that can be used to take some of the pain out of repetitive tasks whilst unit testing with PHPUnit., (*5)

Mocking

There are two methods that help with PHPUnit mock objects., (*6)

TestHelper::assignMockCallbacks

This helper method provides an easy way to configure mock callbacks in bulk., (*7)

use Joomla\Test\TestHelper;

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        // Create the mock.
        $mockFoo = $this->getMock(
            'Foo',
            // Methods array.
            array(),
            // Constructor arguments.
            array(),
            // Mock class name.
            '',
            // Call original constructor.
            false
        );

        $mockCallbacks = array(
            // 'Method Name' => <callback>
            'method1' => array('\mockFoo', 'method1'),
            'method2' => array($this, 'mockMethod2'),
        );

        TestHelper::assignMockCallbacks($mockFoo, $this, $mockCallbacks);
    }

    public function mockMethod2($value)
    {
        return strtolower($value);
    }
}

TestHelper::assignMockReturns

This helper method provides an easy way to configure mock returns values in bulk., (*8)

use Joomla\Test\TestHelper;

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        // Create the mock.
        $mockFoo = $this->getMock(
            'Foo',
            // Methods array.
            array(),
            // Constructor arguments.
            array(),
            // Mock class name.
            '',
            // Call original constructor.
            false
        );

        $mockReturns = array(
            // 'Method Name' => 'Canned return value'
            'method1' => 'canned result 1',
            'method2' => 'canned result 2',
            'method3' => 'canned result 3',
        );

        TestHelper::assignMockReturns($mockFoo, $this, $mockReturns);
    }
}

Reflection

There are three methods that help with reflection., (*9)

TestHelper::getValue

The TestHelper::getValue method allows you to get the value of any protected or private property., (*10)

use Joomla\Test\TestHelper;

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $instance = new \Foo;

        // Get the value of a protected `bar` property.
        $value = TestHelper::getValue($instance, 'bar');
    }
}

This method should be used sparingly. It is usually more appropriate to use PHPunit's assertAttribute* methods., (*11)

TestHelper::setValue

The TestHelper::setValue method allows you to set the value of any protected or private property., (*12)

use Joomla\Test\TestHelper;

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $instance = new \Foo;

        // Set the value of a protected `bar` property.
        TestHelper::setValue($instance, 'bar', 'New Value');
    }
}

This method is useful for injecting values into an object for the purpose of testing getter methods., (*13)

TestHelper::invoke

The TestHelper::invoke method allow you to invoke any protected or private method. After specifying the object and the method name, any remaining arguments are passed to the method being invoked., (*14)

use Joomla\Test\TestHelper;

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $instance = new \Foo;

        // Invoke the protected `bar` method.
        $value1 = TestHelper::invoke($instance, 'bar');

        // Invoke the protected `bar` method with arguments.
        $value2 = TestHelper::invoke($instance, 'bar', 'arg1', 'arg2');
    }
}

Installation via Composer

Add "joomla/test": "^1.4.2" to the require-dev block in your composer.json and then run composer install., (*15)

{
    "require-dev": {
        "joomla/test": "^1.4.2"
    }
}

Alternatively, you can simply run the following from the command line:, (*16)

composer require -- dev joomla/test "^1.4.2"

The Versions

30/01 2018

dev-master

9999999-dev https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

 

The Development Requires

phpunit framework reflection joomla unit test

13/04 2017

1.2.0

1.2.0.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

phpunit framework reflection joomla unit test

21/01 2017

1.1.6

1.1.6.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

phpunit framework reflection joomla unit test

21/01 2017

1.1.5

1.1.5.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

phpunit framework reflection joomla unit test

21/01 2017

1.1.4

1.1.4.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

phpunit framework reflection joomla unit test

21/01 2017

1.1.3

1.1.3.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

phpunit framework reflection joomla unit test

14/03 2015

1.1.2

1.1.2.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

The Development Requires

phpunit framework reflection joomla unit test

09/02 2014

1.1.1

1.1.1.0 https://github.com/joomla-framework/test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

 

phpunit framework reflection joomla unit test

29/11 2013

1.0

1.0.0.0 https://github.com/joomla/joomla-framework-test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

phpunit framework reflection joomla unit test

29/11 2013

1.1.0

1.1.0.0 https://github.com/joomla/joomla-framework-test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

phpunit framework reflection joomla unit test

22/10 2013

1.0-beta3

1.0.0.0-beta3 https://github.com/joomla/joomla-framework-test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

phpunit framework reflection joomla unit test

15/05 2013

1.0-alpha

1.0.0.0-alpha https://github.com/joomla/joomla-framework-test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

phpunit framework reflection joomla unit test

15/05 2013

1.0-beta

1.0.0.0-beta https://github.com/joomla/joomla-framework-test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

phpunit framework reflection joomla unit test

15/05 2013

1.0-beta2

1.0.0.0-beta2 https://github.com/joomla/joomla-framework-test

Joomla Test Helper Package

  Sources   Download

GPL-2.0+

The Requires

  • php >=5.3.10

 

phpunit framework reflection joomla unit test