<?php
class WtfTest extends IP_Story {
public function setUp() {
$this->db->contract->query('TRUNCATE TABLE `engnames`');
$this->db->planner->query('TRUNCATE TABLE `areas`');
$this->db->planner->query('TRUNCATE TABLE `engineers_skills`');
$this->db->planner->query('TRUNCATE TABLE `skills`');
}
/**
* @scenario
*/
public function engineersWithLPGAndWarmAir() {
$this->given('New Area')
->and('New Skill', 'LPG')
->and('New Skill', 'Warm Air')
->and('New Engineer', 'LPG', 'Warm Air')
->and('New Engineer', 'LPG')
->and('New Engineer', 'Warm Air')
->when('Skill Required', 'LPG')
->and('Skill Required', 'Warm Air')
->then('Engineer names should be', 'LPG and Warm Air');
}
/**
* @scenario
*/
public function engineersWithLPG() {
$this->given('New Area')
->and('New Skill', 'LPG')
->and('New Skill', 'Warm Air')
->and('New Engineer', 'LPG', 'Warm Air')
->and('New Engineer', 'LPG')
->and('New Engineer', 'Warm Air')
->when('Skill Required', 'LPG')
->then('Engineer names should be', 'LPG', 'LPG and Warm Air');
}
/**
* @scenario
*/
public function engineersWithWarmAir() {
$this->given('New Area')
->and('New Skill', 'LPG')
->and('New Skill', 'Warm Air')
->and('New Engineer', 'LPG', 'Warm Air')
->and('New Engineer', 'LPG')
->and('New Engineer', 'Warm Air')
->when('Skill Required', 'Warm Air')
->then('Engineer names should be', 'LPG and Warm Air', 'Warm Air');
}
public function runWhen(&$world, $action, $arguments) {
switch ($action) {
case 'Unavailable':
break;
case 'Skill Required':
$world['required_skills'][] = $world['skills'][$arguments[0]];
break;
default: {
return $this->notImplemented($action);
}
}
}
public function runThen(&$world, $action, $arguments) {
switch ($action) {
case 'Engineer names should be':
// Get the valid engineers.
$valid_engineers = ORM::factory('engineer')
->find_by_skills($world['required_skills']);
// Check there's the same number.
$this->assertEquals(count($arguments), count($valid_engineers), 'Engineer Count');
// Get the list of names.
$actual_eng_names = array(); foreach ($valid_engineers as $e) {
$actual_eng_names[] = $e->NAME;
}
// Sort both so they should match in order.
// Check each name is there.
foreach ($arguments as $key => $expected) {
$this->assertEquals($expected, $actual_eng_names[$key]);
}
break;
default: {
return $this->notImplemented($action);
}
}
}
}