1. Go to this page and download the library: Download joomla/test library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
joomla / test example snippets
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);
}
}
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);
}
}
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');
}
}
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');
}
}
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');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.