/** * Test saving the timestamp from the payload in core_config_data. */ public function testUpdateLastTimestamp() { $configPathToSet = 'config/path/for/timestamp'; $timestamp = new DateTime('2000-01-01T00:00:00+00:00'); $store = Mage::getModel('core/store'); // make a mock Mage_Core_Model_Config_Data to check setting and saving // the timestamp value to core_config_data $configData = $this->getModelMock('core/config_data', array('save')); // make sure the data actually gets saved $configData->expects($this->once())->method('save')->will($this->returnSelf()); $this->replaceByMock('model', 'core/config_data', $configData); // stub the config path $this->_configMap->expects($this->any())->method('getPathForKey')->will($this->returnValue($configPathToSet)); // stub payload data $this->_payload->expects($this->any())->method('getTimestamp')->will($this->returnValue($timestamp)); $helper = $this->getHelperMock('ebayenterprise_amqp/config', array('getScopeForStoreSettings')); // stub getting scope for store, tested in self::testgetScopeForStoreSettings $helper->expects($this->any())->method('getScopeForStoreSettings')->will($this->returnValue(array('default', '0'))); EcomDev_Utils_Reflection::setRestrictedPropertyValue($helper, '_amqpConfigMap', $this->_configMap); // invoke method and test that the config_data model has the expected // data set on it $configData = $helper->updateLastTimestamp($this->_payload, $store); $this->assertSame($configPathToSet, $configData->getPath()); $valueDateTime = new DateTime($configData->getValue()); $this->assertSame($timestamp->format('c'), $valueDateTime->format('c')); $this->assertSame('0', $configData->getScopeId()); $this->assertSame('default', $configData->getScope()); }
/** * Update the core_config_data setting for timestamp from the last test * message received. Value should be saved in the most appropriate scope for * the store being processed. E.g. if the store is the default store, or has * the same AMQP configuration as the default store, the timestamp should be * updated in the default scope. If the stores AMQP configuration matches a * website level configuration, should be saved within that website's scope. * @param ITestMessage $payload * @param Mage_Core_Model_Store $store * @return Mage_Core_Model_Config_Data */ public function updateLastTimestamp(ITestMessage $payload, Mage_Core_Model_Store $store) { list($scope, $scopeId) = $this->getScopeForStoreSettings($store); return Mage::getModel('core/config_data')->addData(array('path' => $this->_amqpConfigMap->getPathForKey('last_test_message_timestamp'), 'value' => $payload->getTimestamp()->format(self::TIMESTAMP_FORMAT), 'scope' => $scope, 'scope_id' => $scopeId))->save(); }