Completed
Push — master ( c5c436...b453a3 )
by Ruud
15:58
created

Tests/unit/Entity/FormSubmissionFieldTest.php (3 issues)

Severity

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
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);
0 ignored issues
show
$form is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Form\Form>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$builder is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...m\FormBuilderInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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