| @@ 810-840 (lines=31) @@ | ||
| 807 | } |
|
| 808 | ||
| 809 | /** @dataProvider rules */ |
|
| 810 | public function testRulesKnowsIfRuleIsDefinedOrNot($expectation, $ruleName) |
|
| 811 | { |
|
| 812 | $configurator = new Configurator( |
|
| 813 | 'email-resource', |
|
| 814 | new Container([ |
|
| 815 | 'resources' => [ |
|
| 816 | 'email-resource' => [ |
|
| 817 | 'constraints' => [ |
|
| 818 | 'mandatory' => [ |
|
| 819 | 'first-email', |
|
| 820 | ], |
|
| 821 | 'rules' => [ |
|
| 822 | 'first-email' => [ 'custom-validator' => 'email' ], |
|
| 823 | ], |
|
| 824 | ] |
|
| 825 | ], |
|
| 826 | ], |
|
| 827 | ]) |
|
| 828 | ); |
|
| 829 | ||
| 830 | $properties = [ |
|
| 831 | 'first-email' => '[email protected]', |
|
| 832 | ]; |
|
| 833 | ||
| 834 | $resource = Resource::box($properties, $configurator); |
|
| 835 | ||
| 836 | $this->assertEquals( |
|
| 837 | $expectation, |
|
| 838 | $resource->isRuleDefinedFor($ruleName) |
|
| 839 | ); |
|
| 840 | } |
|
| 841 | ||
| 842 | public function rules() |
|
| 843 | { |
|
| @@ 850-882 (lines=33) @@ | ||
| 847 | ]; |
|
| 848 | } |
|
| 849 | ||
| 850 | public function testProvideRule() |
|
| 851 | { |
|
| 852 | $aSpecificRule = [ 'custom-validator' => 'email' ]; |
|
| 853 | ||
| 854 | $configurator = new Configurator( |
|
| 855 | 'email-resource', |
|
| 856 | new Container([ |
|
| 857 | 'resources' => [ |
|
| 858 | 'email-resource' => [ |
|
| 859 | 'constraints' => [ |
|
| 860 | 'mandatory' => [ |
|
| 861 | 'first-email', |
|
| 862 | ], |
|
| 863 | 'rules' => [ |
|
| 864 | 'first-email' => $aSpecificRule, |
|
| 865 | ], |
|
| 866 | ] |
|
| 867 | ], |
|
| 868 | ], |
|
| 869 | ]) |
|
| 870 | ); |
|
| 871 | ||
| 872 | $properties = [ |
|
| 873 | 'first-email' => '[email protected]', |
|
| 874 | ]; |
|
| 875 | ||
| 876 | $resource = Resource::box($properties, $configurator); |
|
| 877 | ||
| 878 | $this->assertEquals( |
|
| 879 | $aSpecificRule, |
|
| 880 | $resource->getRule('first-email')->asArray() |
|
| 881 | ); |
|
| 882 | } |
|
| 883 | ||
| 884 | /** |
|
| 885 | * @expectedException Sensorario\Resources\Exceptions\PropertyWithoutRuleException |
|