Completed
Push — master ( 96d434...f2324b )
by Daniel
04:52 queued 55s
created

doctrine-orm/tests/Functional/GeneralTest.php (5 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 Psi\Bridge\ContentType\Doctrine\Orm\Tests\Functional;
4
5
use Psi\Component\ContentType\Tests\Functional\Example\Model\Article;
6
use Psi\Component\ContentType\Tests\Functional\Example\Model\Image;
7
use Psi\Component\ContentType\Tests\Functional\Storage\StorageTestTrait;
8
9
class GeneralTest extends OrmTestCase
10
{
11
    use StorageTestTrait;
12
13
    private $entityManager;
14
15
    public function setUp()
16
    {
17
        $container = $this->getContainer([
18
            'mapping' => [
19
                Article::class => [
20
                    'fields' => [
21
                        'title' => [
22
                            'type' => 'text',
23
                            'role' => 'title',
24
                        ],
25
                        'integer' => [
26
                            'type' => 'integer',
27
                        ],
28
                        'image' => [
29
                            'type' => 'image',
30
                            'role' => 'image',
31
                        ],
32
                        'date' => [
33
                            'type' => 'datetime',
34
                        ],
35
                        'referencedImage' => [
36
                            'type' => 'object_reference',
37
                            'shared' => [
38
                                'class' => Image::class,
39
                            ],
40
                        ],
41
                        'paragraphs' => [
42
                            'type' => 'collection',
43
                            'shared' => [
44
                                'field_type' => 'text',
45
                                'field_options' => [],
46
                            ],
47
                        ],
48
                        'numbers' => [
49
                            'type' => 'collection',
50
                            'shared' => [
51
                                'field_type' => 'integer',
52
                            ],
53
                        ],
54
                    ],
55
                ],
56
            ],
57
        ]);
58
        $this->entityManager = $container->get('doctrine.entity_manager');
59
        $this->initOrm($this->entityManager);
60
    }
61
62
    public function testString()
63
    {
64
        $article = new Article();
65
        $article->title = 'Hello';
66
        $article = $this->persistAndReloadArticle($article);
67
        $this->assertEquals('Hello', $article->title);
68
    }
69
70 View Code Duplication
    public function testInteger()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
71
    {
72
        $article = new Article();
73
        $article->integer = 45;
74
        $article = $this->persistAndReloadArticle($article);
75
        $this->assertEquals(45, $article->integer);
76
        $this->assertInternalType('int', $article->integer);
77
    }
78
79 View Code Duplication
    public function testDate()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $article = new Article();
82
        $article->date = new \DateTime('2016-01-01 00:00:00');
83
        $article = $this->persistAndReloadArticle($article);
84
        $this->assertEquals(new \DateTime('2016-01-01 00:00:00'), $article->date);
85
    }
86
87 View Code Duplication
    public function testObject()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        $article = new Article();
90
        $article->image = $this->createImage(
91
            '/path/to/image', 100, 200, 'image/jpeg'
92
        );
93
        $article = $this->persistAndReloadArticle($article);
94
        $this->assertInstanceOf(Image::class, $article->image);
95
        $this->assertEquals(100, $article->image->width);
96
        $this->assertEquals('image/jpeg', $article->image->mimetype);
97
    }
98
99
    public function testReference()
100
    {
101
        $image = $this->createImage('/path/to/image1', 100, 200, 'image/jpeg');
102
        $image->id = '/test/image';
103
        $article = new Article();
104
        $article->id = '/test/article';
105
        $article->title = 'Foo';
106
        $article->date = new \DateTime();
107
        $article->referencedImage = $image;
108
109
        $article = $this->persistAndReloadArticle($article);
110
111
        $image = $article->referencedImage;
112
        $this->assertInstanceOf(Image::class, $image);
113
    }
114
115 View Code Duplication
    public function testScalarCollection()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $article = new Article();
118
        $article->id = '/test/article';
119
        $article->paragraphs = ['one', 'two', 'three'];
120
        $article = $this->persistAndReloadArticle($article);
121
122
        $this->assertSame(['one', 'two', 'three'], $article->paragraphs);
123
    }
124
125 View Code Duplication
    private function persistAndReloadArticle(Article $article)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
    {
127
        $article->id = 'article';
128
        $this->entityManager->persist($article);
129
        $this->entityManager->flush();
130
131
        $this->entityManager->clear();
132
133
        return $this->entityManager->find(Article::class, 'article');
134
    }
135
}
136