@@ 93-107 (lines=15) @@ | ||
90 | $this->logger = null; |
|
91 | } |
|
92 | ||
93 | public function testSerializationWithIncludedHost() |
|
94 | { |
|
95 | $this->generateRequestContext(); |
|
96 | ||
97 | $user = (new 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, 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 testPostSerializationEvent() |
|
110 | { |
|
@@ 133-147 (lines=15) @@ | ||
130 | $this->assertEquals('cover.jpg', $user->getCoverName()); |
|
131 | } |
|
132 | ||
133 | public function testSerializationWithIncludedHttpHostAndPort() |
|
134 | { |
|
135 | $this->generateRequestContext(false, true); |
|
136 | ||
137 | $user = (new UserA()) |
|
138 | ->setPhotoName('photo.jpg') |
|
139 | ->setCoverName('cover.jpg'); |
|
140 | ||
141 | $context = DeserializationContext::create(); |
|
142 | $event = new PreSerializeEvent($context, $user, []); |
|
143 | $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, UserA::class, $context->getFormat(), $event); |
|
144 | ||
145 | $this->assertEquals('http://example.com:8000/uploads/photo.jpg', $user->getPhotoName()); |
|
146 | $this->assertEquals('http://example.com:8000/uploads/cover.jpg', $user->getCoverName()); |
|
147 | } |
|
148 | ||
149 | public function testSerializationWithIncludedHttpsHostAndPort() |
|
150 | { |
|
@@ 149-163 (lines=15) @@ | ||
146 | $this->assertEquals('http://example.com:8000/uploads/cover.jpg', $user->getCoverName()); |
|
147 | } |
|
148 | ||
149 | public function testSerializationWithIncludedHttpsHostAndPort() |
|
150 | { |
|
151 | $this->generateRequestContext(true, true); |
|
152 | ||
153 | $user = (new UserA()) |
|
154 | ->setPhotoName('photo.jpg') |
|
155 | ->setCoverName('cover.jpg'); |
|
156 | ||
157 | $context = DeserializationContext::create(); |
|
158 | $event = new PreSerializeEvent($context, $user, []); |
|
159 | $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, UserA::class, $context->getFormat(), $event); |
|
160 | ||
161 | $this->assertEquals('https://example.com:8800/uploads/photo.jpg', $user->getPhotoName()); |
|
162 | $this->assertEquals('https://example.com:8800/uploads/cover.jpg', $user->getCoverName()); |
|
163 | } |
|
164 | ||
165 | public function testSerializationWithoutIncludedHost() |
|
166 | { |
|
@@ 165-179 (lines=15) @@ | ||
162 | $this->assertEquals('https://example.com:8800/uploads/cover.jpg', $user->getCoverName()); |
|
163 | } |
|
164 | ||
165 | public function testSerializationWithoutIncludedHost() |
|
166 | { |
|
167 | $this->generateRequestContext(); |
|
168 | ||
169 | $user = (new UserB()) |
|
170 | ->setPhotoName('photo.jpg') |
|
171 | ->setCoverName('cover.jpg'); |
|
172 | ||
173 | $context = DeserializationContext::create(); |
|
174 | $event = new PreSerializeEvent($context, $user, []); |
|
175 | $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, UserB::class, $context->getFormat(), $event); |
|
176 | ||
177 | $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName()); |
|
178 | $this->assertEquals('/uploads/cover.jpg', $user->getCoverName()); |
|
179 | } |
|
180 | ||
181 | /** |
|
182 | * @expectedException \Fresh\VichUploaderSerializationBundle\Exception\IncompatibleUploadableAndSerializableFieldAnnotationException |
|
@@ 184-198 (lines=15) @@ | ||
181 | /** |
|
182 | * @expectedException \Fresh\VichUploaderSerializationBundle\Exception\IncompatibleUploadableAndSerializableFieldAnnotationException |
|
183 | */ |
|
184 | public function testExceptionForIncompatibleAnnotations() |
|
185 | { |
|
186 | $this->generateRequestContext(); |
|
187 | ||
188 | $user = (new UserC()) |
|
189 | ->setPhotoName('photo.jpg') |
|
190 | ->setCoverName('cover.jpg'); |
|
191 | ||
192 | $context = DeserializationContext::create(); |
|
193 | $event = new PreSerializeEvent($context, $user, []); |
|
194 | $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, UserC::class, $context->getFormat(), $event); |
|
195 | ||
196 | $this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName()); |
|
197 | $this->assertEquals('/uploads/cover.jpg', $user->getCoverName()); |
|
198 | } |
|
199 | ||
200 | public function testSerializationOfTheSameObjectTwice() |
|
201 | { |
|
@@ 260-274 (lines=15) @@ | ||
257 | $this->assertEquals('cover.jpg', $user->getCoverName()); |
|
258 | } |
|
259 | ||
260 | public function testSerializationOfTheProxyObject() |
|
261 | { |
|
262 | $this->generateRequestContext(); |
|
263 | ||
264 | $picture = new UserPicture(); |
|
265 | $picture->setPhotoName('photo.jpg') |
|
266 | ->setCoverName('cover.jpg'); |
|
267 | ||
268 | $context = DeserializationContext::create(); |
|
269 | $event = new PreSerializeEvent($context, $picture, []); |
|
270 | $this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, UserA::class, $context->getFormat(), $event); |
|
271 | ||
272 | $this->assertEquals('http://example.com/uploads/photo.jpg', $picture->getPhotoName()); |
|
273 | $this->assertEquals('http://example.com/uploads/cover.jpg', $picture->getCoverName()); |
|
274 | } |
|
275 | ||
276 | protected function generateRequestContext($https = false, $port = false) |
|
277 | { |