protected function setUp() { $this->uploadDao = M::mock(UploadDao::classname()); $this->treeDao = M::mock(TreeDao::classname()); $container = M::mock('ContainerBuilder'); $GLOBALS['container'] = $container; $container->shouldReceive('get')->with('dao.upload')->andReturn($this->uploadDao); $container->shouldReceive('get')->with('dao.tree')->andReturn($this->treeDao); $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount(); }
protected function setUp() { global $container; $this->highlightDao = M::mock(HighlightDao::classname()); $container->shouldReceive('get')->withArgs(array('dao.highlight'))->andReturn($this->highlightDao); $container->shouldReceive('get')->withArgs(array('dao.upload'))->andReturn(M::mock(UploadDao::classname())); $container->shouldReceive('get')->withArgs(array('dao.clearing'))->andReturn(M::mock(ClearingDao::classname())); $container->shouldReceive('get')->withArgs(array('decision.types'))->andReturn(M::mock(DecisionTypes::classname())); $container->shouldReceive('get')->withArgs(array('businessrules.clearing_decision_processor'))->andReturn(M::mock(ClearingDecisionProcessor::classname())); $container->shouldReceive('get')->withArgs(array('businessrules.agent_license_event_processor'))->andReturn(M::mock(AgentLicenseEventProcessor::classname())); $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount(); }
protected function setUp() { $this->uploadDao = M::mock(UploadDao::classname()); $logger = new Logger('default'); $logger->pushHandler(new ErrorLogHandler()); $this->testDb = new TestPgDb(); $this->dbManager =& $this->testDb->getDbManager(); $this->clearingDao = new ClearingDao($this->dbManager, $this->uploadDao); $this->testDb->createPlainTables(array('clearing_decision', 'clearing_decision_event', 'clearing_decision_type', 'clearing_event', 'clearing_licenses', 'highlight_bulk', 'license_ref', 'license_ref_bulk', 'license_set_bulk', 'users', 'uploadtree')); $this->testDb->createInheritedTables(); $userArray = array(array('myself', 1), array('in_same_group', 2), array('in_trusted_group', 3)); foreach ($userArray as $ur) { $this->dbManager->insertInto('users', 'user_name, root_folder_fk', $ur); } $refArray = array(array(401, 'FOO', 'foo full', 'foo text'), array(402, 'BAR', 'bar full', 'bar text'), array(403, 'BAZ', 'baz full', 'baz text'), array(404, 'QUX', 'qux full', 'qux text')); foreach ($refArray as $params) { $this->dbManager->insertInto('license_ref', 'rf_pk, rf_shortname, rf_fullname, rf_text', $params, $logStmt = 'insert.ref'); } $modd = 536888320; $modf = 33188; /* (pfile,item,lft,rgt) upload101: upload101/ ( 0, 299, 1, 4) Afile (201, 301, 1, 2) Bfile (202, 302, 3, 4) upload102: upload102/ ( 0, 300, 1, 8) Afile (201, 303, 1, 2) A-dir/ ( 0, 304, 3, 6) A-dir/Afile (201, 305, 4, 5) Bfile (202, 306, 7, 8) */ $this->items = array(299 => array(101, 299, 0, $modd, 1, 4, "upload101"), 300 => array(102, 300, 0, $modd, 1, 8, "upload102"), 301 => array(101, 301, 201, $modf, 1, 2, "Afile"), 302 => array(101, 302, 202, $modf, 3, 4, "Bfile"), 303 => array(102, 303, 201, $modf, 1, 2, "Afile"), 304 => array(102, 304, 0, $modd, 3, 6, "A-dir"), 305 => array(102, 305, 201, $modf, 4, 5, "Afile"), 306 => array(102, 306, 202, $modf, 7, 8, "Bfile")); foreach ($this->items as $ur) { $this->dbManager->insertInto('uploadtree', 'upload_fk,uploadtree_pk,pfile_fk,ufile_mode,lft,rgt,ufile_name', $ur); } $this->now = time(); $bulkLicArray = array(array(1, 401, 'TextFOO', false, 101, 299, $this->groupId), array(2, 402, 'TextBAR', false, 101, 299, $this->groupId), array(3, 403, 'TextBAZ', true, 101, 301, $this->groupId), array(4, 403, 'TextBAZ', false, 101, 299, $this->groupId), array(5, 404, 'TextQUX', true, 101, 299, $this->groupId), array(6, 401, 'TexxFOO', true, 101, 302, $this->groupId), array(7, 403, 'TextBAZ', false, 102, 300, $this->groupId), array(8, 403, 'TextBAZ', true, 102, 306, $this->groupId)); foreach ($bulkLicArray as $params) { $paramsRef = array($params[0], $params[2], $params[4], $params[5], $params[6]); $paramsSet = array($params[0], $params[1], $params[3]); $this->dbManager->insertInto('license_ref_bulk', 'lrb_pk, rf_text, upload_fk, uploadtree_fk, group_fk', $paramsRef, 'insert.bulkref'); $this->dbManager->insertInto('license_set_bulk', 'lrb_fk, rf_fk, removing', $paramsSet, 'insert.bulkset'); } $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount(); }
public function testDeciderScanWithTwoEventAndNoAgentShouldMakeADecision() { $this->setUpTables(); $this->setUpRepo(); $dbManager = M::mock(DbManager::classname()); $agentDao = M::mock(AgentDao::classname()); $clearingDao = M::mock(ClearingDao::classname()); $uploadDao = M::mock(UploadDao::classname()); $highlightDao = M::mock(HighlightDao::classname()); $decisionProcessor = M::mock(ClearingDecisionProcessor::classname()); $agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::classname()); $uploadId = 13243; /*mock for Agent class **/ $agentDao->shouldReceive('arsTableExists')->andReturn(true); $agentDao->shouldReceive('getCurrentAgentId')->andReturn($agentId = 24); $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId)->andReturn($arsId = 2); $agentDao->shouldReceive('writeArsRecord')->with(anything(), $agentId, $uploadId, $arsId, true)->andReturn(0); $jobId = 42; $groupId = 6; $userId = 2; $itemIds = array(4343, 43); $bounds0 = M::mock(ItemTreeBounds::classname()); $bounds0->shouldReceive('getItemId')->andReturn($itemIds[0]); $bounds0->shouldReceive('containsFiles')->andReturn(false); $bounds1 = M::mock(ItemTreeBounds::classname()); $bounds1->shouldReceive('getItemId')->andReturn($itemIds[1]); $bounds1->shouldReceive('containsFiles')->andReturn(false); $bounds = array($bounds0, $bounds1); $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[0])->andReturn($bounds[0]); $uploadDao->shouldReceive('getItemTreeBounds')->with($itemIds[1])->andReturn($bounds[1]); $clearingDao->shouldReceive('getEventIdsOfJob')->with($jobId)->andReturn(array($itemIds[0] => array(), $itemIds[1] => array())); $dbManager->shouldReceive('begin')->times(count($itemIds)); $dbManager->shouldReceive('commit')->times(count($itemIds)); /* dummy expectations needed for unmockable LicenseMap constructor */ $dbManager->shouldReceive('prepare'); $res = M::Mock(DbManager::classname()); $dbManager->shouldReceive('execute')->andReturn($res); $row1 = array('rf_fk' => 2334, 'parent_fk' => 1); $row2 = array('rf_fk' => 2333, 'parent_fk' => 1); $dbManager->shouldReceive('fetchArray')->with($res)->andReturn($row1, $row2, false); $dbManager->shouldReceive('freeResult')->with($res); /* /expectations for LicenseMap */ $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds0, $groupId, array(), anything())->andReturn(true); $clearingDao->shouldReceive('markDecisionAsWip')->with($itemIds[0], $userId, $groupId); $decisionProcessor->shouldReceive('hasUnhandledScannerDetectedLicenses')->with($bounds1, $groupId, array(), anything())->andReturn(false); $decisionProcessor->shouldReceive('makeDecisionFromLastEvents')->with($bounds1, $userId, $groupId, DecisionTypes::IDENTIFIED, false, array()); $runner = new SchedulerTestRunnerMock($dbManager, $agentDao, $clearingDao, $uploadDao, $highlightDao, $decisionProcessor, $agentLicenseEventProcessor); list($success, $output, $retCode) = $runner->run($uploadId, $userId, $groupId, $jobId, $args = ""); $this->assertTrue($success, 'cannot run decider'); $this->assertEquals($retCode, 0, 'decider failed: ' . $output); assertThat($this->getHeartCount($output), equalTo(count($itemIds))); $this->rmRepo(); }