|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: davis |
|
5
|
|
|
* Date: 1/23/19 |
|
6
|
|
|
* Time: 10:22 AM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Davispeixoto\Workflow\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use Davispeixoto\Workflow\Tests\Auxiliary\SalesStates; |
|
12
|
|
|
use Davispeixoto\Workflow\Transition; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
class TransitionTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var SalesStates |
|
19
|
|
|
*/ |
|
20
|
|
|
private $from; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var SalesStates |
|
24
|
|
|
*/ |
|
25
|
|
|
private $to; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Transition |
|
29
|
|
|
*/ |
|
30
|
|
|
private $transition; |
|
31
|
|
|
|
|
32
|
|
|
public function __construct(?string $name = null, array $data = [], string $dataName = '') |
|
33
|
|
|
{ |
|
34
|
|
|
parent::__construct($name, $data, $dataName); |
|
35
|
|
|
|
|
36
|
|
|
$this->from = new SalesStates(SalesStates::NEW); |
|
37
|
|
|
$this->to = new SalesStates(SalesStates::DEALING); |
|
38
|
|
|
$this->transition = new Transition($this->from, $this->to); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param SalesStates $from |
|
43
|
|
|
* @param SalesStates $to |
|
44
|
|
|
* @param Transition $expected |
|
45
|
|
|
* @dataProvider constructorProvider |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testConstructor(SalesStates $from, SalesStates $to, Transition $expected) |
|
48
|
|
|
{ |
|
49
|
|
|
$transition = new Transition($from, $to); |
|
50
|
|
|
$this->assertEquals($expected, $transition); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param Transition $transition |
|
55
|
|
|
* @param SalesStates $expected |
|
56
|
|
|
* @dataProvider getFromProvider |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testGetFrom(Transition $transition, SalesStates $expected) |
|
59
|
|
|
{ |
|
60
|
|
|
$this->assertEquals($expected, $transition->getFrom()); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Transition $transition |
|
65
|
|
|
* @param SalesStates $expected |
|
66
|
|
|
* @dataProvider getToProvider |
|
67
|
|
|
*/ |
|
68
|
|
|
public function testGetTo(Transition $transition, SalesStates $expected) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->assertEquals($expected, $transition->getTo()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
// Data providers |
|
74
|
|
|
public function constructorProvider() |
|
75
|
|
|
{ |
|
76
|
|
|
return [ |
|
77
|
|
|
[$this->from, $this->to, $this->transition] |
|
78
|
|
|
]; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getFromProvider() |
|
82
|
|
|
{ |
|
83
|
|
|
return [ |
|
84
|
|
|
[$this->transition, $this->from] |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getToProvider() |
|
89
|
|
|
{ |
|
90
|
|
|
return [ |
|
91
|
|
|
[$this->transition, $this->to] |
|
92
|
|
|
]; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|