14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Bridge \Twig \Extension \WorkflowExtension ;
16
16
use Symfony \Component \Workflow \Definition ;
17
+ use Symfony \Component \Workflow \Metadata \InMemoryMetadataStore ;
17
18
use Symfony \Component \Workflow \Registry ;
18
19
use Symfony \Component \Workflow \SupportStrategy \ClassInstanceSupportStrategy ;
19
20
use Symfony \Component \Workflow \SupportStrategy \InstanceOfSupportStrategy ;
23
24
class WorkflowExtensionTest extends TestCase
24
25
{
25
26
private $ extension ;
27
+ private $ t1 ;
26
28
27
29
protected function setUp ()
28
30
{
@@ -32,10 +34,21 @@ protected function setUp()
32
34
33
35
$ places = array ('ordered ' , 'waiting_for_payment ' , 'processed ' );
34
36
$ transitions = array (
35
- new Transition ('t1 ' , 'ordered ' , 'waiting_for_payment ' ),
37
+ $ this -> t1 = new Transition ('t1 ' , 'ordered ' , 'waiting_for_payment ' ),
36
38
new Transition ('t2 ' , 'waiting_for_payment ' , 'processed ' ),
37
39
);
38
- $ definition = new Definition ($ places , $ transitions );
40
+
41
+ $ metadataStore = null ;
42
+ if (class_exists (InMemoryMetadataStore::class)) {
43
+ $ transitionsMetadata = new \SplObjectStorage ();
44
+ $ transitionsMetadata ->attach ($ this ->t1 , array ('title ' => 't1 title ' ));
45
+ $ metadataStore = new InMemoryMetadataStore (
46
+ array ('title ' => 'workflow title ' ),
47
+ array ('orderer ' => array ('title ' => 'ordered title ' )),
48
+ $ transitionsMetadata
49
+ );
50
+ }
51
+ $ definition = new Definition ($ places , $ transitions , null , $ metadataStore );
39
52
$ workflow = new Workflow ($ definition );
40
53
41
54
$ registry = new Registry ();
@@ -88,4 +101,19 @@ public function testGetMarkedPlaces()
88
101
$ this ->assertSame (array ('ordered ' , 'waiting_for_payment ' ), $ this ->extension ->getMarkedPlaces ($ subject ));
89
102
$ this ->assertSame ($ subject ->marking , $ this ->extension ->getMarkedPlaces ($ subject , false ));
90
103
}
104
+
105
+ public function testGetMetadata ()
106
+ {
107
+ if (!class_exists (InMemoryMetadataStore::class)) {
108
+ $ this ->markTestSkipped ('This test requires symfony/workflow:4.1. ' );
109
+ }
110
+ $ subject = new \stdClass ();
111
+ $ subject ->marking = array ();
112
+
113
+ $ this ->assertSame ('workflow title ' , $ this ->extension ->getMetadata ($ subject , 'title ' ));
114
+ $ this ->assertSame ('ordered title ' , $ this ->extension ->getMetadata ($ subject , 'title ' , 'orderer ' ));
115
+ $ this ->assertSame ('t1 title ' , $ this ->extension ->getMetadata ($ subject , 'title ' , $ this ->t1 ));
116
+ $ this ->assertNull ($ this ->extension ->getMetadata ($ subject , 'not found ' ));
117
+ $ this ->assertNull ($ this ->extension ->getMetadata ($ subject , 'not found ' , $ this ->t1 ));
118
+ }
91
119
}
0 commit comments