Skip to content

Commit 2d6eb27

Browse files
authored
Merge pull request #7815 from kenjis/fix-validation-rule-instances
fix: instances of Validation rules are incremented each time `run()` is executed
2 parents e5d25ea + 6ff41c9 commit 2d6eb27

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

system/Validation/Validation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function __construct($config, RendererInterface $view)
107107
$this->config = $config;
108108

109109
$this->view = $view;
110+
111+
$this->loadRuleSets();
110112
}
111113

112114
/**
@@ -127,7 +129,6 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
127129
// `DBGroup` is a reserved name. For is_unique and is_not_unique
128130
$data['DBGroup'] = $dbGroup;
129131

130-
$this->loadRuleSets();
131132
$this->loadRuleGroup($group);
132133

133134
// If no rules exist, we return false to ensure

tests/system/Validation/ValidationTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,22 @@ public function testRunReturnsFalseWithNothingToDo(): void
240240
$this->assertFalse($this->validation->run([]));
241241
}
242242

243+
public function testRuleClassesInstantiatedOnce(): void
244+
{
245+
$this->validation->setRules([]);
246+
$this->validation->run([]);
247+
$count1 = count(
248+
$this->getPrivateProperty($this->validation, 'ruleSetInstances')
249+
);
250+
251+
$this->validation->run([]);
252+
$count2 = count(
253+
$this->getPrivateProperty($this->validation, 'ruleSetInstances')
254+
);
255+
256+
$this->assertSame($count1, $count2);
257+
}
258+
243259
public function testRunDoesTheBasics(): void
244260
{
245261
$data = ['foo' => 'notanumber'];

0 commit comments

Comments
 (0)