PredictionTest.php
3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
namespace FootyRoom\Tests\Unit\Predictor;
use FootyRoom\Tests\TestCase;
use FootyRoom\Core\CoreException;
use FootyRoom\Core\Predictor\Prediction;
use FootyRoom\Core\Predictor\PredictionCreated;
use FootyRoom\Core\Predictor\PredictionStakeRaised;
class PredictionTest extends TestCase
{
protected const USER_ID = 1000;
protected const MATCH_ID = 2000;
protected const HOME_SCORE = 1;
protected const AWAY_SCORE = 3;
protected const STAKE = 0;
public function setUp()
{
$this->prediction = new Prediction(
self::USER_ID,
self::MATCH_ID,
self::HOME_SCORE,
self::AWAY_SCORE,
self::STAKE
);
parent::setUp();
}
public function test_it_raises_prediction_created_event()
{
$this->assertEquals($this->prediction->releaseEvents(), [new PredictionCreated($this->prediction)]);
}
public function test_it_doesnt_let_you_make_negative_bet()
{
$this->expectException(CoreException::class);
$this->prediction->bet(-1);
}
public function test_it_doesnt_let_you_lower_your_bet()
{
$this->prediction->bet(100);
$this->expectException(CoreException::class);
$this->prediction->bet(50);
}
public function test_it_raises_your_bet_to_new_value()
{
$this->prediction->bet(100);
$this->assertEquals($this->prediction->getStake(), 100);
$this->prediction->bet(200);
$this->assertEquals($this->prediction->getStake(), 200);
}
public function test_it_raises_prediction_stake_raised_event()
{
$this->prediction->releaseEvents();
$this->prediction->bet(100);
$this->assertEquals($this->prediction->releaseEvents(), [new PredictionStakeRaised($this->prediction, 100)]);
$this->prediction->bet(150);
$this->assertEquals($this->prediction->releaseEvents(), [new PredictionStakeRaised($this->prediction, 50)]);
}
public function test_it_lets_you_change_score()
{
$this->prediction->change(5, 6);
$this->assertEquals($this->prediction->getHomeScore(), 5);
$this->assertEquals($this->prediction->getAwayScore(), 6);
}
public function test_it_doesnt_let_you_change_score_if_bet_is_set()
{
$this->prediction->bet(100);
$this->expectException(CoreException::class);
$this->prediction->change(0, 1);
}
public function test_it_doesnt_let_you_set_crazy_scores()
{
$this->expectException(CoreException::class);
$this->prediction->change(20, 30);
}
public function test_it_should_initialize()
{
$this->assertEquals($this->prediction->getUserId(), self::USER_ID);
$this->assertEquals($this->prediction->getMatchId(), self::MATCH_ID);
$this->assertEquals($this->prediction->getHomeScore(), self::HOME_SCORE);
$this->assertEquals($this->prediction->getAwayScore(), self::AWAY_SCORE);
$this->assertEquals($this->prediction->getStake(), self::STAKE);
}
public function test_it_should_place_stake_during_initialization()
{
$prediction = new Prediction(
self::USER_ID,
self::MATCH_ID,
self::HOME_SCORE,
self::AWAY_SCORE,
100
);
$this->assertEquals($prediction->getStake(), 100);
$this->assertTrue(in_array(new PredictionStakeRaised($prediction, 100), $prediction->releaseEvents()));
}
}