Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Tests/unit/Entity/FormSubmissionTest.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 DateTime;
6
use Kunstmaan\FormBundle\Entity\FormSubmission;
7
use Kunstmaan\NodeBundle\Entity\Node;
8
use PHPUnit\Framework\TestCase;
9
10
class FormSubmissionTest extends TestCase
11
{
12
    /**
13
     * @var FormSubmission
14
     */
15
    protected $object;
16
17
    /**
18
     * Sets up the fixture, for example, opens a network connection.
19
     * This method is called before a test is executed.
20
     */
21
    protected function setUp()
22
    {
23
        $this->object = new FormSubmission();
24
    }
25
26
    public function testSetGetId()
27
    {
28
        $object = $this->object;
29
        $id = 123;
30
        $object->setId($id);
31
        $this->assertEquals($id, $object->getId());
32
    }
33
34
    public function testSetGetIpAddress()
35
    {
36
        $object = $this->object;
37
        $ip = '127.0.0.1';
38
        $object->setIpAddress($ip);
39
        $this->assertEquals($ip, $object->getIpAddress());
40
    }
41
42
    public function testSetGetNode()
43
    {
44
        $object = $this->object;
45
        $node = new Node();
46
        $node->setId(123);
47
        $object->setNode($node);
48
        $retrievedNode = $object->getNode();
49
        $this->assertEquals($node, $retrievedNode);
50
        $this->assertEquals($node->getId(), $retrievedNode->getId());
51
    }
52
53
    public function testSetGetLang()
54
    {
55
        $object = $this->object;
56
        $lang = 'nl';
57
        $object->setLang($lang);
58
        $this->assertEquals($lang, $object->getLang());
59
    }
60
61
    public function testSetGetCreated()
62
    {
63
        $object = $this->object;
64
        $now = new DateTime();
65
        $object->setCreated($now);
66
        $this->assertEquals($now, $object->getCreated());
67
    }
68
69
    public function testGetFields()
70
    {
71
        $object = $this->object;
72
        $object->getFields();
0 ignored issues
show
The call to the method Kunstmaan\FormBundle\Ent...Submission::getFields() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
73
    }
74
75
    public function testToString()
76
    {
77
        $stringValue = $this->object->__toString();
78
        $this->assertNotNull($stringValue);
79
        $this->assertTrue(is_string($stringValue));
80
    }
81
}
82