public function test_exception_occurred() { // ARRANGE $uniqueString = __CLASS__ . '::' . __METHOD__ . '::' . __LINE__; $expectedExceptionMsg = 'TEST-CASE-EXCEPTION-' . $uniqueString; $expectedException = new TestCaseException($expectedExceptionMsg); $errorShopModeStrategy = $this->getErrorShopModeStrategy(array('process' => array($this->once(), $this->throwException($expectedException)))); /** @var rz_shop_cart_ModuleTest_TestModule $module */ $module = $this->getModuleMock(null, null, array('getStrategy' => array($this->once(), $errorShopModeStrategy))); // ACT $actualResponse = $this->callProcessAction($module); // ASSERT $expectedShopResponse = new ShopModeResponse('showCart'); $expectedShopResponse->addError($expectedExceptionMsg); $this->assertEquals($expectedShopResponse, $actualResponse); }
public function test_provideUnitData_setValuesFromResponseToUnitContext() { // ARRANGE $uniqueString = __CLASS__ . '::' . __METHOD__ . '::' . __LINE__; $expectedViewMode = 'THE-NEW-VIEW-MODE-' . $uniqueString; $expectedErrorMsg = 'THE-ERROR-MESSAGE-' . $uniqueString; $expectedRedirectUrl = 'THE-REDIRECT-URL-' . $uniqueString; $unitId = 'UNIT-ID-' . $uniqueString; $unit = $this->createUnit(array('id' => $unitId)); $shopModeResponse = new ShopModeResponse($expectedViewMode, $expectedRedirectUrl); $shopModeResponse->addError($expectedErrorMsg); $moduleMock = $this->getModuleMock(null, null, array('processAction' => array($this->once(), $shopModeResponse))); // ACT $actualProvidedData = $this->provideUnitData($moduleMock, null, $unit); // ASSERT $expectedUnixContext = array($unitId => array('view' => $expectedViewMode, 'errors' => array($expectedErrorMsg), 'alreadyProcessed' => true)); $this->assertEquals($expectedUnixContext, $moduleMock->phpunit_getUnitContext()); $this->assertEquals(array('url' => $expectedRedirectUrl), $actualProvidedData['redirect']); }
/** * @param HeadAPI $api * @param Unit $unit * @param ModuleInfo $moduleInfo * * @return ShopModeResponse */ protected function processAction($api, $unit, $moduleInfo) { setlocale(LC_NUMERIC, 'C'); try { $strategy = $this->getStrategy($api, $unit, $moduleInfo); return $strategy->process(); } catch (\Exception $e) { $shopModeResponse = new ShopModeResponse(); $shopModeResponse->addError($e->getMessage()); return $shopModeResponse; } }