Code Duplication    Length = 15-15 lines in 6 locations

Tests/EventListener/JmsSerializerSubscriberTest.php 6 locations

@@ 93-107 (lines=15) @@
90
        $this->logger = null;
91
    }
92
93
    public function testSerializationWithIncludedHost()
94
    {
95
        $this->generateRequestContext();
96
97
        $user = (new Fixtures\UserA())
98
            ->setPhotoName('photo.jpg')
99
            ->setCoverName('cover.jpg');
100
101
        $context = DeserializationContext::create();
102
        $event = new PreSerializeEvent($context, $user, []);
103
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
104
105
        $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName());
106
        $this->assertEquals('http://example.com/uploads/cover.jpg', $user->getCoverName());
107
    }
108
109
    public function testSerializationWithIncludedHttpHostAndPort()
110
    {
@@ 109-123 (lines=15) @@
106
        $this->assertEquals('http://example.com/uploads/cover.jpg', $user->getCoverName());
107
    }
108
109
    public function testSerializationWithIncludedHttpHostAndPort()
110
    {
111
        $this->generateRequestContext(false, true);
112
113
        $user = (new Fixtures\UserA())
114
            ->setPhotoName('photo.jpg')
115
            ->setCoverName('cover.jpg');
116
117
        $context = DeserializationContext::create();
118
        $event = new PreSerializeEvent($context, $user, []);
119
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
120
121
        $this->assertEquals('http://example.com:8000/uploads/photo.jpg', $user->getPhotoName());
122
        $this->assertEquals('http://example.com:8000/uploads/cover.jpg', $user->getCoverName());
123
    }
124
125
    public function testSerializationWithIncludedHttpsHostAndPort()
126
    {
@@ 125-139 (lines=15) @@
122
        $this->assertEquals('http://example.com:8000/uploads/cover.jpg', $user->getCoverName());
123
    }
124
125
    public function testSerializationWithIncludedHttpsHostAndPort()
126
    {
127
        $this->generateRequestContext(true, true);
128
129
        $user = (new Fixtures\UserA())
130
            ->setPhotoName('photo.jpg')
131
            ->setCoverName('cover.jpg');
132
133
        $context = DeserializationContext::create();
134
        $event = new PreSerializeEvent($context, $user, []);
135
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
136
137
        $this->assertEquals('https://example.com:8800/uploads/photo.jpg', $user->getPhotoName());
138
        $this->assertEquals('https://example.com:8800/uploads/cover.jpg', $user->getCoverName());
139
    }
140
141
    public function testSerializationWithoutIncludedHost()
142
    {
@@ 141-155 (lines=15) @@
138
        $this->assertEquals('https://example.com:8800/uploads/cover.jpg', $user->getCoverName());
139
    }
140
141
    public function testSerializationWithoutIncludedHost()
142
    {
143
        $this->generateRequestContext();
144
145
        $user = (new Fixtures\UserB())
146
            ->setPhotoName('photo.jpg')
147
            ->setCoverName('cover.jpg');
148
149
        $context = DeserializationContext::create();
150
        $event = new PreSerializeEvent($context, $user, []);
151
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserB::class, $context->getFormat(), $event);
152
153
        $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName());
154
        $this->assertEquals('/uploads/cover.jpg', $user->getCoverName());
155
    }
156
157
    /**
158
     * @expectedException \Fresh\VichUploaderSerializationBundle\Exception\IncompatibleUploadableAndSerializableFieldAnnotationException
@@ 160-174 (lines=15) @@
157
    /**
158
     * @expectedException \Fresh\VichUploaderSerializationBundle\Exception\IncompatibleUploadableAndSerializableFieldAnnotationException
159
     */
160
    public function testExceptionForIncompatibleAnnotations()
161
    {
162
        $this->generateRequestContext();
163
164
        $user = (new Fixtures\UserC())
165
            ->setPhotoName('photo.jpg')
166
            ->setCoverName('cover.jpg');
167
168
        $context = DeserializationContext::create();
169
        $event = new PreSerializeEvent($context, $user, []);
170
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserC::class, $context->getFormat(), $event);
171
172
        $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName());
173
        $this->assertEquals('/uploads/cover.jpg', $user->getCoverName());
174
    }
175
176
    public function testSerializationOfTheSameObjectTwice()
177
    {
@@ 198-212 (lines=15) @@
195
        $this->assertEquals('http://example.com/uploads/cover.jpg', $user->getCoverName());
196
    }
197
198
    public function testSerializationOfTheProxyObject()
199
    {
200
        $this->generateRequestContext();
201
202
        $picture = new Fixtures\UserPicture();
203
        $picture->setPhotoName('photo.jpg')
204
                ->setCoverName('cover.jpg');
205
206
        $context = DeserializationContext::create();
207
        $event   = new PreSerializeEvent($context, $picture, []);
208
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
209
210
        $this->assertEquals('http://example.com/uploads/photo.jpg', $picture->getPhotoName());
211
        $this->assertEquals('http://example.com/uploads/cover.jpg', $picture->getCoverName());
212
    }
213
214
    protected function generateRequestContext($https = false, $port = false)
215
    {