11
11
12
12
class MoneyCastTest extends TestCase
13
13
{
14
+ protected Model $ model ;
15
+ protected function setUp ():void
16
+ {
17
+ $ this ->model = $ model = $ this ->getMockBuilder (Model::class)->disableOriginalConstructor ()->getMock ();
18
+ }
19
+
14
20
public function testItWillNotGetMoneyFromNonString ()
15
21
{
16
22
$ this ->expectException (UnexpectedValueException::class);
17
23
18
- $ model = $ this ->getMockBuilder (Model::class)->getMock ();
19
24
20
- (new MoneyCast )->get ($ model , 'money ' , [], []);
25
+ (new MoneyCast )->get ($ this -> model , 'money ' , [], []);
21
26
}
22
27
23
28
public function testItWillNotGetMoneyFromNonJson ()
24
29
{
25
30
$ this ->expectException (UnexpectedValueException::class);
26
31
27
- $ model = $ this ->getMockBuilder (Model::class)->getMock ();
28
32
29
- (new MoneyCast )->get ($ model , 'money ' , 'testing ' , []);
33
+ (new MoneyCast )->get ($ this -> model , 'money ' , 'testing ' , []);
30
34
}
31
35
32
36
public function testItWillNotGetMoneyFromIllFormedJson ()
33
37
{
34
38
$ this ->expectException (UnexpectedValueException::class);
35
39
36
- $ model = $ this ->getMockBuilder (Model::class)->getMock ();
37
40
38
- (new MoneyCast )->get ($ model , 'money ' , '{"key":"value"} ' , []);
41
+ (new MoneyCast )->get ($ this -> model , 'money ' , '{"key":"value"} ' , []);
39
42
}
40
43
41
44
public function testItGetsMoneyFromJson ()
42
45
{
43
- $ model = $ this ->getMockBuilder (Model::class)->getMock ();
44
46
$ json = '{"amount":1000,"currency":"USD"} ' ;
45
47
46
- $ value = (new MoneyCast )->get ($ model , 'money ' , $ json , []);
48
+ $ value = (new MoneyCast )->get ($ this -> model , 'money ' , $ json , []);
47
49
48
50
$ this ->assertEquals (
49
51
new Money ('1000 ' , new Currency ('USD ' )),
@@ -55,17 +57,15 @@ public function testItWillNotSetNonMoneyAsJson()
55
57
{
56
58
$ this ->expectException (UnexpectedValueException::class);
57
59
58
- $ model = $ this ->getMockBuilder (Model::class)->getMock ();
59
60
60
- (new MoneyCast )->set ($ model , 'money ' , 1000 , []);
61
+ (new MoneyCast )->set ($ this -> model , 'money ' , 1000 , []);
61
62
}
62
63
63
64
public function testItSetsMoneyAsJson ()
64
65
{
65
- $ model = $ this ->getMockBuilder (Model::class)->getMock ();
66
66
$ money = new Money ('1200 ' , Currency::USD ());
67
67
68
- $ value = (new MoneyCast )->set ($ model , 'money ' , $ money , []);
68
+ $ value = (new MoneyCast )->set ($ this -> model , 'money ' , $ money , []);
69
69
70
70
$ this ->assertSame (
71
71
'{"amount":1200,"currency":"USD"} ' ,
0 commit comments