30 private $uploadId = 25;
31 private $olderAgentId = 3;
32 private $otherAgentId = 4;
34 private $incompleteAgentId = 6;
36 private $agentName =
"agentName";
37 private $otherAgentName =
"otherAgentName";
39 private $agentRev =
"<agentRev>";
40 private $olderAgentRev =
"<olderAgentRev>";
41 private $otherAgentRev =
"<otherAgentRev>";
42 private $incompleteAgentRev =
"<incompleteAgentRev>";
44 private $agentDesc =
"<agentDesc>";
45 private $otherAgentDesc =
"<otherAgentDesc>";
47 private $agentEnabled =
true;
68 private $incompleteAgent;
70 protected function setUp()
72 $this->
dbManager = M::mock(DbManager::class);
73 $this->logger = M::mock(
'Monolog\Logger');
76 $this->
dbManager = &$this->testDb->getDbManager();
78 $this->agent =
new AgentRef($this->agentId, $this->agentName, $this->agentRev);
79 $this->olderAgent =
new AgentRef($this->olderAgentId, $this->agentName, $this->olderAgentRev);
80 $this->otherAgent =
new AgentRef($this->otherAgentId, $this->otherAgentName, $this->otherAgentRev);
81 $this->incompleteAgent =
new AgentRef($this->incompleteAgentId, $this->agentName, $this->incompleteAgentRev);
83 $this->testDb->createPlainTables(
89 array($this->olderAgentId, $this->agentName, $this->olderAgentRev, $this->agentDesc, $this->
dbManager->booleanToDb($this->agentEnabled)),
90 array($this->otherAgentId, $this->otherAgentName, $this->otherAgentRev, $this->otherAgentDesc, $this->
dbManager->booleanToDb($this->agentEnabled)),
91 array($this->agentId, $this->agentName, $this->agentRev, $this->agentDesc, $this->
dbManager->booleanToDb($this->agentEnabled)),
92 array($this->incompleteAgentId, $this->agentName, $this->incompleteAgentRev, $this->agentDesc, $this->
dbManager->booleanToDb($this->agentEnabled)),
94 foreach ($agentArray as $agentRow) {
95 $this->
dbManager->insertInto(
'agent',
'agent_pk, agent_name, agent_rev, agent_desc, agent_enabled', $agentRow);
99 $arsTableName = $this->agentName . AgentDao::ARS_TABLE_SUFFIX;
100 $this->
dbManager->queryOnce(
"create table " . $arsTableName .
" (ars_pk int, agent_fk int, upload_fk int, ars_success bool)");
102 array(1, $this->olderAgentId, $this->uploadId, $this->
dbManager->booleanToDb(
true)),
103 array(2, $this->agentId, $this->uploadId, $this->
dbManager->booleanToDb(
true)),
104 array(3, $this->incompleteAgentId, $this->uploadId, $this->
dbManager->booleanToDb(
false))
106 foreach ($arsArray as $arsRow) {
107 $this->
dbManager->insertInto($arsTableName,
'ars_pk, agent_fk, upload_fk, ars_success', $arsRow);
110 $arsTableName = $this->otherAgentName . AgentDao::ARS_TABLE_SUFFIX;
111 $this->
dbManager->queryOnce(
"create table " . $arsTableName .
" (ars_pk int, agent_fk int, upload_fk int, ars_success bool)");
113 array(1, $this->otherAgentId, $this->uploadId, $this->
dbManager->booleanToDb(
true)),
115 foreach ($arsArray as $arsRow) {
116 $this->
dbManager->insertInto($arsTableName,
'ars_pk, agent_fk, upload_fk, ars_success', $arsRow);
120 protected function tearDown()
122 $this->
dbManager->queryOnce(
"drop table " . $this->agentName . AgentDao::ARS_TABLE_SUFFIX);
123 $this->
dbManager->queryOnce(
"drop table " . $this->otherAgentName . AgentDao::ARS_TABLE_SUFFIX);
126 $this->testDb = null;
131 public function testGetCurrentAgent()
133 assertThat($this->agentsDao->getCurrentAgentRef($this->agentName), is($this->incompleteAgent));
134 $this->addToAssertionCount(1);
137 public function testGetSuccessfulAgentRuns()
139 assertThat($this->agentsDao->getSuccessfulAgentRuns($this->agentName, $this->uploadId), is(array($this->agent, $this->olderAgent)));
140 $this->addToAssertionCount(1);
143 public function testGetLatestAgentResultForUpload()
146 $container = M::mock(
'ContainerBuilder');
147 $this->dbManagerMock = M::mock(DbManager::class);
148 $container->shouldReceive(
'get')->withArgs(array(
'db.manager'))->andReturn($this->dbManagerMock);
150 $this->dbManagerMock->shouldReceive(
'prepare')->once();
151 $this->dbManagerMock->shouldReceive(
'execute')->once();
152 $this->dbManagerMock->shouldReceive(
'fetchArray')
153 ->andReturn(array(
'agent_pk'=>$this->agentId,
'agent_name'=>$this->agentName),
154 array(
'agent_pk'=>$this->otherAgentId,
'agent_name'=>$this->otherAgentName),
156 $this->dbManagerMock->shouldReceive(
'freeResult')->once();
158 $latestAgentResults = $this->agentsDao->getLatestAgentResultForUpload($this->uploadId, array($this->agentName, $this->otherAgentName));
159 assertThat($latestAgentResults, is(array(
160 $this->agentName => $this->agentId,
161 $this->otherAgentName => $this->otherAgentId
163 $this->addToAssertionCount(1);
166 public function testGetRunningAgentIds()
168 assertThat($this->agentsDao->getRunningAgentIds($this->uploadId, $this->agentName), is(array($this->incompleteAgentId)));
169 $this->addToAssertionCount(1);
172 public function testGetRunningAgentIdsForFinishedAgent()
174 assertThat($this->agentsDao->getRunningAgentIds($this->uploadId, $this->otherAgentName), is(emptyArray()));
175 $this->addToAssertionCount(1);
178 public function testGetRunningAgentIdsForUnknownAgent()
180 assertThat($this->agentsDao->getRunningAgentIds($this->uploadId,
"unknown"), is(emptyArray()));
181 $this->addToAssertionCount(1);
184 public function testArsTableExists()
186 $this->assertTrue($this->agentsDao->arsTableExists($this->agentName));
189 public function testArsTableExistsReturnsFalseIfTableDoesNotExist()
191 $this->assertFalse($this->agentsDao->arsTableExists(
"unknown"));
fo_dbManager * dbManager
fo_dbManager object