*/ class DeliveryMonitoringStorageTest extends TaoPhpUnitTestRunner { public function testPartialSave() { //$pm = $this->getSqlMock('monitoring'); $pm = $this->getPmMock(); DbSetup::generateTable($pm->getPersistenceById('monitoring')); $sl = $this->getServiceLocatorMock([\common_persistence_Manager::SERVICE_ID => $pm]); $deP = $this->prophesize(DeliveryExecution::class); $deP->getIdentifier()->willReturn('http://test/deliveryExecution'); $stateProphecy = $this->prophesize(\core_kernel_classes_Resource::class); $stateProphecy->getUri()->willReturn(DeliveryExecution::STATE_PAUSED); $deP->getState()->willReturn($stateProphecy); $de = $deP->reveal(); $storage = new MonitoringStorage([ MonitoringStorage::OPTION_PERSISTENCE => 'monitoring', 'use_update_multiple' => false, 'primary_columns' => DbSetup::getPrimaryColumns() ]); $storage->setServiceLocator($sl); // full save $data = $storage->getData($de); $this->assertInstanceOf(DeliveryMonitoringData::class, $data); $data->update('a', '1'); $data->update('b', '2'); $data->update(DeliveryMonitoringService::STATUS, DeliveryExecution::STATE_PAUSED); $success = $storage->save($data); $this->assertTrue($success); // partial save $data2 = $storage->createMonitoringData($de); $data2->update('a', '3'); $success = $storage->partialSave($data2); $this->assertTrue($success); // load and compare data $data3 = $storage->getData($de); $this->assertInstanceOf(DeliveryMonitoringData::class, $data3); $dataArray = $data3->get(); $this->assertArrayHasKey('a', $dataArray); $this->assertEquals('3', $dataArray['a']); $this->assertEquals('2', $dataArray['b']); } private function getPmMock() { $sqlMock = $this->getSqlMock('monitoring'); $cacheMock = $this->getKvMock('cache'); $this->persistence = $sqlMock->getPersistenceById('monitoring'); $pmMock = $this->getMockBuilder(PersistenceManager::class) ->setMethods(['getPersistenceById']) ->getMock(); $pmMock->method('getPersistenceById') ->will($this->returnCallback( function ($persistenceId) use ($sqlMock, $cacheMock) { if ($persistenceId === 'cache') { return $cacheMock->getPersistenceById('cache'); } if ($persistenceId === 'monitoring') { return $sqlMock->getPersistenceById('monitoring'); } } )); return $pmMock; } }