Skip to content

Commit fb8be3e

Browse files
committed
test: refactor method
1 parent 200cd8d commit fb8be3e

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

tests/system/Helpers/FormHelperTest.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace CodeIgniter\Helpers;
1313

14-
use CodeIgniter\HTTP\IncomingRequest;
1514
use CodeIgniter\HTTP\URI;
1615
use CodeIgniter\Test\CIUnitTestCase;
1716
use Config\App;
@@ -34,7 +33,7 @@ protected function setUp(): void
3433
$this->resetServices();
3534
}
3635

37-
private function getRequest(): IncomingRequest
36+
private function setRequest(): void
3837
{
3938
$uri = new URI('http://example.com/');
4039
Services::injectMock('uri', $uri);
@@ -43,12 +42,13 @@ private function getRequest(): IncomingRequest
4342
$config->baseURL = '';
4443
$config->indexPage = 'index.php';
4544

46-
return Services::request($config);
45+
$request = Services::request($config);
46+
Services::injectMock('request', $request);
4747
}
4848

4949
public function testFormOpenBasic()
5050
{
51-
$request = $this->getRequest();
51+
$request = $this->setRequest();
5252
Services::injectMock('request', $request);
5353

5454
$before = (new Filters())->globals['before'];
@@ -77,8 +77,7 @@ public function testFormOpenBasic()
7777

7878
public function testFormOpenHasLocale()
7979
{
80-
$request = $this->getRequest();
81-
Services::injectMock('request', $request);
80+
$this->setRequest();
8281

8382
$expected = <<<'EOH'
8483
<form action="http://example.com/index.php/en/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">
@@ -95,8 +94,7 @@ public function testFormOpenHasLocale()
9594

9695
public function testFormOpenWithoutAction()
9796
{
98-
$request = $this->getRequest();
99-
Services::injectMock('request', $request);
97+
$this->setRequest();
10098

10199
$before = (new Filters())->globals['before'];
102100
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
@@ -123,8 +121,7 @@ public function testFormOpenWithoutAction()
123121

124122
public function testFormOpenWithoutMethod()
125123
{
126-
$request = $this->getRequest();
127-
Services::injectMock('request', $request);
124+
$this->setRequest();
128125

129126
$before = (new Filters())->globals['before'];
130127
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
@@ -151,8 +148,7 @@ public function testFormOpenWithoutMethod()
151148

152149
public function testFormOpenWithHidden()
153150
{
154-
$request = $this->getRequest();
155-
Services::injectMock('request', $request);
151+
$this->setRequest();
156152

157153
$before = (new Filters())->globals['before'];
158154
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {
@@ -186,8 +182,7 @@ public function testFormOpenWithHidden()
186182

187183
public function testFormOpenMultipart()
188184
{
189-
$request = $this->getRequest();
190-
Services::injectMock('request', $request);
185+
$this->setRequest();
191186

192187
$before = (new Filters())->globals['before'];
193188
if (in_array('csrf', $before, true) || array_key_exists('csrf', $before)) {

0 commit comments

Comments
 (0)