public function testShouldResetAssertionCountOnTestStart() { $listener = new TestListener(); // Bump the hamcrest assertion count by 1. assertThat(true, is(true)); $this->assertSame(1, MatcherAssert::getCount(), 'Hamcrest is not counting assertions correctly.'); $listener->startTest(Mockery::mock(PHPUnit_Framework_Test::class)); $this->assertSame(0, MatcherAssert::getCount(), 'The listener did not reset the hamcrest assertion count.'); }
/** * @param PHPUnit_Framework_Test $test * @param float $time */ public function endTest(\PHPUnit_Framework_Test $test, $time) { try { if ($test instanceof \PHPUnit_Framework_TestCase) { $test->addToAssertionCount(MatcherAssert::getCount()); } } catch (\Exception $e) { $result = $test->getTestResultObject(); $result->addError($test, $e, $time); } }
/** * Adds Hamcrest assertion counts to PHPUnit */ public function runBare() { $e = null; ha::resetCount(); try { parent::runBare(); } catch (\Exception $e) { } $this->addToAssertionCount(ha::getCount()); if ($e !== null) { throw $e; } }
/** * Collects assertions performed by Hamcrest matchers during the test. * * @throws Exception */ public function runBare() { MatcherAssert::resetCount(); try { parent::runBare(); } catch (\Exception $exception) { // rethrown below } $this->addToAssertionCount(MatcherAssert::getCount()); if (isset($exception)) { throw $exception; } }
protected function tearDown() { $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); }
public function runAndTestReport($uploadId = 1) { list($success, $output, $retCode) = $this->runnerCli->run($uploadId, $this->userId, $this->groupId, $jobId = 7); assertThat('cannot run runner', $success, equalTo(true)); assertThat('report failed: "' . $output . '"', $retCode, equalTo(0)); assertThat($this->getHeartCount($output), greaterThan(0)); $row = $this->dbManager->getSingleRow("SELECT upload_fk,job_fk,filepath FROM reportgen WHERE job_fk = \$1", array($jobId), "reportFileName"); assertThat($row, hasKeyValuePair('upload_fk', $uploadId)); assertThat($row, hasKeyValuePair('job_fk', $jobId)); $filepath = $row['filepath']; assertThat($filepath, endsWith('.rdf')); assertThat(file_exists($filepath), equalTo(true)); $copyrightStatement = '*****@*****.**'; assertThat(file_get_contents($filepath), stringContainsInOrder($copyrightStatement)); $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); $this->verifyRdf($filepath); unlink($filepath); $this->rmRepo(); }
protected function tearDown() { $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); $this->testDb = null; $this->dbManager = null; }
public function testAssertThatWithFourArgsThrowsErrorAndDoesntIncrementCount() { try { \Hamcrest\MatcherAssert::assertThat(1, 2, 3, 4); self::fail('expected invalid argument exception'); } catch (\InvalidArgumentException $ex) { self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } }
public function testGetMappedLicenseRefView() { $this->testDb = new TestPgDb(); $this->testDb->createPlainTables(array('license_ref', 'license_map')); $this->dbManager = $this->testDb->getDbManager(); $this->dbManager->queryOnce("CREATE TABLE license_candidate (group_fk integer) INHERITS (license_ref)"); $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => 2, 'rf_parent' => 1, 'usage' => LicenseMap::CONCLUSION)); $this->dbManager->insertTableRow('license_ref', array('rf_pk' => 1, 'rf_shortname' => 'One', 'rf_fullname' => 'One-1')); $this->dbManager->insertTableRow('license_ref', array('rf_pk' => 2, 'rf_shortname' => 'Two', 'rf_fullname' => 'Two-2')); $this->dbManager->insertTableRow('license_candidate', array('rf_pk' => 3, 'rf_shortname' => 'Three', 'rf_fullname' => 'Three-3', 'group_fk' => $this->groupId)); $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount(); $view = LicenseMap::getMappedLicenseRefView(LicenseMap::CONCLUSION); $stmt = __METHOD__; $this->dbManager->prepare($stmt, $view); $res = $this->dbManager->execute($stmt); $map = $this->dbManager->fetchAll($res); $this->dbManager->freeResult($res); assertThat($map, is(arrayWithSize(2))); $expected = array(array('rf_origin' => 1, 'rf_pk' => 1, 'rf_shortname' => 'One', 'rf_fullname' => 'One-1'), array('rf_origin' => 2, 'rf_pk' => 1, 'rf_shortname' => 'One', 'rf_fullname' => 'One-1')); assertThat($map, containsInAnyOrder($expected)); }
public function testGetAgentFileLicenseMatchesWithLicenseMapping() { $this->testDb->createPlainTables(array('license_ref', 'uploadtree', 'license_file', 'agent', 'license_map')); $this->testDb->insertData_license_ref(); $lic0 = $this->dbManager->getSingleRow("Select * from license_ref limit 1", array(), __METHOD__ . '.anyLicense'); $licRefId = $lic0['rf_pk']; $licenseFileId = 1; $pfileId = 42; $agentId = 23; $matchPercent = 50; $uploadtreeId = 512; $uploadID = 123; $left = 2009; $right = 2014; $agentName = "fake"; $agentRev = 1; $lic1 = $this->dbManager->getSingleRow("SELECT * FROM license_ref WHERE rf_pk!=\$1 LIMIT 1", array($licRefId), __METHOD__ . '.anyOtherLicense'); $licVarId = $lic1['rf_pk']; $mydate = "'2014-06-04 14:01:30.551093+02'"; $this->dbManager->insertTableRow('license_map', array('license_map_pk' => 0, 'rf_fk' => $licVarId, 'rf_parent' => $licRefId, 'usage' => LicenseMap::CONCLUSION)); $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk, rf_fk, agent_fk, rf_match_pct, rf_timestamp, pfile_fk)\n VALUES ({$licenseFileId}, {$licVarId}, {$agentId}, {$matchPercent}, {$mydate}, {$pfileId})"); $this->dbManager->queryOnce("INSERT INTO uploadtree (uploadtree_pk, upload_fk, pfile_fk, lft, rgt)\n VALUES ({$uploadtreeId}, {$uploadID}, {$pfileId}, {$left}, {$right})"); $stmt = __METHOD__ . '.insert.agent'; $this->dbManager->prepare($stmt, "INSERT INTO agent (agent_pk, agent_name, agent_rev, agent_enabled) VALUES (\$1,\$2,\$3,\$4)"); $this->dbManager->execute($stmt, array($agentId, $agentName, $agentRev, 'true')); $licDao = new LicenseDao($this->dbManager); $itemTreeBounds = new ItemTreeBounds($uploadtreeId, "uploadtree", $uploadID, $left, $right); $matches = $licDao->getAgentFileLicenseMatches($itemTreeBounds, LicenseMap::CONCLUSION); $licenseRef = new LicenseRef($licRefId, $lic0['rf_shortname'], $lic0['rf_fullname']); $agentRef = new AgentRef($agentId, $agentName, $agentRev); $expected = array(new LicenseMatch($pfileId, $licenseRef, $agentRef, $licenseFileId, $matchPercent)); assertThat($matches, equalTo($expected)); $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore); }