Skip to content

Instantly share code, notes, and snippets.

@jlem
Last active August 29, 2015 14:23
Show Gist options
  • Save jlem/665a3b94b27b924193c9 to your computer and use it in GitHub Desktop.
Save jlem/665a3b94b27b924193c9 to your computer and use it in GitHub Desktop.
Example unit test
class BottomNavTest extends PHPUnit_Framework_Testcase
{
public function test_buttons_are_constructed_from_php_config_and_have_the_given_order()
{
// Defined in JSON, mocked here
$buttonOrder = ['home', 'pages', 'pierce', 'map', 'on-scene'];
// Configuration for buttons lives in PHP for now
$buttonConfig = [
['identifier' => 'pierce', 'target' => '#control'],
['identifier' => 'home', 'target' => '#home'],
['identifier' => 'pages', 'target' => '#'],
['identifier' => 'on-scene', 'target' => '#on-scene'],
['identifier' => 'map', 'target' => '#']
];
// Construct the bottom navigation bar with button configuration data
$BottomNav = new BottomNav($buttonConfig);
// Manually define the expected result - an array of BottomNavButtons in the correct order
$expectedResult = [
new BottomNavButton('home', '#home'),
new BottomNavButton('pages', '#'),
new BottomNavButton('pierce', '#control'),
new BottomNavButton('map', '#'),
new BottomNavButton('on-scene', '#on-scene')
];
// Obtain the actual result we want to compare against - a list of buttons ordered by the given order
$actualResult = $BottomNav->getButtons($buttonOrder);
// Make the assertion - if they are the same, test passes.
$this->assertSame($expectedResult, $actualResult);
}
public function test_buttons_are_constructed_from_json_config_and_have_the_given_order()
{
// repeat the test, but with data source from JSON config
$this->assertSame($expectedResult, $actualResult);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment