protected function setUp()
 {
     global $container;
     $container = M::mock('ContainerBuilder');
     $this->dbManagerMock = M::mock(DbManager::classname());
     $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManagerMock);
     $this->almostAllColumns = 'rf_pk,rf_shortname,rf_text,rf_url,rf_add_date,rf_copyleft,rf_fullname,rf_notes,marydone,rf_active,rf_text_updatable,rf_md5,rf_detector_type,rf_source';
 }
 protected function setUp()
 {
     $this->folderDao = M::mock(FolderDao::classname());
     $this->dbManager = M::mock(DbManager::classname());
     $this->folderNav = new FolderNav($this->dbManager, $this->folderDao);
     $this->uri = Traceback_uri();
     $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
 }
 protected function setUp()
 {
     $this->dbViewDao = new DbViewProxy($this->dbViewQuery, $this->dbViewName);
     global $container;
     $container = M::mock('ContainerBuilder');
     $this->dbManagerMock = M::mock(DbManager::classname());
     $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManagerMock);
 }
 public function testSetEnclosure()
 {
     $dbManager = M::mock(DbManager::classname());
     $licenseCsvExport = new LicenseCsvExport($dbManager);
     $reflection = new \ReflectionClass($licenseCsvExport);
     $enclosure = $reflection->getProperty('enclosure');
     $enclosure->setAccessible(true);
     $licenseCsvExport->setEnclosure('|');
     assertThat($enclosure->getValue($licenseCsvExport), is('|'));
     $licenseCsvExport->setEnclosure('<>');
     assertThat($enclosure->getValue($licenseCsvExport), is('<'));
 }
 protected function setUp()
 {
     $this->licenseDao = M::mock(LicenseDao::classname());
     $this->agentsDao = M::mock(AgentDao::classname());
     $this->itemTreeBounds = M::mock(ItemTreeBounds::classname());
     $this->agentLicenseEventProcessor = new AgentLicenseEventProcessor($this->licenseDao, $this->agentsDao);
     global $container;
     $this->dbManagerMock = M::mock(DbManager::classname());
     $this->dbManagerMock->shouldReceive('prepare');
     $this->dbManagerMock->shouldReceive('execute');
     $this->dbManagerMock->shouldReceive('fetchArray')->andReturn($this->latestScanners[0], $this->latestScanners[1], false);
     $this->dbManagerMock->shouldReceive('freeResult');
     $container = M::mock('ContainerBuilder');
     $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManagerMock);
 }
 protected function setUp()
 {
     $this->uploadTreeId = 432;
     $this->pfileId = 32;
     $this->userId = 12;
     $this->groupId = 5;
     $this->timestamp = time();
     $this->clearingDao = M::mock(ClearingDao::classname());
     $this->agentLicenseEventProcessor = M::mock(AgentLicenseEventProcessor::classname());
     $this->clearingEventProcessor = new ClearingEventProcessor();
     $this->itemTreeBounds = M::mock(ItemTreeBounds::classname());
     $this->itemTreeBounds->shouldReceive("getItemId")->withNoArgs()->andReturn($this->uploadTreeId);
     $this->itemTreeBounds->shouldReceive("getPfileId")->withNoArgs()->andReturn($this->pfileId);
     $this->dbManager = M::mock(DbManager::classname());
     $this->dbManager->shouldReceive('begin')->withNoArgs();
     $this->dbManager->shouldReceive('commit')->withNoArgs();
     $this->clearingDecisionProcessor = new ClearingDecisionProcessor($this->clearingDao, $this->agentLicenseEventProcessor, $this->clearingEventProcessor, $this->dbManager);
     $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();
 }
 public function testHandleFile()
 {
     $dbManager = M::mock(DbManager::classname());
     $licenseCsvImport = new LicenseCsvImport($dbManager);
     $filename = tempnam("/tmp", "FOO");
     $handle = fopen($filename, 'w');
     fwrite($handle, "shortname,fullname,text");
     fclose($handle);
     $msg = $licenseCsvImport->handleFile($filename);
     assertThat($msg, startsWith(_('head okay')));
     unlink($filename);
 }
namespace Fossology\Decider;

use Fossology\Lib\Data\LicenseMatch;
use Mockery as M;
use Fossology\Lib\Test\Reflectory;
use Fossology\Lib\Dao\HighlightDao;
use Fossology\Lib\Db\DbManager;
use Fossology\Lib\Dao\AgentDao;
use Fossology\Lib\BusinessRules\AgentLicenseEventProcessor;
use Fossology\Lib\BusinessRules\ClearingDecisionProcessor;
use Fossology\Lib\Dao\ClearingDao;
use Fossology\Lib\Dao\UploadDao;
use Fossology\Lib\Data\DecisionTypes;
global $container;
$container = M::mock('ContainerBuilder');
$container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn(M::mock(DbManager::classname()));
$agentDao = M::mock(AgentDao::classname());
$agentDao->shouldReceive('getCurrentAgentId')->andReturn(1234);
$container->shouldReceive('get')->withArgs(array('dao.agent'))->andReturn($agentDao);
require_once __DIR__ . '/../../../lib/php/Test/Agent/AgentTestMockHelper.php';
require_once __DIR__ . '/../../agent/DeciderAgent.php';
class DeciderAgentTest extends \PHPUnit_Framework_TestCase
{
    private $highlightDao;
    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()));
 public function testGetLatestAgentResultForUpload()
 {
     global $container;
     $container = M::mock('ContainerBuilder');
     $this->dbManagerMock = M::mock(DbManager::classname());
     $container->shouldReceive('get')->withArgs(array('db.manager'))->andReturn($this->dbManagerMock);
     $this->dbManagerMock->shouldReceive('prepare')->once();
     $this->dbManagerMock->shouldReceive('execute')->once();
     $this->dbManagerMock->shouldReceive('fetchArray')->andReturn(array('agent_pk' => $this->agentId, 'agent_name' => $this->agentName), array('agent_pk' => $this->otherAgentId, 'agent_name' => $this->otherAgentName), false);
     $this->dbManagerMock->shouldReceive('freeResult')->once();
     $latestAgentResults = $this->agentsDao->getLatestAgentResultForUpload($this->uploadId, array($this->agentName, $this->otherAgentName));
     assertThat($latestAgentResults, is(array($this->agentName => $this->agentId, $this->otherAgentName => $this->otherAgentId)));
     $this->addToAssertionCount(1);
 }