diff --git a/services.yaml b/services.yaml index b50ad33..6b9e62f 100644 --- a/services.yaml +++ b/services.yaml @@ -44,4 +44,7 @@ services: OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate: class: OxidEsales\ModuleTemplate\Subscriber\BeforeModelUpdate - tags: [ 'kernel.event_subscriber' ] \ No newline at end of file + tags: [ 'kernel.event_subscriber' ] + + OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface: + class: OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactory \ No newline at end of file diff --git a/src/Controller/Admin/GreetingAdminController.php b/src/Controller/Admin/GreetingAdminController.php index 5fca419..88ad2c1 100644 --- a/src/Controller/Admin/GreetingAdminController.php +++ b/src/Controller/Admin/GreetingAdminController.php @@ -26,4 +26,4 @@ public function render() return parent::render(); } -} \ No newline at end of file +} diff --git a/src/Infrastructure/CoreRequestFactory.php b/src/Infrastructure/CoreRequestFactory.php new file mode 100644 index 0000000..30a2211 --- /dev/null +++ b/src/Infrastructure/CoreRequestFactory.php @@ -0,0 +1,23 @@ +settings = $settings; - $this->request = $request; + $this->coreRequestFactory = $coreRequestFactory; } public function getGreeting(?EshopModelUser $user = null): string @@ -59,7 +59,8 @@ public function saveGreeting(EshopModelUser $user): bool private function getRequestOemtGreeting(): string { - $input = (string)$this->request->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); + $coreRequestService = $this->coreRequestFactory->create(); + $input = (string)$coreRequestService->getRequestParameter(ModuleCore::OEMT_GREETING_TEMPLATE_VARNAME); //in real life add some input validation return (string)substr($input, 0, 253); diff --git a/tests/Integration/Service/GreetingMessageTest.php b/tests/Integration/Service/GreetingMessageTest.php index c6fa721..a31bedf 100644 --- a/tests/Integration/Service/GreetingMessageTest.php +++ b/tests/Integration/Service/GreetingMessageTest.php @@ -10,8 +10,8 @@ namespace OxidEsales\ModuleTemplate\Tests\Integration\Service; use OxidEsales\Eshop\Application\Model\User as EshopModelUser; -use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; +use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Service\GreetingMessage; use OxidEsales\ModuleTemplate\Service\ModuleSettings; use OxidEsales\ModuleTemplate\Tests\Integration\IntegrationTestCase; @@ -22,7 +22,7 @@ public function testModuleGenericGreetingModeEmptyUser(): void { $service = new GreetingMessage( $this->getSettingsMock(ModuleSettings::GREETING_MODE_GENERIC), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); @@ -33,7 +33,7 @@ public function testModulePersonalGreetingModeEmptyUser(): void { $service = new GreetingMessage( $this->getSettingsMock(), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); @@ -44,7 +44,7 @@ public function testModuleGenericGreeting(): void { $service = new GreetingMessage( $this->getSettingsMock(ModuleSettings::GREETING_MODE_GENERIC), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); $user->setPersonalGreeting('Hi sweetie!'); @@ -56,7 +56,7 @@ public function testModulePersonalGreeting(): void { $service = new GreetingMessage( $this->getSettingsMock(), - oxNew(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $user = oxNew(EshopModelUser::class); $user->setPersonalGreeting('Hi sweetie!'); diff --git a/tests/Unit/Infrastructure/CoreRequestFactoryTest.php b/tests/Unit/Infrastructure/CoreRequestFactoryTest.php new file mode 100644 index 0000000..5e3a0f5 --- /dev/null +++ b/tests/Unit/Infrastructure/CoreRequestFactoryTest.php @@ -0,0 +1,29 @@ +getMockBuilder(CoreRequestFactory::class) + ->onlyMethods(['create']) + ->getMock(); + + $this->assertInstanceOf(Request::class, $coreThemeFactoryMock->create()); + } +} \ No newline at end of file diff --git a/tests/Unit/Service/GreetingMessageTest.php b/tests/Unit/Service/GreetingMessageTest.php index 48058fd..d3b860a 100644 --- a/tests/Unit/Service/GreetingMessageTest.php +++ b/tests/Unit/Service/GreetingMessageTest.php @@ -11,6 +11,7 @@ use OxidEsales\Eshop\Core\Request as CoreRequest; use OxidEsales\ModuleTemplate\Core\Module as ModuleCore; +use OxidEsales\ModuleTemplate\Infrastructure\CoreRequestFactoryInterface; use OxidEsales\ModuleTemplate\Service\GreetingMessage; use OxidEsales\ModuleTemplate\Service\ModuleSettings; use PHPUnit\Framework\TestCase; @@ -24,7 +25,7 @@ public function testGenericGreetingNoUser(string $mode, string $expected): void { $service = new GreetingMessage( $this->createConfiguredMock(ModuleSettings::class, ['getGreetingMode' => $mode]), - $this->createStub(CoreRequest::class) + $this->createMock(CoreRequestFactoryInterface::class) ); $this->assertSame($expected, $service->getGreeting());