Skip to content

Commit efe500d

Browse files
committed
[TwigBridge][Workflow] Fixed code and tests
1 parent 4d0cc68 commit efe500d

File tree

4 files changed

+25
-30
lines changed

4 files changed

+25
-30
lines changed

src/Symfony/Bridge/Twig/CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
CHANGELOG
22
=========
33

4+
3.3.0
5+
-----
6+
7+
* added a `workflow_has_marked_place` function
8+
49
3.2.0
510
-----
611

712
* added `AppVariable::getToken()`
813
* Deprecated the possibility to inject the Form `TwigRenderer` into the `FormExtension`.
9-
* [BC BREAK] Registering the `FormExtension` without configuring a runtime loader for the `TwigRenderer`
14+
* [BC BREAK] Registering the `FormExtension` without configuring a runtime loader for the `TwigRenderer`
1015
doesn't work anymore.
11-
16+
1217
Before:
1318

1419
```php
@@ -36,6 +41,7 @@ CHANGELOG
3641
$twig->addExtension(new FormExtension());
3742
```
3843
* Deprecated the `TwigRendererEngineInterface` interface.
44+
* added WorkflownExtension (provides `workflow_can` and `workflow_transitions`)
3945

4046
2.7.0
4147
-----

src/Symfony/Bridge/Twig/Extension/WorkflowExtension.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function getFunctions()
3232
return array(
3333
new \Twig_SimpleFunction('workflow_can', array($this, 'canTransition')),
3434
new \Twig_SimpleFunction('workflow_transitions', array($this, 'getEnabledTransitions')),
35-
new \Twig_SimpleFunction('workflow_has_place', array($this, 'hasPlace')),
35+
new \Twig_SimpleFunction('workflow_has_marked_place', array($this, 'hasMarkedPlace')),
3636
);
3737
}
3838

@@ -46,12 +46,9 @@ public function getEnabledTransitions($object, $name = null)
4646
return $this->workflowRegistry->get($object, $name)->getEnabledTransitions($object);
4747
}
4848

49-
public function hasPlace($object, $state, $name = null)
49+
public function hasMarkedPlace($object, $place, $name = null)
5050
{
51-
$workflow = $this->workflowRegistry->get($object, $name);
52-
$marking = $workflow->getMarking($object);
53-
54-
return $marking->has($state);
51+
return $this->workflowRegistry->get($object, $name)->getMarking($object)->has($place);
5552
}
5653

5754
public function getName()

src/Symfony/Bridge/Twig/Tests/Extension/WorkflowExtensionTest.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Twig\Tests\Extension;
1313

1414
use Symfony\Bridge\Twig\Extension\WorkflowExtension;
15+
use Symfony\Component\Workflow\Definition;
1516
use Symfony\Component\Workflow\Marking;
1617
use Symfony\Component\Workflow\Registry;
1718
use Symfony\Component\Workflow\Workflow;
@@ -20,35 +21,26 @@ class WorkflowExtensionTest extends \PHPUnit_Framework_TestCase
2021
{
2122
protected function setUp()
2223
{
23-
parent::setUp();
24-
25-
if (!class_exists('Symfony\Component\Workflow\Workflow')) {
24+
if (!class_exists(Workflow::class)) {
2625
$this->markTestSkipped('The Workflow component is needed to run tests for this extension.');
2726
}
2827
}
2928

30-
public function testHasPlace()
29+
public function testHasMarkedPlace()
3130
{
32-
$subject = new \stdClass();
33-
34-
$marking = new Marking(array('ordered' => true, 'waiting_for_payment' => true));
31+
$definition = new Definition(['ordered', 'waiting_for_payment', 'processed'], []);
32+
$workflow = new Workflow($definition);
3533

36-
$workflow = $this->getMock(Workflow::class, array(), array(), '', false);
37-
$workflow->expects($this->exactly(3))
38-
->method('getMarking')
39-
->with($subject)
40-
->will($this->returnValue($marking));
41-
42-
$registry = $this->getMock(Registry::class);
43-
$registry->expects($this->exactly(3))
44-
->method('get')
45-
->with($subject)
46-
->will($this->returnValue($workflow));
34+
$registry = new Registry();
35+
$registry->add($workflow, \stdClass::class);
4736

4837
$extension = new WorkflowExtension($registry);
4938

50-
$this->assertTrue($extension->hasPlace($subject, 'ordered'));
51-
$this->assertTrue($extension->hasPlace($subject, 'waiting_for_payment'));
52-
$this->assertFalse($extension->hasPlace($subject, 'processed'));
39+
$subject = new \stdClass();
40+
$subject->marking = array('ordered' => 1, 'waiting_for_payment' => 1);
41+
42+
$this->assertTrue($extension->hasMarkedPlace($subject, 'ordered'));
43+
$this->assertTrue($extension->hasMarkedPlace($subject, 'waiting_for_payment'));
44+
$this->assertFalse($extension->hasMarkedPlace($subject, 'processed'));
5345
}
5446
}

src/Symfony/Component/Workflow/Marking.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Marking
2121
private $places = array();
2222

2323
/**
24-
* @param string[] $representation Keys are the place name and values should be 1
24+
* @param int[] $representation Keys are the place name and values should be 1
2525
*/
2626
public function __construct(array $representation = array())
2727
{

0 commit comments

Comments
 (0)