Skip to content

Commit 470c41f

Browse files
authored
Merge pull request #7548 from kenjis/fix-feature-test-validation
fix: feature test with validation
2 parents e634bd5 + dbf469f commit 470c41f

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

system/Test/FeatureTestTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ public function call(string $method, string $path, ?array $params = null)
175175
// Make sure filters are reset between tests
176176
Services::injectMock('filters', Services::filters(null, false));
177177

178+
// Make sure validation is reset between tests
179+
Services::injectMock('validation', Services::validation(null, false));
180+
178181
$response = $this->app
179182
->setContext('web')
180183
->setRequest($request)

tests/system/Test/FeatureTestTraitTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,36 @@ public function testCallPostWithBody()
102102
$response->assertSee('Hello Mars!');
103103
}
104104

105+
public function testCallValidationTwice()
106+
{
107+
$this->withRoutes([
108+
[
109+
'post',
110+
'section/create',
111+
static function () {
112+
$validation = Services::validation();
113+
$validation->setRule('title', 'title', 'required|min_length[3]');
114+
115+
$post = Services::request()->getPost();
116+
117+
if ($validation->run($post)) {
118+
return 'Okay';
119+
}
120+
121+
return 'Invalid';
122+
},
123+
],
124+
]);
125+
126+
$response = $this->post('section/create', ['foo' => 'Mars']);
127+
128+
$response->assertSee('Invalid');
129+
130+
$response = $this->post('section/create', ['title' => 'Section Title']);
131+
132+
$response->assertSee('Okay');
133+
}
134+
105135
public function testCallPut()
106136
{
107137
$this->withRoutes([

0 commit comments

Comments
 (0)