13 require_once(dirname(dirname(dirname(__DIR__))) .
'/lib/php/Test/Reflectory.php');
14 require_once(dirname(dirname(dirname(__DIR__))) .
'/lib/php/Plugin/FO_Plugin.php');
15 require_once(dirname(dirname(dirname(__DIR__))) .
'/lib/php/common-plugin.php');
16 require_once(dirname(dirname(dirname(__DIR__))) .
'/lib/php/common-menu.php');
17 require_once(dirname(dirname(dirname(__DIR__))) .
'/lib/php/common-job.php');
39 private $assertCountBefore;
45 protected function setUp():
void
49 if (!class_exists(
'AgentAdder',
false)) {
50 $GLOBALS[
'SysConf'] = [];
51 $GLOBALS[
'container'] =
new class {
52 public function get($name)
54 return new \stdClass();
57 require_once(__DIR__ .
'/../../ui/agent-add.php');
60 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
65 $this->callLog = array();
67 $GLOBALS[
'SysConf'][
'auth'][
'UserId'] = 1;
68 $GLOBALS[
'SysConf'][
'auth'][
'GroupId'] = 1;
72 $this->agentAdder = (new \ReflectionClass(
'AgentAdder'))->newInstanceWithoutConstructor();
75 protected function tearDown():
void
77 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
87 $log = &$this->callLog;
88 $plugin =
new class($pluginName, $log) {
92 public function __construct($name, &$log)
95 $this->
State = PLUGIN_STATE_READY;
98 public function AgentAdd(...$args)
100 $this->log[] =
"$this->Name:AgentAdd";
103 public function scheduleAgent(...$args)
105 $this->log[] =
"$this->Name:scheduleAgent";
111 $Plugins[$pluginName] = $plugin;
115 private function mockContainer($uploadFilename =
'test.tar')
117 $dbManager = M::mock(DbManager::class);
118 $dbManager->shouldReceive(
'getSingleRow')->andReturn([
'job_pk' => 1]);
120 $upload = M::mock(Upload::class);
121 $upload->shouldReceive(
'getFilename')->andReturn($uploadFilename);
122 $uploadDao = M::mock(
'stdClass');
123 $uploadDao->shouldReceive(
'getUpload')->andReturn($upload);
125 $container = M::mock(
'ContainerBuilder');
126 $container->shouldReceive(
'get')->with(
'db.manager')->andReturn($dbManager);
127 $container->shouldReceive(
'get')->with(
'dao.upload')->andReturn($uploadDao);
129 $GLOBALS[
'container'] = $container;
142 $this->mockContainer();
147 $request = new \Symfony\Component\HttpFoundation\Request(
148 [], [
'agents' => [
'agent_nomos',
'agent_decider',
'agent_scancode']]
151 $result = Reflectory::invokeObjectsMethodnameWith(
152 $this->agentAdder,
'agentsAdd', [42, [
'agent_nomos',
'agent_decider',
'agent_scancode'], $request]
155 $this->assertSame(1, $result);
157 $nomosIdx = array_search(
'agent_nomos:AgentAdd', $this->callLog);
158 $scancodeIdx = array_search(
'agent_scancode:scheduleAgent', $this->callLog);
159 $deciderIdx = array_search(
'agent_decider:scheduleAgent', $this->callLog);
161 $this->assertNotFalse($nomosIdx,
'nomos was never scheduled');
162 $this->assertNotFalse($scancodeIdx,
'scancode was never scheduled');
163 $this->assertNotFalse($deciderIdx,
'decider was never scheduled');
164 $this->assertLessThan($deciderIdx, $nomosIdx,
'nomos must be queued before decider');
165 $this->assertLessThan($deciderIdx, $scancodeIdx,
'scancode must be queued before decider');
179 $this->mockContainer();
183 $request = new \Symfony\Component\HttpFoundation\Request(
184 [], [
'agents' => [
'agent_decider',
'agent_scancode']]
187 Reflectory::invokeObjectsMethodnameWith(
188 $this->agentAdder,
'agentsAdd', [42, [
'agent_decider',
'agent_scancode'], $request]
191 $scheduleIdx = array_search(
'agent_scancode:scheduleAgent', $this->callLog);
192 $agentAddIdx = array_search(
'agent_scancode:AgentAdd', $this->callLog);
194 $this->assertNotFalse($scheduleIdx);
195 $this->assertNotFalse($agentAddIdx);
196 $this->assertLessThan($agentAddIdx, $scheduleIdx);
207 $request = new \Symfony\Component\HttpFoundation\Request();
209 $result = Reflectory::invokeObjectsMethodnameWith(
210 $this->agentAdder,
'agentsAdd', [42,
'not-an-array', $request]
213 $this->assertSame(
'bad parameters', $result);
Test for AgentAdder::agentsAdd(), covering the scheduling-order fix @runTestsInSeparateProcesses @pre...
testPlainAgentsAndReorderedParmAgentsRunBeforeDecider()
testRejectsNonArrayAgentsToStart()
registerLoggingPlugin($menu, $pluginName)
testScancodeScheduleAgentRunsBeforeItsOwnLeftoverAgentAddPass()