Skip to content

Commit e6a0cbe

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: Revert "bug #53865 [Workflow]Fix Marking when it must contains more than one tokens (lyrixx)"
2 parents f210400 + b639f68 commit e6a0cbe

File tree

4 files changed

+22
-191
lines changed

4 files changed

+22
-191
lines changed

Marking.php

+6-29
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,32 @@ class Marking
2727
public function __construct(array $representation = [])
2828
{
2929
foreach ($representation as $place => $nbToken) {
30-
$this->mark($place, $nbToken);
30+
$this->mark($place);
3131
}
3232
}
3333

3434
/**
3535
* @return void
3636
*/
37-
public function mark(string $place, int $nbToken = 1)
37+
public function mark(string $place)
3838
{
39-
if ($nbToken < 1) {
40-
throw new \LogicException(sprintf('The number of tokens must be greater than 0, "%s" given.', $nbToken));
41-
}
42-
43-
if (!\array_key_exists($place, $this->places)) {
44-
$this->places[$place] = 0;
45-
}
46-
$this->places[$place] += $nbToken;
39+
$this->places[$place] = 1;
4740
}
4841

4942
/**
5043
* @return void
5144
*/
52-
public function unmark(string $place, int $nbToken = 1)
45+
public function unmark(string $place)
5346
{
54-
if ($nbToken < 1) {
55-
throw new \LogicException(sprintf('The number of tokens must be greater than 0, "%s" given.', $nbToken));
56-
}
57-
58-
if (!$this->has($place)) {
59-
throw new \LogicException(sprintf('The place "%s" is not marked.', $place));
60-
}
61-
62-
$this->places[$place] -= $nbToken;
63-
64-
if (0 > $this->places[$place]) {
65-
throw new \LogicException(sprintf('The place "%s" could not contain a negative token number.', $place));
66-
}
67-
68-
if (0 === $this->places[$place]) {
69-
unset($this->places[$place]);
70-
}
47+
unset($this->places[$place]);
7148
}
7249

7350
/**
7451
* @return bool
7552
*/
7653
public function has(string $place)
7754
{
78-
return \array_key_exists($place, $this->places);
55+
return isset($this->places[$place]);
7956
}
8057

