File size: 1,713 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

declare(strict_types=1);

namespace Mautic\SmsBundle\Tests\Integration\Twilio;

use Mautic\LeadBundle\Entity\Lead;
use Mautic\PluginBundle\Helper\IntegrationHelper;
use Mautic\SmsBundle\Integration\Twilio\Configuration;
use Mautic\SmsBundle\Integration\Twilio\TwilioTransport;
use Monolog\Logger;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class TwilioTransportTest extends TestCase
{
    private TwilioTransport $twilioTransport;

    /**
     * @var MockObject&\Monolog\Logger
     */
    private MockObject $logger;

    protected function setUp(): void
    {
        $this->logger      = $this->createMock(Logger::class);
        $integrationHelper = $this->createMock(IntegrationHelper::class);
        $configuration     = new Configuration($integrationHelper);

        $this->twilioTransport = new TwilioTransport($configuration, $this->logger);
    }

    public function testSendSMS(): void
    {
        $lead = new Lead();
        $lead->setMobile('123456');
        $this->logger->expects($this->once())
            ->method('warning')
            ->with('mautic.sms.transport.twilio.not_configured');

        $this->twilioTransport->sendSms($lead, 'some_content');
    }

    public function testCreatePayload(): void
    {
        $reflection = new \ReflectionClass($this->twilioTransport::class);
        $method     = $reflection->getMethod('createPayload');
        $method->setAccessible(true);

        $payload = ['messagingServiceSid' => 'MS1234', 'body' => 'some_content'];

        $result = $method->invokeArgs($this->twilioTransport, array_values($payload));
        Assert::assertSame($payload, $result);
    }
}