1
+ <?php
2
+
3
+ namespace Symfony \Component \Workflow \Tests \Event ;
4
+
5
+ use PHPUnit \Framework \TestCase ;
6
+ use Symfony \Component \Workflow \Event \AnnounceEvent ;
7
+ use Symfony \Component \Workflow \Event \CompletedEvent ;
8
+ use Symfony \Component \Workflow \Event \EnteredEvent ;
9
+ use Symfony \Component \Workflow \Event \EnterEvent ;
10
+ use Symfony \Component \Workflow \Event \GuardEvent ;
11
+ use Symfony \Component \Workflow \Event \LeaveEvent ;
12
+ use Symfony \Component \Workflow \Event \TransitionEvent ;
13
+
14
+ class EventNameTraitTest extends TestCase
15
+ {
16
+ /**
17
+ * @dataProvider getEvents
18
+ *
19
+ * @param class-string $class
20
+ */
21
+ public function testEventNames (string $ class , string |null $ workflowName , string |null $ transitionOrPlaceName , string $ expected )
22
+ {
23
+ $ name = $ class ::get ($ workflowName , $ transitionOrPlaceName );
24
+ $ this ->assertEquals ($ expected , $ name );
25
+ }
26
+
27
+ public static function getEvents (): iterable
28
+ {
29
+ yield [AnnounceEvent::class, null , null , 'workflow.announce ' ];
30
+ yield [AnnounceEvent::class, 'post ' , null , 'workflow.post.announce ' ];
31
+ yield [AnnounceEvent::class, 'post ' , 'publish ' , 'workflow.post.announce.publish ' ];
32
+
33
+ yield [CompletedEvent::class, null , null , 'workflow.completed ' ];
34
+ yield [CompletedEvent::class, 'post ' , null , 'workflow.post.completed ' ];
35
+ yield [CompletedEvent::class, 'post ' , 'publish ' , 'workflow.post.completed.publish ' ];
36
+
37
+ yield [EnteredEvent::class, null , null , 'workflow.entered ' ];
38
+ yield [EnteredEvent::class, 'post ' , null , 'workflow.post.entered ' ];
39
+ yield [EnteredEvent::class, 'post ' , 'published ' , 'workflow.post.entered.published ' ];
40
+
41
+ yield [EnterEvent::class, null , null , 'workflow.enter ' ];
42
+ yield [EnterEvent::class, 'post ' , null , 'workflow.post.enter ' ];
43
+ yield [EnterEvent::class, 'post ' , 'published ' , 'workflow.post.enter.published ' ];
44
+
45
+ yield [GuardEvent::class, null , null , 'workflow.guard ' ];
46
+ yield [GuardEvent::class, 'post ' , null , 'workflow.post.guard ' ];
47
+ yield [GuardEvent::class, 'post ' , 'publish ' , 'workflow.post.guard.publish ' ];
48
+
49
+ yield [LeaveEvent::class, null , null , 'workflow.leave ' ];
50
+ yield [LeaveEvent::class, 'post ' , null , 'workflow.post.leave ' ];
51
+ yield [LeaveEvent::class, 'post ' , 'published ' , 'workflow.post.leave.published ' ];
52
+
53
+ yield [TransitionEvent::class, null , null , 'workflow.transition ' ];
54
+ yield [TransitionEvent::class, 'post ' , null , 'workflow.post.transition ' ];
55
+ yield [TransitionEvent::class, 'post ' , 'publish ' , 'workflow.post.transition.publish ' ];
56
+ }
57
+
58
+ public function testInvalidArgumentExceptionIsThrownIfWorkflowNameIsMissing ()
59
+ {
60
+ $ this ->expectException (\InvalidArgumentException::class);
61
+
62
+ EnterEvent::get (null , 'place ' );
63
+ }
64
+ }
0 commit comments