8158
/**

Tests/MarkingTest.php

+4-50
Original file line numberDiff line numberDiff line change
@@ -22,70 +22,24 @@ public function testMarking()
2222

2323
$this->assertTrue($marking->has('a'));
2424
$this->assertFalse($marking->has('b'));
25-
$this->assertPlaces(['a' => 1], $marking);
25+
$this->assertSame(['a' => 1], $marking->getPlaces());
2626

2727
$marking->mark('b');
2828

2929
$this->assertTrue($marking->has('a'));
3030
$this->assertTrue($marking->has('b'));
31-
$this->assertPlaces(['a' => 1, 'b' => 1], $marking);
31+
$this->assertSame(['a' => 1, 'b' => 1], $marking->getPlaces());
3232

3333
$marking->unmark('a');
3434

3535
$this->assertFalse($marking->has('a'));
3636
$this->assertTrue($marking->has('b'));
37-
$this->assertPlaces(['b' => 1], $marking);
37+
$this->assertSame(['b' => 1], $marking->getPlaces());
3838

3939
$marking->unmark('b');
4040

4141
$this->assertFalse($marking->has('a'));
4242
$this->assertFalse($marking->has('b'));
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 testGuardNotNbTokenLowerThanZero()
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.');
73-
$marking->unmark('a', 2);
74-
}
75-
76-
public function testGuardNotNbTokenEquals0()
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);
43+
$this->assertSame([], $marking->getPlaces());
9044
}
9145
}

Tests/WorkflowBuilderTrait.php

-39
Original file line numberDiff line numberDiff line change
@@ -158,43 +158,4 @@ private static function createComplexStateMachineDefinition(): Definition
158158
// | d | -------------+
159159
// +-----+
160160
}
161-
162-
private static function createWorkflowWithSameNameBackTransition(): Definition
163-
{
164-
$places = range('a', 'c');
165-
166-
$transitions = [];
167-
$transitions[] = new Transition('a_to_bc', 'a', ['b', 'c']);
168-
$transitions[] = new Transition('back1', 'b', 'a');
169-
$transitions[] = new Transition('back1', 'c', 'b');
170-
$transitions[] = new Transition('back2', 'c', 'b');
171-
$transitions[] = new Transition('back2', 'b', 'a');
172-
$transitions[] = new Transition('c_to_cb', 'c', ['b', 'c']);
173-
174-
return new Definition($places, $transitions);
175-
176-
// The graph looks like:
177-
// +-----------------------------------------------------------------+
178-
// | |
179-
// | |
180-
// | +---------------------------------------------+ |
181-
// v | v |
182-
// +---+ +---------+ +-------+ +---------+ +---+ +-------+
183-
// | a | --> | a_to_bc | --> | | --> | back2 | --> | | --> | back2 |
184-
// +---+ +---------+ | | +---------+ | | +-------+
185-
// ^ | | | |
186-
// | | c | <-----+ | b |
187-
// | | | | | |
188-
// | | | +---------+ | | +-------+
189-
// | | | --> | c_to_cb | --> | | --> | back1 |
190-
// | +-------+ +---------+ +---+ +-------+
191-
// | | ^ |
192-
// | | | |
193-
// | v | |
194-
// | +-------+ | |
195-
// | | back1 | ----------------------+ |
196-
// | +-------+ |
197-
// | |
198-
// +-----------------------------------------------------------------+
199-
}
200161
}

Tests/WorkflowTest.php

+12-73
Original file line numberDiff line numberDiff line change
@@ -319,32 +319,28 @@ public function testApplyWithSameNameTransition()
319319

320320
$marking = $workflow->apply($subject, 'a_to_bc');
321321

322-
$this->assertPlaces([
323-
'b' => 1,
324-
'c' => 1,
325-
], $marking);
322+
$this->assertFalse($marking->has('a'));
323+
$this->assertTrue($marking->has('b'));
324+
$this->assertTrue($marking->has('c'));
326325

327326
$marking = $workflow->apply($subject, 'to_a');
328327

329-
// Two tokens in "a"
330-
$this->assertPlaces([
331-
'a' => 2,
332-
], $marking);
328+
$this->assertTrue($marking->has('a'));
329+
$this->assertFalse($marking->has('b'));
330+
$this->assertFalse($marking->has('c'));
333331

334332
$workflow->apply($subject, 'a_to_bc');
335333
$marking = $workflow->apply($subject, 'b_to_c');
336334

337-
$this->assertPlaces([
338-
'a' => 1,
339-
'c' => 2,
340-
], $marking);
335+
$this->assertFalse($marking->has('a'));
336+
$this->assertFalse($marking->has('b'));
337+
$this->assertTrue($marking->has('c'));
341338

342339
$marking = $workflow->apply($subject, 'to_a');
343340

344-
$this->assertPlaces([
345-
'a' => 2,
346-
'c' => 1,
347-
], $marking);
341+
$this->assertTrue($marking->has('a'));
342+
$this->assertFalse($marking->has('b'));
343+
$this->assertFalse($marking->has('c'));
348344
}
349345

350346
public function testApplyWithSameNameTransition2()
@@ -780,63 +776,6 @@ public function testGetEnabledTransitionsWithSameNameTransition()
780776
$this->assertSame('to_a', $transitions[1]->getName());
781777
$this->assertSame('to_a', $transitions[2]->getName());
782778
}
783-
784-
/**
785-
* @@testWith ["back1"]
786-
* ["back2"]
787-
*/
788-
public function testApplyWithSameNameBackTransition(string $transition)
789-
{
790-
$definition = $this->createWorkflowWithSameNameBackTransition();
791-
$workflow = new Workflow($definition, new MethodMarkingStore());
792-
793-
$subject = new Subject();
794-
795-
$marking = $workflow->apply($subject, 'a_to_bc');
796-
$this->assertPlaces([
797-
'b' => 1,
798-
'c' => 1,
799-
], $marking);
800-
801-
$marking = $workflow->apply($subject, $transition);
802-
$this->assertPlaces([
803-
'a' => 1,
804-
'b' => 1,
805-
], $marking);
806-
807-
$marking = $workflow->apply($subject, $transition);
808-
$this->assertPlaces([
809-
'a' => 2,
810-
], $marking);
811-
812-
$marking = $workflow->apply($subject, 'a_to_bc');
813-
$this->assertPlaces([
814-
'a' => 1,
815-
'b' => 1,
816-
'c' => 1,
817-
], $marking);
818-
819-
$marking = $workflow->apply($subject, 'c_to_cb');
820-
$this->assertPlaces([
821-
'a' => 1,
822-
'b' => 2,
823-
'c' => 1,
824-
], $marking);
825-
826-
$marking = $workflow->apply($subject, 'c_to_cb');
827-
$this->assertPlaces([
828-
'a' => 1,
829-
'b' => 3,
830-
'c' => 1,
831-
], $marking);
832-
}
833-
834-
private function assertPlaces(array $expected, Marking $marking)
835-
{
836-
$places = $marking->getPlaces();
837-
ksort($places);
838-
$this->assertSame($expected, $places);
839-
}
840779
}
841780

842781
class EventDispatcherMock implements \Symfony\Contracts\EventDispatcher\EventDispatcherInterface

0 commit comments

Comments
 (0)