Completed
Push — 3.x ( 733455...aa9981 )
by Grégoire
02:00
created

PostTest::testSettersGetters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 9.264
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NewsBundle\Tests\Model;
13
14
use PHPUnit\Framework\TestCase;
15
use Sonata\NewsBundle\Model\Post;
16
17
class ModelTest_Post extends Post
0 ignored issues
show
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
18
{
19
    public function getId()
20
    {
21
    }
22
}
23
24
/**
25
 * Tests the post model.
26
 */
27
class PostTest 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...
28
{
29
    public function testSettersGetters()
30
    {
31
        $date = new \DateTime();
32
33
        $post = new ModelTest_Post();
34
        $post->setAbstract('My abstract content');
35
        $post->setAuthor('My author');
0 ignored issues
show
Documentation introduced by
'My author' is of type string, but the function expects a object<FOS\UserBundle\Model\UserInterface>.

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...
36
        $post->setCollection($this->createMock('Sonata\ClassificationBundle\Model\CollectionInterface'));
37
        $post->setCommentsCloseAt($date);
38
        $post->setCommentsCount(5);
39
        $post->setCommentsDefaultStatus(1);
40
        $post->setCommentsEnabled(true);
41
        $post->setContent('My content');
42
        $post->setContentFormatter('markdown');
43
        $post->setCreatedAt($date);
44
        $post->setEnabled(true);
45
        $post->setPublicationDateStart($date);
46
        $post->setRawContent('My raw content');
47
        $post->setTags($this->createMock('Sonata\ClassificationBundle\Model\TagInterface'));
48
        $post->setTitle('My title');
49
        $post->setSlug('my-post-slug');
50
        $post->setUpdatedAt($date);
51
52
        $this->assertEquals($post->getAbstract(), 'My abstract content');
53
        $this->assertEquals($post->getAuthor(), 'My author');
54
        $this->assertEquals($post->getCollection(), $this->createMock('Sonata\ClassificationBundle\Model\CollectionInterface'));
55
        $this->assertEquals($post->getCommentsCloseAt(), $date);
56
        $this->assertEquals($post->getCommentsCount(), 5);
57
        $this->assertEquals($post->getCommentsDefaultStatus(), 1);
58
        $this->assertEquals($post->getCommentsEnabled(), true);
59
        $this->assertEquals($post->getContent(), 'My content');
60
        $this->assertEquals($post->getContentFormatter(), 'markdown');
61
        $this->assertEquals($post->getCreatedAt(), $date);
62
        $this->assertEquals($post->getEnabled(), true);
63
        $this->assertEquals($post->getPublicationDateStart(), $date);
64
        $this->assertEquals($post->getRawContent(), 'My raw content');
65
        $this->assertEquals($post->getSlug(), 'my-post-slug');
66
        $this->assertEquals($post->getTags(), $this->createMock('Sonata\ClassificationBundle\Model\TagInterface'));
67
        $this->assertEquals($post->getTitle(), 'My title');
68
        $this->assertEquals($post->getUpdatedAt(), $date);
69
    }
70
}
71