-
-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e9dbd52
commit 152a695
Showing
3 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\TypeDescriber; | ||
|
||
use Nelmio\ApiDocBundle\TypeDescriber\BoolDescriber; | ||
use OpenApi\Annotations as OA; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\TypeInfo\Type; | ||
use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; | ||
|
||
class BoolDescriberTest extends TestCase | ||
{ | ||
private BoolDescriber $typeDescriber; | ||
|
||
protected function setUp(): void | ||
{ | ||
if (!class_exists(Type::class)) { | ||
self::markTestSkipped('The "symfony/type-info" package is not available.'); | ||
} | ||
|
||
$this->typeDescriber = new BoolDescriber(); | ||
} | ||
|
||
/** | ||
* @dataProvider provideTypes | ||
* | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function testDescribe(Type $type, array $context = []): void | ||
{ | ||
$schema = new OA\Schema([]); | ||
|
||
self::assertTrue($this->typeDescriber->supports($type, $context)); | ||
Check failure on line 42 in tests/TypeDescriber/BoolDescriberTest.php
|
||
|
||
$this->typeDescriber->describe($type, $schema, $context); | ||
Check failure on line 44 in tests/TypeDescriber/BoolDescriberTest.php
|
||
|
||
self::assertSame([ | ||
'type' => 'boolean', | ||
], json_decode($schema->toJson(), true)); | ||
} | ||
|
||
public static function provideTypes(): \Generator | ||
{ | ||
$typeResolver = TypeResolver::create(); | ||
|
||
yield [ | ||
Type::bool(), | ||
]; | ||
|
||
yield [ | ||
$typeResolver->resolve(new \ReflectionProperty(new class { | ||
public bool $property; | ||
}, 'property')), | ||
]; | ||
|
||
yield [ | ||
$typeResolver->resolve(new \ReflectionMethod(new class { | ||
public function method(): bool | ||
{ | ||
} | ||
}, 'method')), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\TypeDescriber; | ||
|
||
use Nelmio\ApiDocBundle\TypeDescriber\FloatDescriber; | ||
use OpenApi\Annotations as OA; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\TypeInfo\Type; | ||
use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; | ||
|
||
class FloatDescriberTest extends TestCase | ||
{ | ||
private FloatDescriber $typeDescriber; | ||
|
||
protected function setUp(): void | ||
{ | ||
if (!class_exists(Type::class)) { | ||
self::markTestSkipped('The "symfony/type-info" package is not available.'); | ||
} | ||
|
||
$this->typeDescriber = new FloatDescriber(); | ||
} | ||
|
||
/** | ||
* @dataProvider provideTypes | ||
* | ||
* @param array<string, mixed> $context | ||
*/ | ||
public function testDescribe(Type $type, array $context = []): void | ||
{ | ||
$schema = new OA\Schema([]); | ||
|
||
self::assertTrue($this->typeDescriber->supports($type, $context)); | ||
Check failure on line 42 in tests/TypeDescriber/FloatDescriberTest.php
|
||
|
||
$this->typeDescriber->describe($type, $schema, $context); | ||
Check failure on line 44 in tests/TypeDescriber/FloatDescriberTest.php
|
||
|
||
self::assertSame([ | ||
'type' => 'number', | ||
'format' => 'float', | ||
], json_decode($schema->toJson(), true)); | ||
} | ||
|
||
public static function provideTypes(): \Generator | ||
{ | ||
$typeResolver = TypeResolver::create(); | ||
|
||
yield [ | ||
Type::float(), | ||
]; | ||
|
||
yield [ | ||
$typeResolver->resolve(new \ReflectionProperty(new class { | ||
public float $property; | ||
}, 'property')), | ||
]; | ||
|
||
yield [ | ||
$typeResolver->resolve(new \ReflectionMethod(new class { | ||
public function method(): float | ||
{ | ||
} | ||
}, 'method')), | ||
]; | ||
} | ||
} |