From 9dd7e25b15f8b4312b35f3d8f0830fe0a6abc551 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 3 Oct 2022 11:24:32 +0900 Subject: [PATCH] test: extract method --- tests/system/Helpers/FormHelperTest.php | 52 +++++++------------------ 1 file changed, 15 insertions(+), 37 deletions(-) diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index e5666b2b83cf..c795e0a611d7 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -11,6 +11,7 @@ namespace CodeIgniter\Helpers; +use CodeIgniter\HTTP\IncomingRequest; use CodeIgniter\HTTP\URI; use CodeIgniter\Test\CIUnitTestCase; use Config\App; @@ -33,15 +34,21 @@ protected function setUp(): void $this->resetServices(); } - public function testFormOpenBasic() + private function getRequest(): IncomingRequest { $uri = new URI('http://example.com/'); Services::injectMock('uri', $uri); + $config = new App(); $config->baseURL = ''; $config->indexPage = 'index.php'; - $request = Services::request($config); + return Services::request($config); + } + + public function testFormOpenBasic() + { + $request = $this->getRequest(); Services::injectMock('request', $request); $before = (new Filters())->globals['before']; @@ -70,14 +77,9 @@ public function testFormOpenBasic() public function testFormOpenHasLocale() { - $uri = new URI('http://example.com/'); - Services::injectMock('uri', $uri); - $config = new App(); - $config->baseURL = ''; - $config->indexPage = 'index.php'; - $request = Services::request($config); - + $request = $this->getRequest(); Services::injectMock('request', $request); + $expected = <<<'EOH'
@@ -93,13 +95,7 @@ public function testFormOpenHasLocale() public function testFormOpenWithoutAction() { - $uri = new URI('http://example.com/'); - Services::injectMock('uri', $uri); - $config = new App(); - $config->baseURL = ''; - $config->indexPage = 'index.php'; - $request = Services::request($config); - + $request = $this->getRequest(); Services::injectMock('request', $request); $before = (new Filters())->globals['before']; @@ -127,13 +123,7 @@ public function testFormOpenWithoutAction() public function testFormOpenWithoutMethod() { - $uri = new URI('http://example.com/'); - Services::injectMock('uri', $uri); - $config = new App(); - $config->baseURL = ''; - $config->indexPage = 'index.php'; - $request = Services::request($config); - + $request = $this->getRequest(); Services::injectMock('request', $request); $before = (new Filters())->globals['before']; @@ -161,13 +151,7 @@ public function testFormOpenWithoutMethod() public function testFormOpenWithHidden() { - $uri = new URI('http://example.com/'); - Services::injectMock('uri', $uri); - $config = new App(); - $config->baseURL = ''; - $config->indexPage = 'index.php'; - $request = Services::request($config); - + $request = $this->getRequest(); Services::injectMock('request', $request); $before = (new Filters())->globals['before']; @@ -202,13 +186,7 @@ public function testFormOpenWithHidden() public function testFormOpenMultipart() { - $uri = new URI('http://example.com/'); - Services::injectMock('uri', $uri); - $config = new App(); - $config->baseURL = ''; - $config->indexPage = 'index.php'; - $request = Services::request($config); - + $request = $this->getRequest(); Services::injectMock('request', $request); $before = (new Filters())->globals['before'];