Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@..
Decoded Output download
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Notifier\Bridge\Brevo\Tests;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Brevo\BrevoTransport;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class BrevoTransportTest extends TransportTestCase
{
public static function createTransport(?HttpClientInterface $client = null): BrevoTransport
{
return (new BrevoTransport('api-key', '0611223344', $client ?? new MockHttpClient()))->setHost('host.test');
}
public static function toStringProvider(): iterable
{
yield ['brevo://host.test?sender=0611223344', self::createTransport()];
}
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}
public static function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [new DummyMessage()];
}
public function testSendWithErrorResponseThrowsTransportException()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(400);
$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['code' => 400, 'message' => 'bad request']));
$client = new MockHttpClient(static fn (): ResponseInterface => $response);
$transport = self::createTransport($client);
$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send the SMS: bad request');
$transport->send(new SmsMessage('phone', 'testMessage'));
}
}
?>
Did this file decode correctly?
Original Code
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Notifier\Bridge\Brevo\Tests;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Notifier\Bridge\Brevo\BrevoTransport;
use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class BrevoTransportTest extends TransportTestCase
{
public static function createTransport(?HttpClientInterface $client = null): BrevoTransport
{
return (new BrevoTransport('api-key', '0611223344', $client ?? new MockHttpClient()))->setHost('host.test');
}
public static function toStringProvider(): iterable
{
yield ['brevo://host.test?sender=0611223344', self::createTransport()];
}
public static function supportedMessagesProvider(): iterable
{
yield [new SmsMessage('0611223344', 'Hello!')];
}
public static function unsupportedMessagesProvider(): iterable
{
yield [new ChatMessage('Hello!')];
yield [new DummyMessage()];
}
public function testSendWithErrorResponseThrowsTransportException()
{
$response = $this->createMock(ResponseInterface::class);
$response->expects($this->exactly(2))
->method('getStatusCode')
->willReturn(400);
$response->expects($this->once())
->method('getContent')
->willReturn(json_encode(['code' => 400, 'message' => 'bad request']));
$client = new MockHttpClient(static fn (): ResponseInterface => $response);
$transport = self::createTransport($client);
$this->expectException(TransportException::class);
$this->expectExceptionMessage('Unable to send the SMS: bad request');
$transport->send(new SmsMessage('phone', 'testMessage'));
}
}
Function Calls
None |
Stats
MD5 | 5dcbb6c4dda98ee634dae3de5b82ea19 |
Eval Count | 0 |
Decode Time | 93 ms |