8000 [Notifier] [SmsBiuras] Simplify test and data provider by OskarStark · Pull Request #48278 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] [SmsBiuras] Simplify test and data provider #48278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -62,64 +62,32 @@ 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());

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];
}
}
0