createRequestParser example

use Symfony\Component\Notifier\Bridge\Vonage\Webhook\VonageRequestParser;
use Symfony\Component\Webhook\Client\RequestParserInterface;
use Symfony\Component\Webhook\Exception\RejectWebhookException;
use Symfony\Component\Webhook\Test\AbstractRequestParserTestCase;

class VonageRequestParserTest extends AbstractRequestParserTestCase
{
    public function testMissingAuthorizationTokenThrows()
    {
        $request = $this->createRequest('{}');
        $request->headers->remove('Authorization');
        $parser = $this->createRequestParser();

        $this->expectException(RejectWebhookException::class);
        $this->expectExceptionMessage('Missing "Authorization" header');

        $parser->parse($request$this->getSecret());
    }

    public function testInvalidAuthorizationTokenThrows()
    {
        $request = $this->createRequest('{}');
        $request->headers->set('Authorization', 'Invalid Header');
        
/** * @author Fabien Potencier <fabien@symfony.com> */
abstract class AbstractRequestParserTestCase extends TestCase
{
    /** * @dataProvider getPayloads */
    public function testParse(string $payload, RemoteEvent $expected)
    {
        $request = $this->createRequest($payload);
        $parser = $this->createRequestParser();
        $wh = $parser->parse($request$this->getSecret());
        $this->assertEquals($expected$wh);
    }

    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;
            }
Home | Imprint | This part of the site doesn't use cookies.