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.');
 }
Example #2
0
 /**
  * @test
  */
 public function it_displays_an_error_for_unresolved_characters()
 {
     $this->container['repository.test'] = new InMemoryRepository();
     $this->commandTester->execute(['command' => SearchCommand::COMMAND_NAME, '--from' => 'test', 'codepoint' => '1']);
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('Character Not Found'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(1)));
 }
 /**
  * @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);
     }
 }
Example #4
0
 /**
  * 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;
     }
 }
 /**
  * @test
  */
 public function it_displays_characters_residing_in_a_supplied_script()
 {
     $repository = new InMemoryRepository();
     $codepoint = Codepoint::fromInt(97);
     $script = Script::fromValue(Script::LATIN);
     $character = $this->buildCharacterWithCodepoint($codepoint, null, null, $script);
     $characters = Collection::fromArray([$character]);
     $repository->addMany($characters);
     $this->container['repository.test'] = $repository;
     $this->commandTester->execute(['command' => PropertiesCommand::COMMAND_NAME, '--from' => 'test', 'property-type' => PropertiesCommand::PROPERTY_SCRIPT, 'value' => $script->getValue()]);
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('U+61:'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
 /**
  * @test
  */
 public function it_transfers_characters_from_one_repository_to_another()
 {
     $codepoint = Codepoint::fromInt(1);
     $character = $this->buildCharacterWithCodepoint($codepoint);
     $characters = Collection::fromArray([$character]);
     $source = new InMemoryRepository();
     $source->addMany($characters);
     $destination = new InMemoryRepository();
     $this->container['repository.test-source'] = $source;
     $this->container['repository.test-destination'] = $destination;
     ha::assertThat(count($source), hm::is(hm::identicalTo(1)));
     ha::assertThat(count($destination), hm::is(hm::identicalTo(0)));
     $this->commandTester->execute(['command' => RepositoryTransferCommand::COMMAND_NAME, 'from' => 'test-source', 'to' => 'test-destination']);
     ha::assertThat(count($source), hm::is(hm::identicalTo(1)));
     ha::assertThat(count($destination), hm::is(hm::identicalTo(1)));
     $output = $this->commandTester->getDisplay();
     $statusCode = $this->commandTester->getStatusCode();
     ha::assertThat('output', $output, hm::containsString('Database Generated'));
     ha::assertThat('status code', $statusCode, hm::is(hm::identicalTo(0)));
 }
Example #8
0
 /**
  * @test
  */
 public function it_can_be_added_to_if_writable()
 {
     if (!$this->repository instanceof WritableRepository) {
         $this->markTestSkipped('Repository is not writable');
     }
     $codepoint = Codepoint::fromInt(1);
     $addCharacter = $this->buildCharacterWithCodepoint($codepoint);
     $addCharacters = Character\Collection::fromArray([$addCharacter]);
     $this->repository->addMany($addCharacters);
     $character = $this->repository->getByCodepoint($codepoint);
     ha::assertThat('character', $character, hm::is(hm::equalTo($addCharacter)));
     ha::assertThat('count', count($this->repository), hm::is(hm::equalTo(2)));
 }
Example #9
0
 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();
 }
Example #10
0
 protected function tearDown()
 {
     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
     $this->testDb = null;
     $this->dbManager = null;
 }
Example #11
0
 protected function setUp()
 {
     \Hamcrest\MatcherAssert::resetCount();
 }
Example #12
0
 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);
 }
Example #13
0
 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 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');
     }
 }
 /**
  * @Then /^The Consumer "([^"]*)" has been called once with message "([^"]*)"$/
  */
 public function theConsumerHasBeenCalledOnceWithMessage($consumerId, $message)
 {
     $consumerCalls = $this->getContainer()->get($consumerId)->getCallback()[0]->getExecuteCalls();
     ha::assertThat(count($consumerCalls), hm::is(hm::identicalTo(1)));
     ha::assertThat($message, hm::is(hm::identicalTo($consumerCalls[0]->body)));
 }
Example #16
0
 protected function tearDown()
 {
     $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
 }
Example #17
0
 public function testHamcrestMatcher()
 {
     $uuid1 = Uuid::fromString(self::UUID4_STRING);
     $uuid2 = Uuid::fromString(self::UUID1_STRING);
     MatcherAssert::assertThat($uuid1, $uuid1);
     $this->setExpectedException(AssertionError::class, 'Expected: "' . self::UUID1_STRING . '"' . PHP_EOL . '     but: was "' . self::UUID4_STRING . '"');
     MatcherAssert::assertThat($uuid1, $uuid2);
 }