Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

EmailPagePartTest::testSetErrorMessageRequired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\FormBundle\Tests\Tests\Entity\PageParts;
4
5
use ArrayObject;
6
use Kunstmaan\FormBundle\Entity\PageParts\EmailPagePart;
7
use Kunstmaan\FormBundle\Form\EmailPagePartAdminType;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\Form\FormBuilderInterface;
10
11
/**
12
 * Tests for EmailPagePart
13
 */
14
class EmailPagePartTest extends TestCase
15
{
16
    /**
17
     * @var EmailPagePart
18
     */
19
    protected $object;
20
21
    /**
22
     * Sets up the fixture, for example, opens a network connection.
23
     * This method is called before a test is executed.
24
     */
25
    protected function setUp()
26
    {
27
        $this->object = new EmailPagePart();
28
    }
29
30 View Code Duplication
    public function testSetErrorMessageRequired()
0 ignored issues
show
Duplication introduced by Wim Vandersmissen
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
31
    {
32
        $object = $this->object;
33
        $object->setErrorMessageRequired('');
34
        $this->assertEquals('', $object->getErrorMessageRequired());
35
36
        $message = 'Some example required message';
37
        $object->setErrorMessageRequired($message);
38
        $this->assertEquals($message, $object->getErrorMessageRequired());
39
    }
40
41 View Code Duplication
    public function testSetErrorMessageInvalid()
0 ignored issues
show
Duplication introduced by Wim Vandersmissen
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $object = $this->object;
44
        $object->setErrorMessageInvalid('');
45
        $this->assertEquals('', $object->getErrorMessageInvalid());
46
47
        $message = 'Some example invalid message';
48
        $object->setErrorMessageInvalid($message);
49
        $this->assertEquals($message, $object->getErrorMessageInvalid());
50
    }
51
52
    public function testGetDefaultView()
53
    {
54
        $stringValue = $this->object->getDefaultView();
55
        $this->assertNotNull($stringValue);
56
        $this->assertInternalType('string', $stringValue);
0 ignored issues
show
Deprecated Code introduced by Jeroen Thora
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
57
    }
58
59 View Code Duplication
    public function testAdaptForm()
0 ignored issues
show
Duplication introduced by Wim Vandersmissen
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $object = $this->object;
62
        $object->setRequired(true);
63
64
        $formBuilder = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')
65
            ->disableOriginalConstructor()
66
            ->getMock();
67
68
        $formBuilder->expects($this->any())
69
            ->method('getData')
70
            ->willReturn([]);
71
72
        $fields = new ArrayObject();
73
74
        $object->setErrorMessageRequired('form error!');
75
        $object->setErrorMessageInvalid('not valid');
76
        $this->assertEquals(count($fields), 0);
77
        /* @var FormBuilderInterface $formBuilder */
78
        $object->adaptForm($formBuilder, $fields, 0);
79
        $this->assertTrue(count($fields) > 0);
80
    }
81
82
    public function testGetDefaultAdminType()
83
    {
84
        $this->assertEquals(EmailPagePartAdminType::class, $this->object->getDefaultAdminType());
85
    }
86
87
    public function testRequired()
88
    {
89
        $object = $this->object;
90
91
        $object->setRequired(true);
92
        $this->assertTrue($object->getRequired());
93
    }
94
}
95