Skip to content

Commit

Permalink
skip tests if not available
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Jan 17, 2025
1 parent e9dbd52 commit 152a695
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Nelmio\ApiDocBundle\Tests\Functional\TestKernel;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\TypeInfo\Type;

final class ObjectModelDescriberTypeInfoTest extends ObjectModelDescriberTest
{
Expand All @@ -21,6 +22,15 @@ protected static function createKernel(array $options = []): KernelInterface
return new TestKernel(TestKernel::USE_TYPE_INFO);
}

protected function setUp(): void
{
if (!class_exists(Type::class)) {
self::markTestSkipped('The "symfony/type-info" package is not available.');
}

parent::setUp(); // TODO: Change the autogenerated stub
}

public static function provideFixtures(): \Generator
{
/*
Expand Down
73 changes: 73 additions & 0 deletions tests/TypeDescriber/BoolDescriberTest.php
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

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $type of method Nelmio\ApiDocBundle\TypeDescriber\BoolDescriber::supports() expects Symfony\Component\TypeInfo\Type\BuiltinType, Symfony\Component\TypeInfo\Type given.

$this->typeDescriber->describe($type, $schema, $context);

Check failure on line 44 in tests/TypeDescriber/BoolDescriberTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $type of method Nelmio\ApiDocBundle\TypeDescriber\BoolDescriber::describe() expects Symfony\Component\TypeInfo\Type\BuiltinType, Symfony\Component\TypeInfo\Type given.

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

Check failure on line 67 in tests/TypeDescriber/BoolDescriberTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method class@anonymous/tests/TypeDescriber/BoolDescriberTest.php:66::method() should return bool but return statement is missing.
{
}
}, 'method')),
];
}
}
74 changes: 74 additions & 0 deletions tests/TypeDescriber/FloatDescriberTest.php
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

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $type of method Nelmio\ApiDocBundle\TypeDescriber\FloatDescriber::supports() expects Symfony\Component\TypeInfo\Type\BuiltinType, Symfony\Component\TypeInfo\Type given.

$this->typeDescriber->describe($type, $schema, $context);

Check failure on line 44 in tests/TypeDescriber/FloatDescriberTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $type of method Nelmio\ApiDocBundle\TypeDescriber\FloatDescriber::describe() expects Symfony\Component\TypeInfo\Type\BuiltinType, Symfony\Component\TypeInfo\Type given.

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

Check failure on line 68 in tests/TypeDescriber/FloatDescriberTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method class@anonymous/tests/TypeDescriber/FloatDescriberTest.php:67::method() should return float but return statement is missing.
{
}
}, 'method')),
];
}
}

0 comments on commit 152a695

Please sign in to comment.