|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Workflow\Tests\Event; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Workflow\Event\AnnounceEvent; |
| 16 | +use Symfony\Component\Workflow\Event\CompletedEvent; |
| 17 | +use Symfony\Component\Workflow\Event\EnteredEvent; |
| 18 | +use Symfony\Component\Workflow\Event\EnterEvent; |
| 19 | +use Symfony\Component\Workflow\Event\GuardEvent; |
| 20 | +use Symfony\Component\Workflow\Event\LeaveEvent; |
| 21 | +use Symfony\Component\Workflow\Event\TransitionEvent; |
| 22 | + |
| 23 | +class EventNameTraitTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @dataProvider getEvents |
| 27 | + * |
| 28 | + * @param class-string $class |
| 29 | + */ |
| 30 | + public function testEventNames(string $class, ?string $workflowName, ?string $transitionOrPlaceName, string $expected) |
| 31 | + { |
| 32 | + $name = $class::getName($workflowName, $transitionOrPlaceName); |
| 33 | + $this->assertEquals($expected, $name); |
| 34 | + } |
| 35 | + |
| 36 | + public static function getEvents(): iterable |
| 37 | + { |
| 38 | + yield [AnnounceEvent::class, null, null, 'workflow.announce']; |
| 39 | + yield [AnnounceEvent::class, 'post', null, 'workflow.post.announce']; |
| 40 | + yield [AnnounceEvent::class, 'post', 'publish', 'workflow.post.announce.publish']; |
| 41 | + |
| 42 | + yield [CompletedEvent::class, null, null, 'workflow.completed']; |
| 43 | + yield [CompletedEvent::class, 'post', null, 'workflow.post.completed']; |
| 44 | + yield [CompletedEvent::class, 'post', 'publish', 'workflow.post.completed.publish']; |
| 45 | + |
| 46 | + yield [EnteredEvent::class, null, null, 'workflow.entered']; |
| 47 | + yield [EnteredEvent::class, 'post', null, 'workflow.post.entered']; |
| 48 | + yield [EnteredEvent::class, 'post', 'published', 'workflow.post.entered.published']; |
| 49 | + |
| 50 | + yield [EnterEvent::class, null, null, 'workflow.enter']; |
| 51 | + yield [EnterEvent::class, 'post', null, 'workflow.post.enter']; |
| 52 | + yield [EnterEvent::class, 'post', 'published', 'workflow.post.enter.published']; |
| 53 | + |
| 54 | + yield [GuardEvent::class, null, null, 'workflow.guard']; |
| 55 | + yield [GuardEvent::class, 'post', null, 'workflow.post.guard']; |
| 56 | + yield [GuardEvent::class, 'post', 'publish', 'workflow.post.guard.publish']; |
| 57 | + |
| 58 | + yield [LeaveEvent::class, null, null, 'workflow.leave']; |
| 59 | + yield [LeaveEvent::class, 'post', null, 'workflow.post.leave']; |
| 60 | + yield [LeaveEvent::class, 'post', 'published', 'workflow.post.leave.published']; |
| 61 | + |
| 62 | + yield [TransitionEvent::class, null, null, 'workflow.transition']; |
| 63 | + yield [TransitionEvent::class, 'post', null, 'workflow.post.transition']; |
| 64 | + yield [TransitionEvent::class, 'post', 'publish', 'workflow.post.transition.publish']; |
| 65 | + } |
| 66 | + |
| 67 | + public function testInvalidArgumentExceptionIsThrownIfWorkflowNameIsMissing() |
| 68 | + { |
| 69 | + $this->expectException(\InvalidArgumentException::class); |
| 70 | + |
| 71 | + EnterEvent::getName(null, 'place'); |
| 72 | + } |
| 73 | +} |
0 commit comments