Code Duplication    Length = 15-15 lines in 5 locations

Tests/EventListener/JmsPreSerializeListenerTest.php 5 locations

@@ 146-160 (lines=15) @@
143
    /**
144
     * Test serialization with included host in the URI
145
     */
146
    public function testSerializationWithIncludedHost()
147
    {
148
        $this->generateRequestContext();
149
150
        $user = (new Fixtures\UserA())
151
            ->setPhotoName('photo.jpg')
152
            ->setCoverName('cover.jpg');
153
154
        $context = DeserializationContext::create();
155
        $event = new ObjectEvent($context, $user, []);
156
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
157
158
        $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName());
159
        $this->assertEquals('http://example.com/uploads/cover.jpg', $user->getCoverName());
160
    }
161
162
    /**
163
     * Test serialization with included http host and port in the URI
@@ 165-179 (lines=15) @@
162
    /**
163
     * Test serialization with included http host and port in the URI
164
     */
165
    public function testSerializationWithIncludedHttpHostAndPort()
166
    {
167
        $this->generateRequestContext(false,true);
168
169
        $user = (new Fixtures\UserA())
170
            ->setPhotoName('photo.jpg')
171
            ->setCoverName('cover.jpg');
172
173
        $context = DeserializationContext::create();
174
        $event = new ObjectEvent($context, $user, []);
175
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
176
177
        $this->assertEquals('http://example.com:8000/uploads/photo.jpg', $user->getPhotoName());
178
        $this->assertEquals('http://example.com:8000/uploads/cover.jpg', $user->getCoverName());
179
    }
180
181
    /**
182
     * Test serialization with included https host and port in the URI
@@ 184-198 (lines=15) @@
181
    /**
182
     * Test serialization with included https host and port in the URI
183
     */
184
    public function testSerializationWithIncludedHttpsHostAndPort()
185
    {
186
        $this->generateRequestContext(true,true);
187
188
        $user = (new Fixtures\UserA())
189
            ->setPhotoName('photo.jpg')
190
            ->setCoverName('cover.jpg');
191
192
        $context = DeserializationContext::create();
193
        $event = new ObjectEvent($context, $user, []);
194
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event);
195
196
        $this->assertEquals('https://example.com:8800/uploads/photo.jpg', $user->getPhotoName());
197
        $this->assertEquals('https://example.com:8800/uploads/cover.jpg', $user->getCoverName());
198
    }
199
200
    /**
201
     * Test serialization without included host in the URI
@@ 203-217 (lines=15) @@
200
    /**
201
     * Test serialization without included host in the URI
202
     */
203
    public function testSerializationWithoutIncludedHost()
204
    {
205
        $this->generateRequestContext();
206
207
        $user = (new Fixtures\UserB())
208
            ->setPhotoName('photo.jpg')
209
            ->setCoverName('cover.jpg');
210
211
        $context = DeserializationContext::create();
212
        $event = new ObjectEvent($context, $user, []);
213
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserB::class, $context->getFormat(), $event);
214
215
        $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName());
216
        $this->assertEquals('/uploads/cover.jpg', $user->getCoverName());
217
    }
218
219
    /**
220
     * Test serialization without included host in the URI
@@ 224-238 (lines=15) @@
221
     *
222
     * @expectedException \Fresh\VichUploaderSerializationBundle\Exception\IncompatibleUploadableAndSerializableFieldAnnotationException
223
     */
224
    public function testExceptionForIncompatibleAnnotations()
225
    {
226
        $this->generateRequestContext();
227
228
        $user = (new Fixtures\UserC())
229
            ->setPhotoName('photo.jpg')
230
            ->setCoverName('cover.jpg');
231
232
        $context = DeserializationContext::create();
233
        $event = new ObjectEvent($context, $user, []);
234
        $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserC::class, $context->getFormat(), $event);
235
236
        $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName());
237
        $this->assertEquals('/uploads/cover.jpg', $user->getCoverName());
238
    }
239
240
    /**
241
     * Test serialization of the same object twice