Skip to content

Commit fdc9afe

Browse files
committed
test: 💍 add tests
1 parent bc62568 commit fdc9afe

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <dunglas@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\JsonSchema\Tests\Fixtures;
15+
16+
use ApiPlatform\Metadata\ApiResource;
17+
18+
#[ApiResource]
19+
class DummyWithMixed
20+
{
21+
public mixed $mixedProperty;
22+
public array $mixedArrayProperty;
23+
}

src/JsonSchema/Tests/Metadata/Property/Factory/SchemaPropertyMetadataFactoryTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory;
1717
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithCustomOpenApiContext;
1818
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithEnum;
19+
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithMixed;
1920
use ApiPlatform\JsonSchema\Tests\Fixtures\DummyWithUnionTypeProperty;
2021
use ApiPlatform\JsonSchema\Tests\Fixtures\Enum\IntEnumAsIdentifier;
2122
use ApiPlatform\Metadata\ApiProperty;
@@ -167,4 +168,37 @@ public function testUnionTypeAnyOfIsArray(): void
167168

168169
$this->assertEquals($expectedSchema, $apiProperty->getSchema());
169170
}
171+
172+
public function testMixed(): void
173+
{
174+
if (!method_exists(PropertyInfoExtractor::class, 'getType')) { // @phpstan-ignore-line symfony/property-info 6.4 is still allowed and this may be true
175+
$this->markTestSkipped('This test only supports type-info component');
176+
}
177+
178+
$resourceClassResolver = $this->createMock(ResourceClassResolverInterface::class);
179+
$apiProperty = new ApiProperty(nativeType: Type::mixed());
180+
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
181+
$decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedProperty')->willReturn($apiProperty);
182+
183+
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
184+
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedProperty');
185+
186+
$this->assertEquals([
187+
'type' => ['string', 'null'],
188+
], $apiProperty->getSchema());
189+
190+
$apiProperty = new ApiProperty(nativeType: Type::array(Type::mixed()));
191+
$decorated = $this->createMock(PropertyMetadataFactoryInterface::class);
192+
$decorated->expects($this->once())->method('create')->with(DummyWithMixed::class, 'mixedArrayProperty')->willReturn($apiProperty);
193+
194+
$schemaPropertyMetadataFactory = new SchemaPropertyMetadataFactory($resourceClassResolver, $decorated);
195+
$apiProperty = $schemaPropertyMetadataFactory->create(DummyWithMixed::class, 'mixedArrayProperty');
196+
197+
$this->assertEquals([
198+
'type' => 'array',
199+
'items' => [
200+
'type' => ['string', 'null'],
201+
],
202+
], $apiProperty->getSchema());
203+
}
170204
}

0 commit comments

Comments
 (0)