Mustached Robot uses PHPUnit for it's Unit Testing needs. It must be installed for the tests to run.
NOTE: No code will be accepted without tests written.
Running the unit tests is as simple as navigating to the root install folder on the command line and running the following:
$ php oil test
That's it! You can also tell it specific groups (which we will get into in minute) to run. For example to run only the App tests (exluding the FuelPHP tests):
$ php oil test --group=App
All tests are to go in the tests folders inside their respective parent folder. For instance:
- App tests go in fuel/app/tests
- Package tests go in fuel/packages/package_name/tests
- Module tests go in fuel/modules/module_name/tests
The Test class names should be in the form of Tests_Whatever.
Filenames should be all lower case and be the class name minus the "Tests_" part.
Some example names:
// Good
Tests_Arr in fuel/core/tests/arr.php
Tests_Image in fuel/core/tests/image.php
Tests_Fuel in fuel/core/tests/fuel.php
// Bad
Arrtests
Somestuff
All tests inside the app folder must be in the app group. A classes test's should also be grouped together under the name of the class.
Here is an example of a core class test with proper DocBlocks:
/**
* Arr class tests
*
* @group Core
* @group Arr
*/
class Tests_Arr extends TestCase {
/**
* Tests Arr::get()
*
* @test
*/
public function test_get()
{
// Test code here
}
}
All Plugins tests should be in the Plugin group.
App tests can be in any namespace.
All tests should extend the Fuel\Core\TestCase class.
namespace Fuel\Core;
/**
* Arr class tests
*
* @group Core
* @group Arr
*/
class Tests_Arr extends TestCase {
/**
* Tests Arr::flatten_assoc()
*
* @test
*/
public function test_flatten_assoc()
{
$people = array(
array(
"name" => "Jack",
"age" => 21
),
array(
"name" => "Jill",
"age" => 23
)
);
$expected = array(
"0:name" => "Jack",
"0:age" => 21,
"1:name" => "Jill",
"1:age" => 23
);
$output = Arr::flatten_assoc($people);
$this->assertEquals($expected, $output);
}
}