Skip to content

Commit 1966dc3

Browse files
committed
Refactor more test to use the new system
1 parent 5a0b2c1 commit 1966dc3

File tree

10 files changed

+71
-103
lines changed

10 files changed

+71
-103
lines changed

tests/AutoMapperTest.php

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
use Symfony\Component\EventDispatcher\EventDispatcher;
4747
use Symfony\Component\Finder\Finder;
4848
use Symfony\Component\HttpKernel\Kernel;
49-
use Symfony\Component\Serializer\Mapping\ClassDiscriminatorFromClassMetadata;
5049
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
5150
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
5251
use Symfony\Component\VarDumper\Dumper\CliDumper;
@@ -1217,50 +1216,6 @@ public function testRealClassName(): void
12171216
self::assertEquals('Mapper_AutoMapper_Tests_Fixtures_Proxy_array', $mapper::class);
12181217
}
12191218

1220-
public function testDiscriminatorMapAndInterface3(): void
1221-
{
1222-
if (!class_exists(ClassDiscriminatorFromClassMetadata::class)) {
1223-
self::markTestSkipped('Symfony Serializer is required to run this test.');
1224-
}
1225-
1226-
$autoMapper = AutoMapperBuilder::buildAutoMapper(mapPrivatePropertiesAndMethod: true);
1227-
1228-
$typeA = new Fixtures\DiscriminatorMapAndInterface\TypeA('my name');
1229-
$something = new Fixtures\DiscriminatorMapAndInterface\Something($typeA);
1230-
1231-
$mapped = $autoMapper->map($something, 'array');
1232-
1233-
$expected = [
1234-
'myInterface' => [
1235-
'name' => 'my name',
1236-
'type' => 'type_a',
1237-
],
1238-
];
1239-
self::assertSame($expected, $mapped);
1240-
}
1241-
1242-
public function testDiscriminatorMapAndInterface2(): void
1243-
{
1244-
if (!class_exists(ClassDiscriminatorFromClassMetadata::class)) {
1245-
self::markTestSkipped('Symfony Serializer is required to run this test.');
1246-
}
1247-
1248-
$autoMapper = AutoMapperBuilder::buildAutoMapper(mapPrivatePropertiesAndMethod: true);
1249-
1250-
$something = [
1251-
'myInterface' => [
1252-
'type' => 'type_a',
1253-
'name' => 'my name',
1254-
],
1255-
];
1256-
1257-
$mapped = $autoMapper->map($something, Fixtures\DiscriminatorMapAndInterface\Something::class);
1258-
1259-
self::assertInstanceOf(Fixtures\DiscriminatorMapAndInterface\Something::class, $mapped);
1260-
self::assertInstanceOf(Fixtures\DiscriminatorMapAndInterface\TypeA::class, $mapped->myInterface);
1261-
self::assertSame('my name', $mapped->myInterface->name);
1262-
}
1263-
12641219
public function testDiscriminantToArray(): void
12651220
{
12661221
$this->autoMapper = AutoMapperBuilder::buildAutoMapper(mapPrivatePropertiesAndMethod: true);
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
AutoMapper\Tests\AutoMapperTest\ConstructorWithSerializedName\Bar {
22
+isStatic: true
3-
}
4-
3+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[
22
"is_static" => true
3-
]
3+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
"myInterface" => [
3+
"name" => "my name"
4+
"type" => "type_a"
5+
]
6+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
AutoMapper\Tests\AutoMapperTest\DiscriminatorMapAndInterface\Something {
2+
+myInterface: AutoMapper\Tests\AutoMapperTest\DiscriminatorMapAndInterface\TypeA {
3+
+name: "my name"
4+
}
5+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace AutoMapper\Tests\AutoMapperTest\DiscriminatorMapAndInterface;
6+
7+
use AutoMapper\Tests\AutoMapperBuilder;
8+
use Symfony\Component\Serializer\Attribute\DiscriminatorMap;
9+
10+
#[DiscriminatorMap(typeProperty: 'type', mapping: [
11+
'type_a' => TypeA::class,
12+
'type_b' => TypeB::class,
13+
]
14+
)]
15+
interface MyInterface
16+
{
17+
}
18+
19+
class Something
20+
{
21+
public function __construct(
22+
public MyInterface $myInterface,
23+
) {
24+
}
25+
}
26+
27+
class TypeA implements MyInterface
28+
{
29+
public function __construct(
30+
public string $name,
31+
) {
32+
}
33+
}
34+
35+
class TypeB implements MyInterface
36+
{
37+
public function __construct(
38+
public string $age,
39+
) {
40+
}
41+
}
42+
43+
return (function () {
44+
$autoMapper = AutoMapperBuilder::buildAutoMapper(mapPrivatePropertiesAndMethod: true);
45+
46+
$something = [
47+
'myInterface' => [
48+
'type' => 'type_a',
49+
'name' => 'my name',
50+
],
51+
];
52+
yield 'to-class' => $autoMapper->map($something, Something::class);
53+
54+
$typeA = new TypeA('my name');
55+
$something = new Something($typeA);
56+
57+
yield 'to-array' => $autoMapper->map($something, 'array');
58+
})();

tests/Fixtures/DiscriminatorMapAndInterface/MyInterface.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/Fixtures/DiscriminatorMapAndInterface/Something.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/Fixtures/DiscriminatorMapAndInterface/TypeA.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/Fixtures/DiscriminatorMapAndInterface/TypeB.php

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)