EngineerSkillsTest.php

  1. <?php
  2.  
  3. class WtfTest extends IP_Story {
  4. public function setUp() {
  5. $this->db->contract->query('TRUNCATE TABLE `engnames`');
  6. $this->db->planner->query('TRUNCATE TABLE `areas`');
  7. $this->db->planner->query('TRUNCATE TABLE `engineers_skills`');
  8. $this->db->planner->query('TRUNCATE TABLE `skills`');
  9. }
  10.  
  11. /**
  12. * @scenario
  13. */
  14. public function engineersWithLPGAndWarmAir() {
  15. $this->given('New Area')
  16. ->and('New Skill', 'LPG')
  17. ->and('New Skill', 'Warm Air')
  18. ->and('New Engineer', 'LPG', 'Warm Air')
  19. ->and('New Engineer', 'LPG')
  20. ->and('New Engineer', 'Warm Air')
  21. ->when('Skill Required', 'LPG')
  22. ->and('Skill Required', 'Warm Air')
  23. ->then('Engineer names should be', 'LPG and Warm Air');
  24. }
  25.  
  26. /**
  27. * @scenario
  28. */
  29. public function engineersWithLPG() {
  30. $this->given('New Area')
  31. ->and('New Skill', 'LPG')
  32. ->and('New Skill', 'Warm Air')
  33. ->and('New Engineer', 'LPG', 'Warm Air')
  34. ->and('New Engineer', 'LPG')
  35. ->and('New Engineer', 'Warm Air')
  36. ->when('Skill Required', 'LPG')
  37. ->then('Engineer names should be', 'LPG', 'LPG and Warm Air');
  38. }
  39.  
  40. /**
  41. * @scenario
  42. */
  43. public function engineersWithWarmAir() {
  44. $this->given('New Area')
  45. ->and('New Skill', 'LPG')
  46. ->and('New Skill', 'Warm Air')
  47. ->and('New Engineer', 'LPG', 'Warm Air')
  48. ->and('New Engineer', 'LPG')
  49. ->and('New Engineer', 'Warm Air')
  50. ->when('Skill Required', 'Warm Air')
  51. ->then('Engineer names should be', 'LPG and Warm Air', 'Warm Air');
  52. }
  53.  
  54. public function runWhen(&$world, $action, $arguments) {
  55. switch ($action) {
  56. case 'Unavailable':
  57. break;
  58. case 'Skill Required':
  59. $world['required_skills'][] = $world['skills'][$arguments[0]];
  60. break;
  61. default: {
  62. return $this->notImplemented($action);
  63. }
  64. }
  65. }
  66.  
  67. public function runThen(&$world, $action, $arguments) {
  68. switch ($action) {
  69. case 'Engineer names should be':
  70. // Get the valid engineers.
  71. $valid_engineers = ORM::factory('engineer')
  72. ->find_by_skills($world['required_skills']);
  73.  
  74. // Check there's the same number.
  75. $this->assertEquals(count($arguments), count($valid_engineers), 'Engineer Count');
  76.  
  77. // Get the list of names.
  78. $actual_eng_names = array();
  79. foreach ($valid_engineers as $e) {
  80. $actual_eng_names[] = $e->NAME;
  81. }
  82.  
  83. // Sort both so they should match in order.
  84. sort($actual_eng_names);
  85. sort($arguments);
  86.  
  87. // Check each name is there.
  88. foreach ($arguments as $key => $expected) {
  89. $this->assertEquals($expected, $actual_eng_names[$key]);
  90. }
  91. break;
  92. default: {
  93. return $this->notImplemented($action);
  94. }
  95. }
  96. }
  97. }
  98.