function testCanVerifyByType() { $mock = Phockito::mock('PhockitoHamcrestTest_MockMe'); $mock->Bar('Pow!'); $mock->Bar('Bam!'); Phockito::verify($mock, 2)->Bar(stringValue()); }
function testSpyingCall() { $spy = Phockito::spy('PhockitoOverloadedCallTest_OverloadedCall'); $this->assertEquals($spy->Foo(), 'Foo'); Phockito::when($spy)->Foo()->return(1); $this->assertEquals($spy->Foo(), 1); Phockito::verify($spy, 2)->Foo(); }
function testPhockitoIntegration() { $mock = Phockito::mock('ViewableData'); Phockito::when($mock)->getField(stringValue())->return('Foo'); $this->assertEquals($mock->getField(1), null); $this->assertEquals($mock->getField('Bar'), 'Foo'); Phockito::verify($mock)->getField(integerValue()); }
public function testPostPact() { $http = Phockito::spy('Pact\\HttpClient'); Phockito::when($http)->execute()->return(true); $mockServiceRequests = new MockServiceRequests($http); $pactDetails = ['consumer' => ['name' => 'c'], 'provider' => ['name' => 'p']]; $mockServiceRequests->postPact($pactDetails, 'http://127.0.0.1'); Phockito::verify($http)->execute(); }
function testCanResetCallRecordForSpecificMethod() { $mock = Phockito::mock('PhockitoResetTest_MockMe'); $mock->Foo(); $mock->Bar(); Phockito::verify($mock)->Foo(); Phockito::verify($mock)->Bar(); Phockito::reset($mock, 'Foo'); Phockito::verify($mock, 0)->Foo(); Phockito::verify($mock)->Bar(); }
/** @expectedException PhockitoTest_VerificationFailure */ function testSingleCallCorrectlyFailsVerificationAgainstTwoOrMore() { $mock = Phockito::mock('PhockitoTest_MockMe'); $mock->Foo(); Phockito::verify($mock, '2+')->Foo(); }
public function testActionMethods() { $this->mockController(); $response = $this->router->routeRequest('/routing/test/5/tests/custom', 'POST'); Phockito::verify($this->controller)->custom(anything(), anything()); Phockito::reset($this->controller); $this->assertEquals($response->body(), '{"action":"custom","var":"5","var2":null}'); $response = $this->router->routeRequest('/routing/nested/5/child/70/tests/custom', 'POST'); Phockito::verify($this->controller)->custom(anything(), anything()); $this->assertEquals($response->body(), '{"action":"custom","var":"5","var2":"70"}'); }
function testHighlightQueryOnBoost() { $serviceMock = $this->getServiceMock(); Phockito::when($serviceMock)->search(anything(), anything(), anything(), anything(), anything())->return($this->getFakeRawSolrResponse()); $index = new SolrIndexTest_FakeIndex(); $index->setService($serviceMock); // Search without highlighting $query = new SearchQuery(); $query->search('term', null, array('Field1' => 1.5, 'HasOneObject_Field1' => 3)); $index->search($query); Phockito::verify($serviceMock)->search('+(Field1:term^1.5 OR HasOneObject_Field1:term^3)', anything(), anything(), not(hasKeyInArray('hl.q')), anything()); // Search with highlighting $query = new SearchQuery(); $query->search('term', null, array('Field1' => 1.5, 'HasOneObject_Field1' => 3)); $index->search($query, -1, -1, array('hl' => true)); Phockito::verify($serviceMock)->search('+(Field1:term^1.5 OR HasOneObject_Field1:term^3)', anything(), anything(), hasKeyInArray('hl.q'), anything()); }
public function testDelete() { // Setup mocks $serviceMock = $this->getServiceMock(); self::$index->setService($serviceMock); // Delete the live record (not the stage) Versioned::reading_stage('Stage'); Phockito::reset($serviceMock); $item = new SearchVariantVersionedTest_Item(array('Title' => 'Too')); $item->write(); $item->publish('Stage', 'Live'); Versioned::reading_stage('Live'); $id = $item->ID; $item->delete(); SearchUpdater::flush_dirty_indexes(); Phockito::verify($serviceMock, 1)->deleteById($this->getExpectedDocumentId($id, 'Live')); Phockito::verify($serviceMock, 0)->deleteById($this->getExpectedDocumentId($id, 'Stage')); // Delete the stage record Versioned::reading_stage('Stage'); Phockito::reset($serviceMock); $item = new SearchVariantVersionedTest_Item(array('Title' => 'Too')); $item->write(); $item->publish('Stage', 'Live'); $id = $item->ID; $item->delete(); SearchUpdater::flush_dirty_indexes(); Phockito::verify($serviceMock, 1)->deleteById($this->getExpectedDocumentId($id, 'Stage')); Phockito::verify($serviceMock, 0)->deleteById($this->getExpectedDocumentId($id, 'Live')); }
/** * Test that reindex will generate a top top level queued job, and executing this will perform * the necessary initialisation of the grouped queued jobs */ public function testReindexSegmentsGroups() { $this->createDummyData(18); // Create pre-existing jobs $this->getQueuedJobService()->queueJob(new SolrReindexQueuedJob()); $this->getQueuedJobService()->queueJob(new SolrReindexGroupQueuedJob()); $this->getQueuedJobService()->queueJob(new SolrReindexGroupQueuedJob()); // Initiate re-index $logger = new SolrReindexTest_RecordingLogger(); $this->getHandler()->triggerReindex($logger, 6, 'Solr_Reindex'); // Old jobs should be cancelled $this->assertEquals(1, $logger->countMessages('Cancelled 1 re-index tasks and 2 re-index groups')); $this->assertEquals(1, $logger->countMessages('Queued Solr Reindex Job')); // Next job should be queue job $job = $this->getQueuedJobService()->getNextJob(); $this->assertInstanceOf('SolrReindexQueuedJob', $job); $this->assertEquals(6, $job->getBatchSize()); // Test that necessary items are created $logger->clear(); $job->setLogger($logger); $job->process(); // Deletes are performed in the main task prior to individual groups being processed // 18 records means 3 groups of 6 in each variant (6 total) Phockito::verify($this->service, 2)->deleteByQuery(anything()); $this->assertEquals(1, $logger->countMessages('Beginning init of reindex')); $this->assertEquals(6, $logger->countMessages('Queued Solr Reindex Group ')); $this->assertEquals(3, $logger->countMessages(' of SolrReindexTest_Item in {"SolrReindexTest_Variant":"0"}')); $this->assertEquals(3, $logger->countMessages(' of SolrReindexTest_Item in {"SolrReindexTest_Variant":"1"}')); $this->assertEquals(1, $logger->countMessages('Completed init of reindex')); // Test that invalid classes are removed $this->assertNotEmpty($logger->getMessages('Clearing obsolete classes from SolrReindexTest_Index')); Phockito::verify($this->service, 1)->deleteByQuery('-(ClassHierarchy:SolrReindexTest_Item)'); // Test that valid classes in invalid variants are removed $this->assertNotEmpty($logger->getMessages('Clearing all records of type SolrReindexTest_Item in the current state: {"SolrReindexTest_Variant":"2"}')); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +(_testvariant:"2")'); }
/** * Test that running all groups covers the entire range of dataobject IDs */ public function testRunAllGroups() { $this->createDummyData(120); $logger = new SolrReindexTest_RecordingLogger(); // Test that running all groups covers the complete set of ids $state = array('SolrReindexTest_Variant' => '1'); for ($i = 0; $i < 6; $i++) { // See testReindexSegmentsGroups for test that each of these states is invoked during a full reindex $this->getHandler()->runGroup($logger, $this->index, $state, 'SolrReindexTest_Item', 6, $i); } // Count all ids updated $ids = array(); foreach ($logger->filterMessages('Updated ') as $message) { $this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\\d]+)/', $message, $matches)); $ids = array_unique(array_merge($ids, explode(',', $matches['ids']))); } // Check ids $this->assertEquals(120, count($ids)); Phockito::verify($this->service, 6)->deleteByQuery(anything()); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +_query_:"{!frange l=0 u=0}mod(ID, 6)" +(_testvariant:"1")'); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +_query_:"{!frange l=1 u=1}mod(ID, 6)" +(_testvariant:"1")'); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +_query_:"{!frange l=2 u=2}mod(ID, 6)" +(_testvariant:"1")'); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +_query_:"{!frange l=3 u=3}mod(ID, 6)" +(_testvariant:"1")'); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +_query_:"{!frange l=4 u=4}mod(ID, 6)" +(_testvariant:"1")'); Phockito::verify($this->service, 1)->deleteByQuery('+(ClassHierarchy:SolrReindexTest_Item) +_query_:"{!frange l=5 u=5}mod(ID, 6)" +(_testvariant:"1")'); }