Skip to content

Commit 22c20d4

Browse files
Add tests for webhook name regex
1 parent db0c787 commit 22c20d4

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/RegexTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bundle\MakerBundle\Maker\MakeWebhook;
1516
use Symfony\Bundle\MakerBundle\Test\MakerTestEnvironment;
1617

1718
/**
@@ -66,4 +67,28 @@ private function generatedFilesRegexDataProvider(): \Generator
6667
['tests/FooBarTest.php'],
6768
];
6869
}
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+
}
6994
}

0 commit comments

Comments
 (0)