Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 37d91c7

Browse filesBrowse files
committed
Merge branch '7.0' into 7.1
* 7.0: Revert "bug #53865 [Workflow]Fix Marking when it must contains more than one tokens (lyrixx)"
2 parents a8cb7df + 40cd30b commit 37d91c7
Copy full SHA for 37d91c7

File tree

4 files changed

+22
-191
lines changed
Filter options

4 files changed

+22
-191
lines changed

‎src/Symfony/Component/Workflow/Marking.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Marking.php
+6-29Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,23 @@ 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

34-
public function mark(string $place, int $nbToken = 1): void
34+
public function mark(string $place): void
3535
{
36-
if ($nbToken < 1) {
37-
throw new \LogicException(sprintf('The number of tokens must be greater than 0, "%s" given.', $nbToken));
38-
}
39-
40-
if (!\array_key_exists($place, $this->places)) {
41-
$this->places[$place] = 0;
42-
}
43-
$this->places[$place] += $nbToken;
36+
$this->places[$place] = 1;
4437
}
4538

46-
public function unmark(string $place, int $nbToken = 1): void
39+
public function unmark(string $place): void
4740
{
48-
if ($nbToken < 1) {
49-
throw new \LogicException(sprintf('The number of tokens must be greater than 0, "%s" given.', $nbToken));
50-
}
51-
52-
if (!$this->has($place)) {
53-
throw new \LogicException(sprintf('The place "%s" is not marked.', $place));
54-
}
55-
56-
$this->places[$place] -= $nbToken;
57-
58-
if (0 > $this->places[$place]) {
59-
throw new \LogicException(sprintf('The place "%s" could not contain a negative token number.', $place));
60-
}
61-
62-
if (0 === $this->places[$place]) {
63-
unset($this->places[$place]);
64-
}
41+
unset($this->places[$place]);
6542
}
6643

6744
public function has(string $place): bool
6845
{
69-
return \array_key_exists($place, $this->places);
46+
return isset($this->places[$place]);
7047
}
7148

7249
public function getPlaces(): array

‎src/Symfony/Component/Workflow/Tests/MarkingTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/MarkingTest.php
+4-50Lines changed: 4 additions & 50 deletions
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
}

‎src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php
-39Lines changed: 0 additions & 39 deletions
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
}

‎src/Symfony/Component/Workflow/Tests/WorkflowTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Workflow/Tests/WorkflowTest.php
+12-73Lines changed: 12 additions & 73 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.