|
12 | 12 | namespace Symfony\Bundle\MakerBundle\Tests;
|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase;
|
| 15 | +use Symfony\Bundle\MakerBundle\Maker\MakeWebhook; |
15 | 16 | use Symfony\Bundle\MakerBundle\Test\MakerTestEnvironment;
|
16 | 17 |
|
17 | 18 | /**
|
@@ -66,4 +67,28 @@ private function generatedFilesRegexDataProvider(): \Generator
|
66 | 67 | ['tests/FooBarTest.php'],
|
67 | 68 | ];
|
68 | 69 | }
|
| 70 | + |
| 71 | + /** @dataProvider webhookNameRegexDataProvider */ |
| 72 | + public function testWebhookNameRegex(string $subjectData, bool $expectedResult): void |
| 73 | + { |
| 74 | + $result = preg_match(MakeWebhook::WEBHOOK_NAME_PATTERN, $subjectData); |
| 75 | + |
| 76 | + self::assertSame($expectedResult, (bool) $result); |
| 77 | + } |
| 78 | + |
| 79 | + private function webhookNameRegexDataProvider(): \Generator |
| 80 | + { |
| 81 | + // Valid cases |
| 82 | + yield 'Simple word' => ['mywebhook', true]; |
| 83 | + yield 'With underscore' => ['my_webhook', true]; |
| 84 | + yield 'With hyphen' => ['my-webhook', true]; |
| 85 | + yield 'With extend ascii chars' => ['éÿù', true]; |
| 86 | + yield 'With numbers' => ['mywebh00k', true]; |
| 87 | + |
| 88 | + // Invalid cases |
| 89 | + yield 'Leading number' => ['1mywebh00k', false]; |
| 90 | + yield 'With space' => ['my webhook', false]; |
| 91 | + yield 'With non-ascii characters' => ['web🪝', false]; |
| 92 | + |
| 93 | + } |
69 | 94 | }
|
0 commit comments