Skip to content

Commit 74667da

Browse files
committed
fix tests
1 parent d8d3027 commit 74667da

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

tests/Casts/CurrencyCastTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,38 @@
1010

1111
class CurrencyCastTest extends TestCase
1212
{
13+
protected Model $model;
14+
protected function setUp():void
15+
{
16+
$this->model = $model = $this->getMockBuilder(Model::class)->disableOriginalConstructor()->getMock();
17+
}
1318
public function testItWillNotGetCurrencyFromNonStrings()
1419
{
1520
$this->expectException(UnexpectedValueException::class);
1621

17-
$model = $this->getMockBuilder(Model::class)->getMock();
18-
19-
(new CurrencyCast)->get($model, 'currency', 1, []);
22+
(new CurrencyCast)->get($this->model, 'currency', 1, []);
2023
}
2124

2225
public function testItWillNotSetCurrencyFromNonCurrencies()
2326
{
2427
$this->expectException(UnexpectedValueException::class);
2528

26-
$model = $this->getMockBuilder(Model::class)->getMock();
2729

28-
(new CurrencyCast)->set($model, 'currency', 'USD', []);
30+
(new CurrencyCast)->set($this->model, 'currency', 'USD', []);
2931
}
3032

3133
public function testItGetsCurrencyFromString()
3234
{
33-
$model = $this->getMockBuilder(Model::class)->getMock();
3435

35-
$value = (new CurrencyCast)->get($model, 'currency', 'USD', []);
36+
$value = (new CurrencyCast)->get($this->model, 'currency', 'USD', []);
3637

3738
$this->assertEquals(Currency::USD(), $value);
3839
}
3940

4041
public function testItSetsCurrencyAsString()
4142
{
42-
$mock = $this->getMockBuilder(Model::class)->getMock();
4343

44-
$value = (new CurrencyCast)->set($mock, 'currency', Currency::USD(), []);
44+
$value = (new CurrencyCast)->set($this->model, 'currency', Currency::USD(), []);
4545

4646
$this->assertSame('USD', $value);
4747
}

tests/Casts/MoneyCastTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,41 @@
1111

1212
class MoneyCastTest extends TestCase
1313
{
14+
protected Model $model;
15+
protected function setUp():void
16+
{
17+
$this->model = $model = $this->getMockBuilder(Model::class)->disableOriginalConstructor()->getMock();
18+
}
19+
1420
public function testItWillNotGetMoneyFromNonString()
1521
{
1622
$this->expectException(UnexpectedValueException::class);
1723

18-
$model = $this->getMockBuilder(Model::class)->getMock();
1924

20-
(new MoneyCast)->get($model, 'money', [], []);
25+
(new MoneyCast)->get($this->model, 'money', [], []);
2126
}
2227

2328
public function testItWillNotGetMoneyFromNonJson()
2429
{
2530
$this->expectException(UnexpectedValueException::class);
2631

27-
$model = $this->getMockBuilder(Model::class)->getMock();
2832

29-
(new MoneyCast)->get($model, 'money', 'testing', []);
33+
(new MoneyCast)->get($this->model, 'money', 'testing', []);
3034
}
3135

3236
public function testItWillNotGetMoneyFromIllFormedJson()
3337
{
3438
$this->expectException(UnexpectedValueException::class);
3539

36-
$model = $this->getMockBuilder(Model::class)->getMock();
3740

38-
(new MoneyCast)->get($model, 'money', '{"key":"value"}', []);
41+
(new MoneyCast)->get($this->model, 'money', '{"key":"value"}', []);
3942
}
4043

4144
public function testItGetsMoneyFromJson()
4245
{
43-
$model = $this->getMockBuilder(Model::class)->getMock();
4446
$json = '{"amount":1000,"currency":"USD"}';
4547

46-
$value = (new MoneyCast)->get($model, 'money', $json, []);
48+
$value = (new MoneyCast)->get($this->model, 'money', $json, []);
4749

4850
$this->assertEquals(
4951
new Money('1000', new Currency('USD')),
@@ -55,17 +57,15 @@ public function testItWillNotSetNonMoneyAsJson()
5557
{
5658
$this->expectException(UnexpectedValueException::class);
5759

58-
$model = $this->getMockBuilder(Model::class)->getMock();
5960

60-
(new MoneyCast)->set($model, 'money', 1000, []);
61+
(new MoneyCast)->set($this->model, 'money', 1000, []);
6162
}
6263

6364
public function testItSetsMoneyAsJson()
6465
{
65-
$model = $this->getMockBuilder(Model::class)->getMock();
6666
$money = new Money('1200', Currency::USD());
6767

68-
$value = (new MoneyCast)->set($model, 'money', $money, []);
68+
$value = (new MoneyCast)->set($this->model, 'money', $money, []);
6969

7070
$this->assertSame(
7171
'{"amount":1200,"currency":"USD"}',

0 commit comments

Comments
 (0)