|
@@ 99-113 (lines=15) @@
|
| 96 |
|
/** |
| 97 |
|
* Test serialization with included host in the URI |
| 98 |
|
*/ |
| 99 |
|
public function testSerializationWithIncludedHost() |
| 100 |
|
{ |
| 101 |
|
$this->generateRequestContext(); |
| 102 |
|
|
| 103 |
|
$user = (new Fixtures\UserA()) |
| 104 |
|
->setPhotoName('photo.jpg') |
| 105 |
|
->setCoverName('cover.jpg'); |
| 106 |
|
|
| 107 |
|
$context = DeserializationContext::create(); |
| 108 |
|
$event = new ObjectEvent($context, $user, []); |
| 109 |
|
$this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event); |
| 110 |
|
|
| 111 |
|
$this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName()); |
| 112 |
|
$this->assertEquals('http://example.com/uploads/cover.jpg', $user->getCoverName()); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
/** |
| 116 |
|
* Test serialization with included http host and port in the URI |
|
@@ 118-132 (lines=15) @@
|
| 115 |
|
/** |
| 116 |
|
* Test serialization with included http host and port in the URI |
| 117 |
|
*/ |
| 118 |
|
public function testSerializationWithIncludedHttpHostAndPort() |
| 119 |
|
{ |
| 120 |
|
$this->generateRequestContext(false, true); |
| 121 |
|
|
| 122 |
|
$user = (new Fixtures\UserA()) |
| 123 |
|
->setPhotoName('photo.jpg') |
| 124 |
|
->setCoverName('cover.jpg'); |
| 125 |
|
|
| 126 |
|
$context = DeserializationContext::create(); |
| 127 |
|
$event = new ObjectEvent($context, $user, []); |
| 128 |
|
$this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event); |
| 129 |
|
|
| 130 |
|
$this->assertEquals('http://example.com:8000/uploads/photo.jpg', $user->getPhotoName()); |
| 131 |
|
$this->assertEquals('http://example.com:8000/uploads/cover.jpg', $user->getCoverName()); |
| 132 |
|
} |
| 133 |
|
|
| 134 |
|
/** |
| 135 |
|
* Test serialization with included https host and port in the URI |
|
@@ 137-151 (lines=15) @@
|
| 134 |
|
/** |
| 135 |
|
* Test serialization with included https host and port in the URI |
| 136 |
|
*/ |
| 137 |
|
public function testSerializationWithIncludedHttpsHostAndPort() |
| 138 |
|
{ |
| 139 |
|
$this->generateRequestContext(true, true); |
| 140 |
|
|
| 141 |
|
$user = (new Fixtures\UserA()) |
| 142 |
|
->setPhotoName('photo.jpg') |
| 143 |
|
->setCoverName('cover.jpg'); |
| 144 |
|
|
| 145 |
|
$context = DeserializationContext::create(); |
| 146 |
|
$event = new ObjectEvent($context, $user, []); |
| 147 |
|
$this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserA::class, $context->getFormat(), $event); |
| 148 |
|
|
| 149 |
|
$this->assertEquals('https://example.com:8800/uploads/photo.jpg', $user->getPhotoName()); |
| 150 |
|
$this->assertEquals('https://example.com:8800/uploads/cover.jpg', $user->getCoverName()); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
/** |
| 154 |
|
* Test serialization without included host in the URI |
|
@@ 156-170 (lines=15) @@
|
| 153 |
|
/** |
| 154 |
|
* Test serialization without included host in the URI |
| 155 |
|
*/ |
| 156 |
|
public function testSerializationWithoutIncludedHost() |
| 157 |
|
{ |
| 158 |
|
$this->generateRequestContext(); |
| 159 |
|
|
| 160 |
|
$user = (new Fixtures\UserB()) |
| 161 |
|
->setPhotoName('photo.jpg') |
| 162 |
|
->setCoverName('cover.jpg'); |
| 163 |
|
|
| 164 |
|
$context = DeserializationContext::create(); |
| 165 |
|
$event = new ObjectEvent($context, $user, []); |
| 166 |
|
$this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserB::class, $context->getFormat(), $event); |
| 167 |
|
|
| 168 |
|
$this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName()); |
| 169 |
|
$this->assertEquals('/uploads/cover.jpg', $user->getCoverName()); |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
/** |
| 173 |
|
* Test serialization without included host in the URI |
|
@@ 177-191 (lines=15) @@
|
| 174 |
|
* |
| 175 |
|
* @expectedException \Fresh\VichUploaderSerializationBundle\Exception\IncompatibleUploadableAndSerializableFieldAnnotationException |
| 176 |
|
*/ |
| 177 |
|
public function testExceptionForIncompatibleAnnotations() |
| 178 |
|
{ |
| 179 |
|
$this->generateRequestContext(); |
| 180 |
|
|
| 181 |
|
$user = (new Fixtures\UserC()) |
| 182 |
|
->setPhotoName('photo.jpg') |
| 183 |
|
->setCoverName('cover.jpg'); |
| 184 |
|
|
| 185 |
|
$context = DeserializationContext::create(); |
| 186 |
|
$event = new ObjectEvent($context, $user, []); |
| 187 |
|
$this->dispatcher->dispatch(JmsEvents::PRE_SERIALIZE, Fixtures\UserC::class, $context->getFormat(), $event); |
| 188 |
|
|
| 189 |
|
$this->assertEquals('http://example.com/uploads/photo.jpg', $user->getPhotoName()); |
| 190 |
|
$this->assertEquals('/uploads/cover.jpg', $user->getCoverName()); |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
/** |
| 194 |
|
* Test serialization of the same object twice |