File: MobytOptionsTest.php

package info (click to toggle)
symfony 7.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,424 kB
  • sloc: php: 1,510,651; xml: 7,039; javascript: 979; sh: 586; makefile: 242; pascal: 70
file content (88 lines) | stat: -rw-r--r-- 3,155 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?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\Notifier\Bridge\Mobyt\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Bridge\Mobyt\MobytOptions;
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Notification\Notification;

final class MobytOptionsTest extends TestCase
{
    #[\PHPUnit\Framework\Attributes\DataProvider('fromNotificationDataProvider')]
    public function testFromNotification(string $importance, string $expectedMessageType)
    {
        $notification = (new Notification('Foo'))->importance($importance);

        $options = MobytOptions::fromNotification($notification)->toArray();

        $this->assertSame($expectedMessageType, $options['message_type']);
    }

    /**
     * @return \Generator<array{0: string, 1: string}>
     */
    public static function fromNotificationDataProvider(): \Generator
    {
        yield [Notification::IMPORTANCE_URGENT, MobytOptions::MESSAGE_TYPE_QUALITY_HIGH];
        yield [Notification::IMPORTANCE_HIGH, MobytOptions::MESSAGE_TYPE_QUALITY_HIGH];
        yield [Notification::IMPORTANCE_MEDIUM, MobytOptions::MESSAGE_TYPE_QUALITY_MEDIUM];
        yield [Notification::IMPORTANCE_LOW, MobytOptions::MESSAGE_TYPE_QUALITY_LOW];
    }

    public function testFromNotificationDefaultLevel()
    {
        $notification = (new Notification('Foo'))->importance('Bar');

        $options = MobytOptions::fromNotification($notification)->toArray();

        $this->assertSame(MobytOptions::MESSAGE_TYPE_QUALITY_HIGH, $options['message_type']);
    }

    #[\PHPUnit\Framework\Attributes\DataProvider('validMessageTypes')]
    public function testMessageType(string $type)
    {
        $mobytOptions = new MobytOptions();
        $mobytOptions->messageType($type);

        $this->assertSame(['message_type' => $type], $mobytOptions->toArray());
    }

    public static function validMessageTypes(): iterable
    {
        yield [MobytOptions::MESSAGE_TYPE_QUALITY_HIGH];
        yield [MobytOptions::MESSAGE_TYPE_QUALITY_MEDIUM];
        yield [MobytOptions::MESSAGE_TYPE_QUALITY_LOW];
    }

    public function testCallingMessageTypeMethodWithUnknownTypeThrowsInvalidArgumentException()
    {
        $mobytOptions = new MobytOptions();

        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The message type "foo-bar" is not supported; supported message types are: "N", "L", "LL"');

        $mobytOptions->messageType('foo-bar');
    }

    public function testSettingMessageTypeViaConstructorWithUnknownTypeThrowsInvalidArgumentException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage(
            'The message type "foo-bar" is not supported; supported message types are: "N", "L", "LL"'
        );

        new MobytOptions([
            'message_type' => 'foo-bar',
        ]);
    }
}