|
9 | 9 | use Sourcetoad\RuleHelper\Contracts\DefinedRuleSets; |
10 | 10 | use Sourcetoad\RuleHelper\RuleHelperServiceProvider; |
11 | 11 | use Sourcetoad\RuleHelper\RuleSet; |
| 12 | +use Sourcetoad\RuleHelper\Tests\Stubs\ExampleNonBackedEnum; |
| 13 | +use Sourcetoad\RuleHelper\Tests\Stubs\ExampleStringDuplicateEnum; |
| 14 | +use Sourcetoad\RuleHelper\Tests\Stubs\ExampleStringEnum; |
12 | 15 | use Sourcetoad\RuleHelper\Tests\TestCase; |
13 | 16 |
|
14 | 17 | class DefinedRuleSetsTest extends TestCase |
@@ -88,4 +91,31 @@ public function testConcatDefinedRuleSet(): void |
88 | 91 | // Assert |
89 | 92 | $this->assertSame(['required', 'email'], $ruleSet->toArray()); |
90 | 93 | } |
| 94 | + |
| 95 | + public function testWorksWithNonBackedEnums(): void |
| 96 | + { |
| 97 | + // Arrange |
| 98 | + RuleSet::define(ExampleNonBackedEnum::Value, RuleSet::create()->email()); |
| 99 | + |
| 100 | + // Act |
| 101 | + $ruleSet = RuleSet::useDefined(ExampleNonBackedEnum::Value); |
| 102 | + |
| 103 | + // Assert |
| 104 | + $this->assertSame(['email'], $ruleSet->toArray()); |
| 105 | + } |
| 106 | + |
| 107 | + public function testDefinedEnumsWithDuplicateValuesAreTreatedAsDifferent(): void |
| 108 | + { |
| 109 | + // Arrange |
| 110 | + RuleSet::define(ExampleStringEnum::Another, RuleSet::create()->email()); |
| 111 | + RuleSet::define(ExampleStringDuplicateEnum::Another, RuleSet::create()->required()); |
| 112 | + |
| 113 | + // Act |
| 114 | + $ruleSetOne = RuleSet::useDefined(ExampleStringEnum::Another); |
| 115 | + $ruleSetTwo = RuleSet::useDefined(ExampleStringDuplicateEnum::Another); |
| 116 | + |
| 117 | + // Assert |
| 118 | + $this->assertSame(['email'], $ruleSetOne->toArray()); |
| 119 | + $this->assertSame(['required'], $ruleSetTwo->toArray()); |
| 120 | + } |
91 | 121 | } |
0 commit comments