Completed
Push — master ( e62fa2...4391c3 )
by Kristof
133:20 queued 117:59
created

Tests/unit/Entity/FormSubmissionTest.php (2 issues)

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
9
/**
10
 * Generated by PHPUnit_SkeletonGenerator on 2012-09-20 at 15:14:43.
11
 */
12
class FormSubmissionTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @var FormSubmission
16
     */
17
    protected $object;
18
19
    /**
20
     * Sets up the fixture, for example, opens a network connection.
21
     * This method is called before a test is executed.
22
     */
23
    protected function setUp()
24
    {
25
        $this->object = new FormSubmission();
26
    }
27
28
    public function testSetGetId()
29
    {
30
        $object = $this->object;
31
        $id = 123;
32
        $object->setId($id);
33
        $this->assertEquals($id, $object->getId());
34
    }
35
36
    public function testSetGetIpAddress()
37
    {
38
        $object = $this->object;
39
        $ip = '127.0.0.1';
40
        $object->setIpAddress($ip);
41
        $this->assertEquals($ip, $object->getIpAddress());
42
    }
43
44
    public function testSetGetNode()
45
    {
46
        $object = $this->object;
47
        $node = new Node();
48
        $node->setId(123);
49
        $object->setNode($node);
50
        $retrievedNode = $object->getNode();
51
        $this->assertEquals($node, $retrievedNode);
52
        $this->assertEquals($node->getId(), $retrievedNode->getId());
53
    }
54
55
    public function testSetGetLang()
56
    {
57
        $object = $this->object;
58
        $lang = 'nl';
59
        $object->setLang($lang);
60
        $this->assertEquals($lang, $object->getLang());
61
    }
62
63
    public function testSetGetCreated()
64
    {
65
        $object = $this->object;
66
        $now = new DateTime();
67
        $object->setCreated($now);
0 ignored issues
show
$now is of type object<DateTime>, but the function expects a object<Kunstmaan\FormBundle\Entity\datetime>.

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...
68
        $this->assertEquals($now, $object->getCreated());
69
    }
70
71
    public function testGetFields()
72
    {
73
        $object = $this->object;
74
        $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...
75
    }
76
77
    public function testToString()
78
    {
79
        $stringValue = $this->object->__toString();
80
        $this->assertNotNull($stringValue);
81
        $this->assertTrue(is_string($stringValue));
82
    }
83
}
84