| @@ 848-878 (lines=31) @@ | ||
| 845 | } | |
| 846 | ||
| 847 | /** @dataProvider rules */ | |
| 848 | public function testRulesKnowsIfRuleIsDefinedOrNot($expectation, $ruleName) | |
| 849 |     { | |
| 850 | $configurator = new Configurator( | |
| 851 | 'email-resource', | |
| 852 | new Container([ | |
| 853 | 'resources' => [ | |
| 854 | 'email-resource' => [ | |
| 855 | 'constraints' => [ | |
| 856 | 'mandatory' => [ | |
| 857 | 'first-email', | |
| 858 | ], | |
| 859 | 'rules' => [ | |
| 860 | 'first-email' => [ 'custom-validator' => 'email' ], | |
| 861 | ], | |
| 862 | ] | |
| 863 | ], | |
| 864 | ], | |
| 865 | ]) | |
| 866 | ); | |
| 867 | ||
| 868 | $properties = [ | |
| 869 | 'first-email' => '[email protected]', | |
| 870 | ]; | |
| 871 | ||
| 872 | $resource = Resource::box($properties, $configurator); | |
| 873 | ||
| 874 | $this->assertEquals( | |
| 875 | $expectation, | |
| 876 | $resource->isRuleDefinedFor($ruleName) | |
| 877 | ); | |
| 878 | } | |
| 879 | ||
| 880 | public function rules() | |
| 881 |     { | |
| @@ 888-920 (lines=33) @@ | ||
| 885 | ]; | |
| 886 | } | |
| 887 | ||
| 888 | public function testProvideRule() | |
| 889 |     { | |
| 890 | $aSpecificRule = [ 'custom-validator' => 'email' ]; | |
| 891 | ||
| 892 | $configurator = new Configurator( | |
| 893 | 'email-resource', | |
| 894 | new Container([ | |
| 895 | 'resources' => [ | |
| 896 | 'email-resource' => [ | |
| 897 | 'constraints' => [ | |
| 898 | 'mandatory' => [ | |
| 899 | 'first-email', | |
| 900 | ], | |
| 901 | 'rules' => [ | |
| 902 | 'first-email' => $aSpecificRule, | |
| 903 | ], | |
| 904 | ] | |
| 905 | ], | |
| 906 | ], | |
| 907 | ]) | |
| 908 | ); | |
| 909 | ||
| 910 | $properties = [ | |
| 911 | 'first-email' => '[email protected]', | |
| 912 | ]; | |
| 913 | ||
| 914 | $resource = Resource::box($properties, $configurator); | |
| 915 | ||
| 916 | $this->assertEquals( | |
| 917 | $aSpecificRule, | |
| 918 |             $resource->getRule('first-email')->asArray() | |
| 919 | ); | |
| 920 | } | |
| 921 | ||
| 922 | /** | |
| 923 | * @expectedException Sensorario\Resources\Exceptions\PropertyWithoutRuleException | |