1111
1212namespace CodeIgniter \Helpers ;
1313
14+ use CodeIgniter \HTTP \IncomingRequest ;
1415use CodeIgniter \HTTP \URI ;
1516use CodeIgniter \Test \CIUnitTestCase ;
1617use Config \App ;
@@ -33,15 +34,21 @@ protected function setUp(): void
3334 $ this ->resetServices ();
3435 }
3536
36- public function testFormOpenBasic ()
37+ private function getRequest (): IncomingRequest
3738 {
3839 $ uri = new URI ('http://example.com/ ' );
3940 Services::injectMock ('uri ' , $ uri );
41+
4042 $ config = new App ();
4143 $ config ->baseURL = '' ;
4244 $ config ->indexPage = 'index.php ' ;
43- $ request = Services::request ($ config );
4445
46+ return Services::request ($ config );
47+ }
48+
49+ public function testFormOpenBasic ()
50+ {
51+ $ request = $ this ->getRequest ();
4552 Services::injectMock ('request ' , $ request );
4653
4754 $ before = (new Filters ())->globals ['before ' ];
@@ -70,14 +77,9 @@ public function testFormOpenBasic()
7077
7178 public function testFormOpenHasLocale ()
7279 {
73- $ uri = new URI ('http://example.com/ ' );
74- Services::injectMock ('uri ' , $ uri );
75- $ config = new App ();
76- $ config ->baseURL = '' ;
77- $ config ->indexPage = 'index.php ' ;
78- $ request = Services::request ($ config );
79-
80+ $ request = $ this ->getRequest ();
8081 Services::injectMock ('request ' , $ request );
82+
8183 $ expected = <<<'EOH'
8284 <form action="http://example.com/index.php/en/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">
8385
@@ -93,13 +95,7 @@ public function testFormOpenHasLocale()
9395
9496 public function testFormOpenWithoutAction ()
9597 {
96- $ uri = new URI ('http://example.com/ ' );
97- Services::injectMock ('uri ' , $ uri );
98- $ config = new App ();
99- $ config ->baseURL = '' ;
100- $ config ->indexPage = 'index.php ' ;
101- $ request = Services::request ($ config );
102-
98+ $ request = $ this ->getRequest ();
10399 Services::injectMock ('request ' , $ request );
104100
105101 $ before = (new Filters ())->globals ['before ' ];
@@ -127,13 +123,7 @@ public function testFormOpenWithoutAction()
127123
128124 public function testFormOpenWithoutMethod ()
129125 {
130- $ uri = new URI ('http://example.com/ ' );
131- Services::injectMock ('uri ' , $ uri );
132- $ config = new App ();
133- $ config ->baseURL = '' ;
134- $ config ->indexPage = 'index.php ' ;
135- $ request = Services::request ($ config );
136-
126+ $ request = $ this ->getRequest ();
137127 Services::injectMock ('request ' , $ request );
138128
139129 $ before = (new Filters ())->globals ['before ' ];
@@ -161,13 +151,7 @@ public function testFormOpenWithoutMethod()
161151
162152 public function testFormOpenWithHidden ()
163153 {
164- $ uri = new URI ('http://example.com/ ' );
165- Services::injectMock ('uri ' , $ uri );
166- $ config = new App ();
167- $ config ->baseURL = '' ;
168- $ config ->indexPage = 'index.php ' ;
169- $ request = Services::request ($ config );
170-
154+ $ request = $ this ->getRequest ();
171155 Services::injectMock ('request ' , $ request );
172156
173157 $ before = (new Filters ())->globals ['before ' ];
@@ -202,13 +186,7 @@ public function testFormOpenWithHidden()
202186
203187 public function testFormOpenMultipart ()
204188 {
205- $ uri = new URI ('http://example.com/ ' );
206- Services::injectMock ('uri ' , $ uri );
207- $ config = new App ();
208- $ config ->baseURL = '' ;
209- $ config ->indexPage = 'index.php ' ;
210- $ request = Services::request ($ config );
211-
189+ $ request = $ this ->getRequest ();
212190 Services::injectMock ('request ' , $ request );
213191
214192 $ before = (new Filters ())->globals ['before ' ];
0 commit comments