Skip to content

Commit

Permalink
test: extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Oct 3, 2022
1 parent c08fa41 commit 9dd7e25
Showing 1 changed file with 15 additions and 37 deletions.
52 changes: 15 additions & 37 deletions tests/system/Helpers/FormHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Helpers;

use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\URI;
use CodeIgniter\Test\CIUnitTestCase;
use Config\App;
Expand All @@ -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'];
Expand Down Expand Up @@ -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'
<form action="http://example.com/index.php/en/foo/bar" name="form" id="form" method="POST" accept-charset="utf-8">

Expand All @@ -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'];
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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'];
Expand Down Expand Up @@ -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'];
Expand Down

0 comments on commit 9dd7e25

Please sign in to comment.