@@ -22,24 +22,70 @@ public function testMarking()
22
22
23
23
$ this ->assertTrue ($ marking ->has ('a ' ));
24
24
$ this ->assertFalse ($ marking ->has ('b ' ));
25
- $ this ->assertSame (['a ' => 1 ], $ marking-> getPlaces () );
25
+ $ this ->assertPlaces (['a ' => 1 ], $ marking );
26
26
27
27
$ marking ->mark ('b ' );
28
28
29
29
$ this ->assertTrue ($ marking ->has ('a ' ));
30
30
$ this ->assertTrue ($ marking ->has ('b ' ));
31
- $ this ->assertSame (['a ' => 1 , 'b ' => 1 ], $ marking-> getPlaces () );
31
+ $ this ->assertPlaces (['a ' => 1 , 'b ' => 1 ], $ marking );
32
32
33
33
$ marking ->unmark ('a ' );
34
34
35
35
$ this ->assertFalse ($ marking ->has ('a ' ));
36
36
$ this ->assertTrue ($ marking ->has ('b ' ));
37
- $ this ->assertSame (['b ' => 1 ], $ marking-> getPlaces () );
37
+ $ this ->assertPlaces (['b ' => 1 ], $ marking );
38
38
39
39
$ marking ->unmark ('b ' );
40
40
41
41
$ this ->assertFalse ($ marking ->has ('a ' ));
42
42
$ this ->assertFalse ($ marking ->has ('b ' ));
43
- $ this ->assertSame ([], $ marking ->getPlaces ());
43
+ $ this ->assertPlaces ([], $ marking );
44
+
45
+ $ marking ->mark ('a ' );
46
+ $ this ->assertPlaces (['a ' => 1 ], $ marking );
47
+
48
+ $ marking ->mark ('a ' );
49
+ $ this ->assertPlaces (['a ' => 2 ], $ marking );
50
+
51
+ $ marking ->unmark ('a ' );
52
+ $ this ->assertPlaces (['a ' => 1 ], $ marking );
53
+
54
+ $ marking ->unmark ('a ' );
55
+ $ this ->assertPlaces ([], $ marking );
56
+ }
57
+
58
+ public function testGuardNotMarked ()
59
+ {
60
+ $ marking = new Marking ([]);
61
+
62
+ $ this ->expectException (\LogicException::class);
63
+ $ this ->expectExceptionMessage ('The place "a" is not marked. ' );
64
+ $ marking ->unmark ('a ' );
65
+ }
66
+
67
+ public function testUnmarkGuardResultTokenCountIsNotNegative ()
68
+ {
69
+ $ marking = new Marking (['a ' => 1 ]);
70
+
71
+ $ this ->expectException (\LogicException::class);
72
+ $ this ->expectExceptionMessage ('The place "a" could not contain a negative token number: "1" (initial) - "2" (nbToken) = "-1". ' );
73
+ $ marking ->unmark ('a ' , 2 );
74
+ }
75
+
76
+ public function testUnmarkGuardNbTokenIsGreaterThanZero ()
77
+ {
78
+ $ marking = new Marking (['a ' => 1 ]);
79
+
80
+ $ this ->expectException (\LogicException::class);
81
+ $ this ->expectExceptionMessage ('The number of tokens must be greater than 0, "0" given. ' );
82
+ $ marking ->unmark ('a ' , 0 );
83
+ }
84
+
85
+ private function assertPlaces (array $ expected , Marking $ marking )
86
+ {
87
+ $ places = $ marking ->getPlaces ();
88
+ ksort ($ places );
89
+ $ this ->assertSame ($ expected , $ places );
44
90
}
45
91
}
0 commit comments