/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Webhook/Test/AbstractRequestParserTestCase.php
74 строки
2 KB
Nicolas Grekas
Merge branch '6.4' into 7.4
06 июн 2026, 12:33
06 июн 2026, 12:33
3bd625f
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Webhook\Test; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\RemoteEvent\RemoteEvent; use Symfony\Component\Webhook\Client\RequestParserInterface; /** * @author Fabien Potencier <fabien@symfony.com> */ abstract class AbstractRequestParserTestCase extends TestCase { /** * @dataProvider getPayloads */ #[DataProvider('getPayloads')] public function testParse(string $payload, RemoteEvent|array $expected) { $request = $this->createRequest($payload); $parser = $this->createRequestParser(); $wh = $parser->parse($request, $this->getSecret()); $this->assertEquals($expected, $wh); } /** * @return iterable<array{string, RemoteEvent|RemoteEvent[]}> */ public static function getPayloads(): iterable { $currentDir = \dirname((new \ReflectionClass(static::class))->getFileName()); foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($currentDir.'/Fixtures', \RecursiveDirectoryIterator::SKIP_DOTS)) as $file) { $filename = str_replace($currentDir.'/Fixtures/', '', $file->getPathname()); if (static::getFixtureExtension() !== pathinfo($filename, \PATHINFO_EXTENSION)) { continue; } yield $filename => [ file_get_contents($file), include (str_replace('.'.static::getFixtureExtension(), '.php', $file->getPathname())), ]; } } abstract protected function createRequestParser(): RequestParserInterface; protected function getSecret(): string { return ''; } protected function createRequest(string $payload): Request { return Request::create('/', 'POST', [], [], [], [ 'CONTENT_TYPE' => 'application/json', ], $payload); } protected static function getFixtureExtension(): string { return 'json'; } }