Completed
Push — master ( fcb59d...326ddf )
by Ruud
299:19 queued 288:03
created

testGettersAndSetters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\FormBundle\Tests\Entity\FormSubmissionFieldTypes;
4
5
use Kunstmaan\FormBundle\Entity\FormSubmissionFieldTypes\FileFormSubmissionField;
6
use Kunstmaan\FormBundle\Form\FileFormSubmissionType;
7
use PHPUnit\Framework\TestCase;
8
use Symfony\Component\DependencyInjection\Container;
9
use Symfony\Component\Form\Form;
10
use Symfony\Component\Form\FormBuilder;
11
use Symfony\Component\HttpFoundation\File\UploadedFile;
12
use Symfony\Component\HttpFoundation\Request;
13
14
/**
15
 * Tests for FileFormSubmissionField
16
 */
17
class FileFormSubmissionFieldTest extends TestCase
18
{
19
    /**
20
     * @var FileFormSubmissionField
21
     */
22
    protected $object;
23
24
    /**
25
     * Sets up the fixture, for example, opens a network connection.
26
     * This method is called before a test is executed.
27
     */
28
    protected function setUp()
29
    {
30
        $this->object = new FileFormSubmissionField();
31
    }
32
33
    public function testToString()
34
    {
35
        $stringValue = $this->object->__toString();
36
        $this->assertNotNull($stringValue);
37
        $this->assertInternalType('string', $stringValue);
0 ignored issues
show
Deprecated Code introduced by
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...
38
    }
39
40
    public function testIsNull()
41
    {
42
        $file = new UploadedFile(__DIR__ . '/../../Resources/assets/example.jpg', 'example.jpg');
43
44
        $object = $this->object;
45
        $this->assertTrue($object->isNull());
46
        $object->file = $file;
47
        $this->assertFalse($object->isNull());
48
    }
49
50
    public function testGetSafeFileName()
51
    {
52
        $file = new UploadedFile(__DIR__ . '/../../Resources/assets/example.jpg', 'the file name $@&.jpg');
53
54
        $object = $this->object;
55
        $object->file = $file;
56
        $safeName = $object->getSafeFileName();
57
58
        $this->assertEquals('the-file-name.jpeg', $safeName);
59
    }
60
61
    public function testGettersAndSetters()
62
    {
63
        $object = $this->object;
64
        $fileName = 'test.jpg';
65
        $object->setFileName($fileName);
66
        $object->setUrl('https://nasa.gov');
67
        $object->setUuid('123');
68
69
        $this->assertEquals($fileName, $object->getFileName());
70
        $this->assertEquals('https://nasa.gov', $object->getUrl());
71
        $this->assertEquals('123', $object->getUuid());
72
        $this->assertEquals(FileFormSubmissionType::class, $object->getDefaultAdminType());
73
    }
74
75
    public function testGetSubmissionTemplate()
76
    {
77
        $template = $this->object->getSubmissionTemplate();
78
        $this->assertNotNull($template);
79
    }
80
81
    public function testUpload()
82
    {
83
        $object = $this->object;
84
        $this->assertNull($object->upload('..', '..'));
85
86
        $file = $this->getMockBuilder(UploadedFile::class)
87
            ->disableOriginalConstructor()
88
            ->getMock();
89
90
        $file->expects($this->any())
91
            ->method('move')
92
            ->willReturn(true);
93
94
        $object->file = $file;
0 ignored issues
show
Documentation Bug introduced by
It seems like $file of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Symfony\Component...tion\File\UploadedFile> of property $file.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
95
        $object->upload(__DIR__ . '/../../Resources/assets/', __DIR__ . '/../../Resources/assets/');
96
97
        $form = $this->getMockBuilder(Form::class)
98
            ->disableOriginalConstructor()
99
            ->getMock();
100
101
        $builder = $this->getMockBuilder(FormBuilder::class)
102
            ->disableOriginalConstructor()
103
            ->getMock();
104
105
        $request = new Request();
106
107
        $container = $this->getMockBuilder(Container::class)
108
            ->disableOriginalConstructor()
109
            ->getMock();
110
111
        $container->expects($this->any())
112
            ->method('getParameter')
113
            ->willReturn('whatever');
114
115
        $object->onValidPost($form, $builder, $request, $container);
0 ignored issues
show
Documentation introduced by
$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...
Documentation introduced by
$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...
Documentation introduced by
$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...
116
    }
117
}
118