Passed
Push — issue#782 ( 2c8345 )
by Guilherme
03:56 queued 10s
created

SupportMessageTest::testSupportMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
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 Symfony\Component\Translation\TranslatorInterface;
17
18
class SupportMessageTest extends \PHPUnit_Framework_TestCase
19
{
20
    public function testSimpleSupportMessage()
21
    {
22
        $message = (new SupportMessage())
23
            ->setName($name = 'Name Here')
24
            ->setEmail($email = '[email protected]')
25
            ->setMessage($text = 'Message');
26
27
        $this->assertSame($name, $message->getName());
28
        $this->assertSame($email, $message->getEmail());
29
        $this->assertSame($text, $message->getMessage());
30
    }
31
32
    /**
33
     * @throws \ReflectionException
34
     */
35
    public function testCompleteSupportMessage()
36
    {
37
        /** @var TranslatorInterface|\PHPUnit_Framework_MockObject_MockObject $translator */
38
        $translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
39
        $translator->expects($this->exactly(10))->method('trans')->willReturnCallback(function ($text) {
40
            return $text;
41
        });
42
43
        $mobile = (new PhoneNumber())
44
            ->setCountryCode(55)
45
            ->setNationalNumber('51999999999');
46
47
        $person = (new Person())
48
            ->setFirstName($firstName = 'Fulano')
49
            ->setSurname($lastName = 'de Tal')
50
            ->setEmail($email = '[email protected]')
51
            ->setCreatedAt($createdAt = new \DateTime())
52
            ->setEmailConfirmedAt($emailConfirmedAt = new \DateTime())
53
            ->setMobile($mobile);
54
55
        $reflection = new \ReflectionClass($person);
56
        $property = $reflection->getProperty('id');
57
        $property->setAccessible(true);
58
        $property->setValue($person, '123');
59
60
        $message = (new SupportMessage($person))
61
            ->setMessage('My message');
62
        $formattedMessage = $message->getFormattedMessage($translator);
63
64
        $this->assertContains('My message', $formattedMessage);
65
        $this->assertContains(SupportMessage::EXTRA_HAS_CPF_NO, $formattedMessage);
66
        $this->assertContains(SupportMessage::EXTRA_EMAIL_CONFIRMED_AT, $formattedMessage);
67
        $this->assertContains(SupportMessage::EXTRA_CREATED_AT, $formattedMessage);
68
        $this->assertContains(SupportMessage::EXTRA_ID, $formattedMessage);
69
    }
70
}
71