|
66 | 66 | use Zolex\VOM\Test\Fixtures\PrivateDenormalizer; |
67 | 67 | use Zolex\VOM\Test\Fixtures\PrivateNormalizer; |
68 | 68 | use Zolex\VOM\Test\Fixtures\PropertyPromotion; |
| 69 | +use Zolex\VOM\Test\Fixtures\RegexpExtractorModel; |
| 70 | +use Zolex\VOM\Test\Fixtures\RegexpExtractorProperty; |
69 | 71 | use Zolex\VOM\Test\Fixtures\SerializedObject; |
70 | 72 | use Zolex\VOM\Test\Fixtures\SerializedObjectArray; |
71 | 73 | use Zolex\VOM\Test\Fixtures\SerializedObjectWithAdditionalNormalizer; |
@@ -1362,4 +1364,47 @@ public function testSerializedObjectWithAdditionalNormalizerThrowsException(): v |
1362 | 1364 | $this->expectExceptionMessage('The "__toString()" method on model "Zolex\VOM\Test\Fixtures\SerializedObjectWithAdditionalNormalizer" is configured as a normalizer. There must be no additional normalizer methods.'); |
1363 | 1365 | self::$serializer->denormalize([], SerializedObjectWithAdditionalNormalizer::class); |
1364 | 1366 | } |
| 1367 | + |
| 1368 | + public function testRegexpExtractorModel(): void |
| 1369 | + { |
| 1370 | + $data = 'image1.jpg,tag:foobar,visibility:hidden'; |
| 1371 | + $model = self::$serializer->denormalize($data, RegexpExtractorModel::class); |
| 1372 | + |
| 1373 | + $this->assertInstanceOf(RegexpExtractorModel::class, $model); |
| 1374 | + $this->assertEquals('image1.jpg', $model->filename); |
| 1375 | + $this->assertEquals('foobar', $model->tag); |
| 1376 | + $this->assertFalse($model->isVisible); |
| 1377 | + |
| 1378 | + $normalized = self::$serializer->normalize($model); |
| 1379 | + $this->assertEquals($data, $normalized); |
| 1380 | + } |
| 1381 | + |
| 1382 | + public function testRegexpExtractorProperty(): void |
| 1383 | + { |
| 1384 | + $data = 'image2.jpg,tag:foobar,visibility:visible'; |
| 1385 | + $model = self::$serializer->denormalize($data, RegexpExtractorProperty::class); |
| 1386 | + |
| 1387 | + $this->assertInstanceOf(RegexpExtractorProperty::class, $model); |
| 1388 | + $this->assertEquals('image2.jpg', $model->filename); |
| 1389 | + $this->assertEquals('foobar', $model->tag); |
| 1390 | + $this->assertTrue($model->isVisible); |
| 1391 | + |
| 1392 | + $normalized = self::$serializer->normalize($model); |
| 1393 | + $this->assertEquals($data, $normalized); |
| 1394 | + } |
| 1395 | + |
| 1396 | + public function testRegexpExtractorPropertyThrowsExceptionWhenNotMatching(): void |
| 1397 | + { |
| 1398 | + $this->expectException(MappingException::class); |
| 1399 | + $this->expectExceptionMessage('Extractor "/tag:([^,]+)/" on "Zolex\VOM\Test\Fixtures\RegexpExtractorProperty::$tag" does not match the data "WRONGDATA"'); |
| 1400 | + |
| 1401 | + self::$serializer->denormalize('WRONGDATA', RegexpExtractorProperty::class); |
| 1402 | + } |
| 1403 | + |
| 1404 | + public function testRegexpExtractorModelThrowsExceptionWhenNotMatching(): void |
| 1405 | + { |
| 1406 | + $this->expectException(MappingException::class); |
| 1407 | + $this->expectExceptionMessage('Extractor "/^(?<filename>.+),tag:(?<tag>.*),visibility:(?<isVisible>visible|hidden)/" on model "Zolex\VOM\Test\Fixtures\RegexpExtractorModel" does not match the data "WRONGDATA"'); |
| 1408 | + self::$serializer->denormalize('WRONGDATA', RegexpExtractorModel::class); |
| 1409 | + } |
1365 | 1410 | } |
0 commit comments