From 9221451b6c1156c240dcbb937bc034a63f38f300 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Tue, 22 Nov 2022 08:28:33 +0100 Subject: [PATCH] [Notifier][SmsBiuras] Simplify test and data provider Follows * #48262 --- .../Tests/SmsBiurasTransportTest.php | 54 ++++--------------- 1 file changed, 11 insertions(+), 43 deletions(-) diff --git a/src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php b/src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php index 6e0461b9828e6..7a232ca856cc1 100644 --- a/src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/SmsBiuras/Tests/SmsBiurasTransportTest.php @@ -50,9 +50,9 @@ public function unsupportedMessagesProvider(): iterable /** * @dataProvider provideTestMode() */ - public function testTestMode(array $expected, array $provided) + public function testTestMode(int $expected, bool $testMode) { - $message = new SmsMessage($provided['phone'], $provided['message']); + $message = new SmsMessage('+37012345678', 'Hello World!'); $response = $this->createMock(ResponseInterface::class); $response->expects($this->atLeast(1)) @@ -62,15 +62,15 @@ public function testTestMode(array $expected, array $provided) ->method('getContent') ->willReturn('OK: 519545'); - $client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expected): ResponseInterface { + $client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $message, $testMode, $expected): ResponseInterface { $this->assertSame('GET', $method); $this->assertSame(sprintf( 'https://savitarna.smsbiuras.lt/api?uid=uid&apikey=api_key&message=%s&from=from&test=%s&to=%s', - rawurlencode($expected['message']), - $expected['transport']['test_mode'], - rawurlencode($expected['phone']), + rawurlencode($message->getSubject()), + $expected, + rawurlencode($message->getPhone()), ), $url); - $this->assertSame($expected['transport']['test_mode'], $options['query']['test']); + $this->assertSame($expected, $options['query']['test']); $this->assertSame(200, $response->getStatusCode()); $this->assertSame('OK: 519545', $response->getContent()); @@ -78,48 +78,16 @@ public function testTestMode(array $expected, array $provided) return $response; }); - $transport = new SmsBiurasTransport('uid', 'api_key', 'from', $provided['transport']['test_mode'], $client); + $transport = new SmsBiurasTransport('uid', 'api_key', 'from', $testMode, $client); $sentMessage = $transport->send($message); $this->assertSame('519545', $sentMessage->getMessageId()); } - public static function provideTestMode(): array + public static function provideTestMode(): iterable { - return [ - [ - [ - 'phone' => '+37012345678', - 'message' => 'Hello world!', - 'transport' => [ - 'test_mode' => 0, - ], - ], - [ - 'phone' => '+37012345678', - 'message' => 'Hello world!', - 'transport' => [ - 'test_mode' => 0, - ], - ], - ], - [ - [ - 'phone' => '+37012345678', - 'message' => 'Hello world!', - 'transport' => [ - 'test_mode' => 1, - ], - ], - [ - 'phone' => '+37012345678', - 'message' => 'Hello world!', - 'transport' => [ - 'test_mode' => 1, - ], - ], - ], - ]; + yield [1, true]; + yield [0, false]; } }