9
9
10
10
namespace Respect \Validation \Rules ;
11
11
12
+ use Respect \Validation \Exceptions \ValidationException ;
13
+ use Respect \Validation \Test \Rules \Stub ;
14
+ use Respect \Validation \Test \Rules \WrapperStub ;
12
15
use Respect \Validation \Test \TestCase ;
13
- use Respect \Validation \Validatable ;
14
16
15
17
/**
16
18
* @test core
@@ -23,56 +25,29 @@ final class AbstractWrapperTest extends TestCase
23
25
*/
24
26
public function shouldUseWrappedToValidate (): void
25
27
{
26
- $ input = ' Whatever ' ;
28
+ $ sut = new WrapperStub ( new Stub ( true )) ;
27
29
28
- $ validatable = $ this ->createMock (Validatable::class);
29
- $ validatable
30
- ->expects (self ::once ())
31
- ->method ('validate ' )
32
- ->with ($ input )
33
- ->will (self ::returnValue (true ));
34
-
35
- $ wrapper = $ this ->getMockForAbstractClass (AbstractWrapper::class, [$ validatable ]);
36
-
37
- self ::assertTrue ($ wrapper ->validate ($ input ));
30
+ self ::assertTrue ($ sut ->validate ('Whatever ' ));
38
31
}
39
32
40
33
/**
41
34
* @test
42
35
*/
43
36
public function shouldUseWrappedToAssert (): void
44
37
{
45
- $ input = 'Whatever ' ;
46
-
47
- $ validatable = $ this ->createMock (Validatable::class);
48
- $ validatable
49
- ->expects (self ::once ())
50
- ->method ('assert ' )
51
- ->with ($ input )
52
- ->will (self ::returnValue (true ));
53
-
54
- $ wrapper = $ this ->getMockForAbstractClass (AbstractWrapper::class, [$ validatable ]);
55
-
56
- $ wrapper ->assert ($ input );
38
+ $ sut = new WrapperStub (new Stub (false ));
39
+ $ this ->expectException (ValidationException::class);
40
+ $ sut ->assert ('Whatever ' );
57
41
}
58
42
59
43
/**
60
44
* @test
61
45
*/
62
46
public function shouldUseWrappedToCheck (): void
63
47
{
64
- $ input = 'Whatever ' ;
65
-
66
- $ validatable = $ this ->createMock (Validatable::class);
67
- $ validatable
68
- ->expects (self ::once ())
69
- ->method ('check ' )
70
- ->with ($ input )
71
- ->will (self ::returnValue (true ));
72
-
73
- $ wrapper = $ this ->getMockForAbstractClass (AbstractWrapper::class, [$ validatable ]);
74
-
75
- $ wrapper ->check ($ input );
48
+ $ sut = new WrapperStub (new Stub (false ));
49
+ $ this ->expectException (ValidationException::class);
50
+ $ sut ->check ('Whatever ' );
76
51
}
77
52
78
53
/**
@@ -82,15 +57,11 @@ public function shouldPassNameOnToWrapped(): void
82
57
{
83
58
$ name = 'Whatever ' ;
84
59
85
- $ validatable = $ this ->createMock (Validatable::class);
86
- $ validatable
87
- ->expects (self ::once ())
88
- ->method ('setName ' )
89
- ->with ($ name )
90
- ->will (self ::returnValue ($ validatable ));
60
+ $ rule = new Stub ();
91
61
92
- $ wrapper = $ this ->getMockForAbstractClass (AbstractWrapper::class, [$ validatable ]);
62
+ $ sut = new WrapperStub ($ rule );
63
+ $ sut ->setName ($ name );
93
64
94
- self ::assertSame ($ wrapper , $ wrapper -> setName ( $ name ));
65
+ self ::assertSame ($ name , $ rule -> getName ( ));
95
66
}
96
67
}
0 commit comments