public function testTraitShouldAddCallablesAsProcessors()
 {
     $mock = new MockProcessorAwareClass();
     $processor = function () {
         return [];
     };
     $mock->addProcessor($processor);
     assertThat('There should only be the one processor we added.', $mock->getProcessors(), is(arrayContaining($processor)));
 }
 public function testMismatchesItemsInAnyOrder()
 {
     $matcher = arrayContaining(array(1, 2, 3));
     $this->assertMismatchDescription('was null', $matcher, null);
     $this->assertMismatchDescription('No item matched: <1>', $matcher, array());
     $this->assertMismatchDescription('No item matched: <2>', $matcher, array(1));
     $this->assertMismatchDescription('item with key 0: was <4>', $matcher, array(4, 3, 2, 1));
     $this->assertMismatchDescription('item with key 2: was <4>', $matcher, array(1, 2, 4));
 }
Example #3
0
 public function testTraitShouldAddCallablesAsFilters()
 {
     $mock = new MockFilterAwareClass();
     $filter = function (array $data) {
         return 0;
     };
     $mock->addFilter($filter);
     assertThat('There should only be the one filter we added.', $mock->getFilters(), is(arrayContaining($filter)));
 }
 public function testFormatTraversableShouldApplyFilters()
 {
     $items = ['foo', 'bar', 'baz'];
     $formatter = new MockFormatter();
     $formatter->addFilter(function (array $data) {
         return $data['count'] !== 2;
     });
     $result = $formatter->formatTraversable(new ArrayIterator($items));
     assertThat('The formatter should correctly apply the filter.', iterator_to_array($result), is(arrayContaining(['count' => 1], ['count' => 3])));
 }
Example #5
0
 public function testTraitShouldAddSortersAsTheFirstSorterInTheCollection()
 {
     $mock = new MockSorterAwareClass();
     $sorterOne = function () {
         return 0;
     };
     $sorterTwo = function () {
         return 0;
     };
     $mock->addSorter($sorterOne);
     $mock->addSorter($sorterTwo);
     assertThat('The sorter should add sorters to the beginning of the collection.', $mock->getSorters(), is(arrayContaining($sorterTwo, $sorterOne)));
 }
Example #6
0
 private function runnerDeciderScanWithForceDecision($runner)
 {
     $this->setUpTables();
     $this->setUpRepo();
     $jobId = 42;
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef();
     $agentLicId = $this->licenseDao->getLicenseByShortName("Adaptec")->getRef()->getId();
     $addedLicenses = array($licenseRef1, $licenseRef2);
     assertThat($addedLicenses, not(arrayContaining(null)));
     $agentId = 5;
     $pfile = 4;
     $this->dbManager->queryOnce("INSERT INTO license_file (fl_pk,rf_fk,pfile_fk,agent_fk) VALUES(12222,{$agentLicId},{$pfile},{$agentId})");
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId = 23);
     assertThat($this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds), is(not(emptyArray())));
     $eventId1 = $this->clearingDao->insertClearingEvent($itemId, $userId = 2, $groupId = 3, $licenseRef1->getId(), false);
     $eventId2 = $this->clearingDao->insertClearingEvent($itemId, 5, $groupId, $licenseRef2->getId(), true);
     $this->dbManager->queryOnce("UPDATE clearing_event SET job_fk={$jobId}");
     $addedEventIds = array($eventId1, $eventId2);
     list($success, $output, $retCode) = $runner->run($uploadId = 2, $userId, $groupId, $jobId, $args = "-k1");
     $this->assertTrue($success, 'cannot run runner');
     $this->assertEquals($retCode, 0, 'decider failed: ' . $output);
     assertThat($this->getHeartCount($output), equalTo(1));
     $uploadBounds = $this->uploadDao->getParentItemBounds($uploadId);
     $decisions = $this->clearingDao->getFileClearingsFolder($uploadBounds, $groupId);
     assertThat($decisions, is(arrayWithSize(1)));
     /** @var ClearingDecision $deciderMadeDecision */
     $deciderMadeDecision = $decisions[0];
     $eventIds = array();
     foreach ($deciderMadeDecision->getClearingEvents() as $event) {
         $eventIds[] = $event->getEventId();
     }
     assertThat($eventIds, arrayValue($addedEventIds[0]));
     assertThat($eventIds, arrayValue($addedEventIds[1]));
     assertThat($eventIds, arrayWithSize(1 + count($addedEventIds)));
     $this->rmRepo();
 }
