Skip to content

Commit

Permalink
Add tests for webhook name regex
Browse files Browse the repository at this point in the history
  • Loading branch information
maelanleborgne committed Apr 2, 2024
1 parent db0c787 commit 22c20d4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/RegexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\MakerBundle\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\Maker\MakeWebhook;
use Symfony\Bundle\MakerBundle\Test\MakerTestEnvironment;

/**
Expand Down Expand Up @@ -66,4 +67,28 @@ private function generatedFilesRegexDataProvider(): \Generator
['tests/FooBarTest.php'],
];
}

/** @dataProvider webhookNameRegexDataProvider */
public function testWebhookNameRegex(string $subjectData, bool $expectedResult): void
{
$result = preg_match(MakeWebhook::WEBHOOK_NAME_PATTERN, $subjectData);

self::assertSame($expectedResult, (bool) $result);
}

private function webhookNameRegexDataProvider(): \Generator
{
// Valid cases
yield 'Simple word' => ['mywebhook', true];
yield 'With underscore' => ['my_webhook', true];
yield 'With hyphen' => ['my-webhook', true];
yield 'With extend ascii chars' => ['éÿù', true];
yield 'With numbers' => ['mywebh00k', true];

// Invalid cases
yield 'Leading number' => ['1mywebh00k', false];
yield 'With space' => ['my webhook', false];
yield 'With non-ascii characters' => ['web🪝', false];

}
}

0 comments on commit 22c20d4

Please sign in to comment.