Skip to content

Latest commit

 

History

History
executable file
·
122 lines (86 loc) · 2.58 KB

TESTING.md

File metadata and controls

executable file
·
122 lines (86 loc) · 2.58 KB

Testing Mustached Robot

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 Tests

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

Writing Tests

Where do they go?

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

File / Class Naming

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

Test Grouping

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.

Namespaces

App tests can be in any namespace.

What class do I extend?

All tests should extend the Fuel\Core\TestCase class.

Example

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);
	}

}