Example #7
0
 public function testMainLicenseIds()
 {
     $this->testDb->createPlainTables(array('upload_clearing_license'));
     $uploadId = 101;
     $mainLicIdsInitially = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsInitially, is(emptyArray()));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId = 402);
     $mainLicIdsAfterAddingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOne, arrayContaining(array($licenseId)));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId);
     $mainLicIdsAfterAddingOneTwice = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOneTwice, is(arrayWithSize(1)));
     $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId2 = 403);
     $mainLicIdsAfterAddingOther = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterAddingOther, arrayContainingInAnyOrder(array($licenseId, $licenseId2)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2);
     $mainLicIdsAfterRemovingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdsAfterRemovingOne, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2);
     $mainLicIdAfterRemovingSomethingNotInSet = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterRemovingSomethingNotInSet, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId, $this->groupId + 1, $licenseId);
     $mainLicIdAfterInsertToOtherGroup = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterInsertToOtherGroup, is(arrayWithSize(1)));
     $this->clearingDao->removeMainLicense($uploadId + 1, $this->groupId, $licenseId);
     $mainLicIdAfterInsertToOtherUpload = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId);
     assertThat($mainLicIdAfterInsertToOtherUpload, is(arrayWithSize(1)));
 }
 public function testQueryPrepared()
 {
     $uploadId = 2;
     $agentNames = array('nomos');
     $latestScannerProxy = new LatestScannerProxy('$1', $agentNames, 'latest_scanner', "AND agent_enabled='true'");
     $sql = $latestScannerProxy->getDbViewQuery();
     $scanners = $this->getAllColumns($sql, array($uploadId));
     assertThat($scanners, arrayContaining(array(array('agent_pk' => 6, 'agent_name' => 'nomos'))));
 }
 public function testFormatManyShouldApplySortersInOrder()
 {
     $items = ['foo', 'bar', 'baz'];
     $formatter = new MockFormatter();
     $formatter->addSorter(function (array $data) {
         // Reverse the order of the input.
         return -$data['count'];
     });
     $formatter->addSorter(function (array $data) {
         // Then reverse it back to the default.
         return $data['count'];
     });
     $result = $formatter->formatMany($items);
     assertThat('The sorter should apply sorters in the order they were added.', $result, is(arrayContaining(['count' => 1], ['count' => 2], ['count' => 3])));
 }
 public function testPositiveLicenses()
 {
     $addedLic = M::mock(LicenseRef::classname());
     $addedClearingLic = M::mock(ClearingLicense::classname());
     $addedClearingLic->shouldReceive('isRemoved')->withNoArgs()->andReturn(false);
     $addedClearingLic->shouldReceive('getLicenseRef')->withNoArgs()->andReturn($addedLic);
     $removedClearingLic = M::mock(ClearingLicense::classname());
     $removedClearingLic->shouldReceive('isRemoved')->andReturn(true);
     $removedClearingEvent = M::mock(ClearingEvent::classname());
     $this->clearingEvent->shouldReceive('getClearingLicense')->andReturn($addedClearingLic);
     $removedClearingEvent->shouldReceive('getClearingLicense')->andReturn($removedClearingLic);
     $clearingDec = $this->clearingDecisionBuilder->setClearingEvents(array($this->clearingEvent, $removedClearingEvent))->build();
     assertThat($clearingDec->getPositiveLicenses(), is(arrayContaining($addedLic)));
 }
Example #11
0
 protected function insertDecisionFromTwoEvents($scope = DecisionScopes::ITEM, $originallyClearedItemId = 23)
 {
     $licenseRef1 = $this->licenseDao->getLicenseByShortName("GPL-3.0")->getRef();
     $licenseRef2 = $this->licenseDao->getLicenseByShortName("3DFX")->getRef();
     $addedLicenses = array($licenseRef1, $licenseRef2);
     assertThat($addedLicenses, not(arrayContaining(null)));
     $clearingLicense1 = new ClearingLicense($licenseRef1, false, ClearingEventTypes::USER, "42", "44");
     $clearingLicense2 = new ClearingLicense($licenseRef2, true, ClearingEventTypes::USER, "-42", "-44");
     $eventId1 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, $this->userId, $this->groupId, $licenseRef1->getId(), $clearingLicense1->isRemoved(), $clearingLicense1->getType(), $clearingLicense1->getReportinfo(), $clearingLicense1->getComment());
     $eventId2 = $this->clearingDao->insertClearingEvent($originallyClearedItemId, 5, $this->groupId, $licenseRef2->getId(), $clearingLicense2->isRemoved(), $clearingLicense2->getType(), $clearingLicense2->getReportinfo(), $clearingLicense2->getComment());
     $addedEventIds = array($eventId1, $eventId2);
     $this->clearingDao->createDecisionFromEvents($originallyClearedItemId, $this->userId, $this->groupId, DecisionTypes::IDENTIFIED, $scope, $addedEventIds);
     return array($clearingLicense1, $clearingLicense2, $addedEventIds);
 }