|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Sonata Project package. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Sonata\NewsBundle\Tests\Model; |
|
15
|
|
|
|
|
16
|
|
|
use PHPUnit\Framework\TestCase; |
|
17
|
|
|
use Sonata\ClassificationBundle\Model\CollectionInterface; |
|
18
|
|
|
use Sonata\ClassificationBundle\Model\TagInterface; |
|
19
|
|
|
use Sonata\NewsBundle\Model\Post; |
|
20
|
|
|
|
|
21
|
|
|
class ModelTest_Post extends Post |
|
22
|
|
|
{ |
|
23
|
|
|
public function getId(): void |
|
24
|
|
|
{ |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
class PostTest extends TestCase |
|
29
|
|
|
{ |
|
30
|
|
|
public function testSettersGetters(): void |
|
31
|
|
|
{ |
|
32
|
|
|
$date = new \DateTime(); |
|
33
|
|
|
|
|
34
|
|
|
$post = new ModelTest_Post(); |
|
35
|
|
|
$post->setAbstract('My abstract content'); |
|
36
|
|
|
$post->setAuthor('My author'); |
|
|
|
|
|
|
37
|
|
|
$post->setCollection($collection = $this->createMock(CollectionInterface::class)); |
|
38
|
|
|
$post->setCommentsCloseAt($date); |
|
39
|
|
|
$post->setCommentsCount(5); |
|
40
|
|
|
$post->setCommentsDefaultStatus(1); |
|
41
|
|
|
$post->setCommentsEnabled(true); |
|
42
|
|
|
$post->setContent('My content'); |
|
43
|
|
|
$post->setContentFormatter('markdown'); |
|
44
|
|
|
$post->setCreatedAt($date); |
|
45
|
|
|
$post->setEnabled(true); |
|
46
|
|
|
$post->setPublicationDateStart($date); |
|
47
|
|
|
$post->setRawContent('My raw content'); |
|
48
|
|
|
$post->setTags($tags = [$this->createMock(TagInterface::class)]); |
|
49
|
|
|
$post->setTitle('My title'); |
|
50
|
|
|
$post->setSlug('my-post-slug'); |
|
51
|
|
|
$post->setUpdatedAt($date); |
|
52
|
|
|
|
|
53
|
|
|
$this->assertSame('My abstract content', $post->getAbstract()); |
|
54
|
|
|
$this->assertSame('My author', $post->getAuthor()); |
|
55
|
|
|
$this->assertSame($collection, $post->getCollection()); |
|
56
|
|
|
$this->assertInstanceOf(CollectionInterface::class, $post->getCollection()); |
|
57
|
|
|
$this->assertSame($date, $post->getCommentsCloseAt()); |
|
58
|
|
|
$this->assertSame(5, $post->getCommentsCount()); |
|
59
|
|
|
$this->assertSame(1, $post->getCommentsDefaultStatus()); |
|
60
|
|
|
$this->assertTrue($post->getCommentsEnabled()); |
|
61
|
|
|
$this->assertSame('My content', $post->getContent()); |
|
62
|
|
|
$this->assertSame('markdown', $post->getContentFormatter()); |
|
63
|
|
|
$this->assertSame($date, $post->getCreatedAt()); |
|
64
|
|
|
$this->assertTrue($post->getEnabled()); |
|
65
|
|
|
$this->assertSame($date, $post->getPublicationDateStart()); |
|
66
|
|
|
$this->assertSame('My raw content', $post->getRawContent()); |
|
67
|
|
|
$this->assertSame('my-post-slug', $post->getSlug()); |
|
68
|
|
|
$this->assertSame($tags, $post->getTags()); |
|
69
|
|
|
$this->assertSame('My title', $post->getTitle()); |
|
70
|
|
|
$this->assertSame($date, $post->getUpdatedAt()); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
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: