Failed Conditions
Push — master ( 9bceb4...42a7b7 )
by Guilherme
02:51 queued 10s
created

SupportMessageTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\CoreBundle\Tests\Model;
12
13
use libphonenumber\PhoneNumber;
14
use LoginCidadao\CoreBundle\Entity\Person;
15
use LoginCidadao\CoreBundle\Model\SupportMessage;
16
use PHPUnit\Framework\TestCase;
17
use Symfony\Component\Translation\TranslatorInterface;
18
19
class SupportMessageTest extends TestCase
20
{
21
    public function testSimpleSupportMessage()
22
    {
23
        $message = (new SupportMessage())
24
            ->setName($name = 'Name Here')
25
            ->setEmail($email = '[email protected]')
26
            ->setMessage($text = 'Message');
27
28
        $this->assertSame($name, $message->getName());
29
        $this->assertSame($email, $message->getEmail());
30
        $this->assertSame($text, $message->getMessage());
31
    }
32
33
    /**
34
     * @throws \ReflectionException
35
     */
36
    public function testCompleteSupportMessage()
37
    {
38
        /** @var TranslatorInterface|\PHPUnit_Framework_MockObject_MockObject $translator */
39
        $translator = $this->createMock('Symfony\Component\Translation\TranslatorInterface');
40
        $translator->expects($this->exactly(10))->method('trans')->willReturnCallback(function ($text) {
41
            return $text;
42
        });
43
44
        $mobile = (new PhoneNumber())
45
            ->setCountryCode(55)
46
            ->setNationalNumber('51999999999');
47
48
        $person = (new Person())
49
            ->setFirstName($firstName = 'Fulano')
50
            ->setSurname($lastName = 'de Tal')
51
            ->setEmail($email = '[email protected]')
52
            ->setCreatedAt($createdAt = new \DateTime())
53
            ->setEmailConfirmedAt($emailConfirmedAt = new \DateTime())
54
            ->setMobile($mobile);
55
56
        $reflection = new \ReflectionClass($person);
57
        $property = $reflection->getProperty('id');
58
        $property->setAccessible(true);
59
        $property->setValue($person, '123');
60
61
        $message = (new SupportMessage($person))
62
            ->setMessage('My message');
63
        $formattedMessage = $message->getFormattedMessage($translator);
64
65
        $this->assertContains('My message', $formattedMessage);
66
        $this->assertContains(SupportMessage::EXTRA_HAS_CPF_NO, $formattedMessage);
67
        $this->assertContains(SupportMessage::EXTRA_EMAIL_CONFIRMED_AT, $formattedMessage);
68
        $this->assertContains(SupportMessage::EXTRA_CREATED_AT, $formattedMessage);
69
        $this->assertContains(SupportMessage::EXTRA_ID, $formattedMessage);
70
    }
71
}
72