Completed
Push — master ( e1f0fb...216f84 )
by Sander
199:09 queued 186:30
created

Tests/unit/Entity/FormSubmissionFieldTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\FormBundle\Tests\Entity;
4
5
use Kunstmaan\FormBundle\Entity\FormSubmission;
6
use Kunstmaan\FormBundle\Entity\FormSubmissionField;
7
use Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\StringFormSubmissionField;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\DependencyInjection\Container;
10
use Symfony\Component\Form\Form;
11
use Symfony\Component\Form\FormBuilder;
12
use Symfony\Component\HttpFoundation\Request;
13
14
class Plain extends FormSubmissionField
15
{
16
}
17
18
class FormSubmissionFieldTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
19
{
20
    /**
21
     * @var StringFormSubmissionField
22
     */
23
    protected $object;
24
25
    /**
26
     * Sets up the fixture, for example, opens a network connection.
27
     * This method is called before a test is executed.
28
     */
29
    protected function setUp()
30
    {
31
        $this->object = new StringFormSubmissionField();
32
    }
33
34
    public function testSetGetId()
35
    {
36
        $object = $this->object;
37
        $id = 123;
38
        $object->setId($id);
39
        $this->assertEquals($id, $object->getId());
40
    }
41
42
    public function testSetGetFieldName()
43
    {
44
        $object = $this->object;
45
        $fieldName = 'someFieldName';
46
        $object->setFieldName($fieldName);
47
        $this->assertEquals($fieldName, $object->getFieldName());
48
    }
49
50
    public function testSetGetLabel()
51
    {
52
        $object = $this->object;
53
        $label = 'Some label';
54
        $object->setLabel($label);
55
        $this->assertEquals($label, $object->getLabel());
56
    }
57
58
    public function testSetGetSequence()
59
    {
60
        $object = $this->object;
61
        $label = 'Some label';
62
        $object->setSequence($label);
63
        $this->assertEquals($label, $object->getSequence());
64
    }
65
66
    public function testOnValidPost()
67
    {
68
        $object = $this->object;
69
        $form = $this->getMockBuilder(Form::class)
70
            ->disableOriginalConstructor()
71
            ->getMock();
72
73
        $builder = $this->getMockBuilder(FormBuilder::class)
74
            ->disableOriginalConstructor()
75
            ->getMock();
76
77
        $request = new Request();
78
79
        $container = $this->getMockBuilder(Container::class)
80
            ->disableOriginalConstructor()
81
            ->getMock();
82
83
        $container->expects($this->any())
84
            ->method('getParameter')
85
            ->will($this->returnValue('whatever'));
86
87
        $object->onValidPost($form, $builder, $request, $container);
88
    }
89
90
    public function testSetGetSubmission()
91
    {
92
        $object = $this->object;
93
        $submission = new FormSubmission();
94
        $submission->setId(123);
95
        $object->setSubmission($submission);
96
        $retrievedSubmission = $object->getSubmission();
97
        $this->assertEquals($submission, $retrievedSubmission);
98
        $this->assertEquals($submission->getId(), $retrievedSubmission->getId());
99
    }
100
101
    public function testToString()
102
    {
103
        $plainObject = new Plain();
104
        $stringValue = $plainObject->__toString();
105
        $this->assertEquals('FormSubmission Field', $stringValue);
106
    }
107
}
108