Skip to content

Commit

Permalink
fix: fixes all failing unit tests
Browse files Browse the repository at this point in the history
- addresses feedback from review (import OpenApi\Attribtues as OAT)
  • Loading branch information
faizanakram99 committed Dec 11, 2023
1 parent 4207f88 commit 4988cfe
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 132 deletions.
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/ClassApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Nelmio\ApiDocBundle\Annotation\Security;
use OpenApi\Annotations as OA;
use OpenApi\Attributes\Response;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -39,7 +39,7 @@ public function securityAction()
#[Route('/api', host: 'api.example.com')]
class ClassApiController
{
#[Response(response: 201, description: '')]
#[OAT\Response(response: 201, description: '')]
#[Route('/security/class')]
public function securityAction()
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/InvokableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Response;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -37,7 +37,7 @@ public function __invoke()
/**
* Prevents a regression (see https://github.com/nelmio/NelmioApiDocBundle/issues/1559).
*/
#[Response(response: 200, description: 'Invokable!')]
#[OAT\Response(response: 200, description: 'Invokable!')]
#[Route('/api/invoke', host: 'api.example.com', name: 'invokable', methods: ['GET'])]
class InvokableController
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/SerializedNameController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Nelmio\ApiDocBundle\Tests\Functional\EntityExcluded\SerializedNameEnt;
use Nelmio\ApiDocBundle\Tests\Functional\EntityExcluded\Symfony7\SerializedNameEntity;
use OpenApi\Annotations as OA;
use OpenApi\Attributes\Response;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Annotation\Route;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function serializedNameAction()
#[Route('/api', host: 'api.example.com')]
class SerializedNameController
{
#[Response(response: 200, description: 'success', attachables: [new Model(type: SerializedNameEntity::class)])]
#[OAT\Response(response: 200, description: 'success', attachables: [new Model(type: SerializedNameEntity::class)])]
#[Route('/serializename', methods: ['GET'])]
public function serializedNameAction()
{
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Controller/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Controller;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Response;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\Annotation\Route;

Expand All @@ -38,7 +38,7 @@ public function testAction()
#[Route('/test', host: 'api-test.example.com')]
class TestController
{
#[Response(response: 200, description: 'Test')]
#[OAT\Response(response: 200, description: 'Test')]
#[Route('/test/', methods: ['GET'])]
public function testAction()
{
Expand Down
5 changes: 2 additions & 3 deletions Tests/Functional/Entity/EntityWithAlternateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\Schema;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION < 7) {
Expand All @@ -36,7 +35,7 @@ public function getIterator(): \ArrayIterator
}
}
} else {
#[Schema(type: 'array', items: new Items(type: 'string'))]
#[OAT\Schema(type: 'array', items: new OAT\Items(type: 'string'))]
class EntityWithAlternateType implements \IteratorAggregate
{
/**
Expand Down
14 changes: 7 additions & 7 deletions Tests/Functional/Entity/EntityWithNullableSchemaSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Property;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION < 7) {
Expand Down Expand Up @@ -66,37 +66,37 @@ class EntityWithNullableSchemaSet
/**
* @var ?string
*/
#[Property]
#[OAT\Property]
public $nullablePropertyNullableNotSet;

/**
* @var ?string
*/
#[Property(nullable: false)]
#[OAT\Property(nullable: false)]
public $nullablePropertyNullableFalseSet;

/**
* @var ?string
*/
#[Property(nullable: true)]
#[OAT\Property(nullable: true)]
public $nullablePropertyNullableTrueSet;

/**
* @var string
*/
#[Property]
#[OAT\Property]
public $nonNullablePropertyNullableNotSet;

/**
* @var string
*/
#[Property(nullable: false)]
#[OAT\Property(nullable: false)]
public $nonNullablePropertyNullableFalseSet;

/**
* @var string
*/
#[Property(nullable: true)]
#[OAT\Property(nullable: true)]
public $nonNullablePropertyNullableTrueSet;
}
}
4 changes: 2 additions & 2 deletions Tests/Functional/Entity/EntityWithObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Schema;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION < 7) {
Expand All @@ -27,7 +27,7 @@ class EntityWithObjectType
public $notIgnored = 'this should be read';
}
} else {
#[Schema(type: 'object')]
#[OAT\Schema(type: 'object')]
class EntityWithObjectType
{
/**
Expand Down
4 changes: 2 additions & 2 deletions Tests/Functional/Entity/EntityWithRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Schema;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION < 7) {
Expand All @@ -27,7 +27,7 @@ class EntityWithRef
public $ignored = 'this property should be ignored because of the annotation above';
}
} else {
#[Schema(ref: '#/components/schemas/Test')]
#[OAT\Schema(ref: '#/components/schemas/Test')]
class EntityWithRef
{
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Items;
use OpenApi\Attributes\Property;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
Expand Down Expand Up @@ -68,7 +67,7 @@ class SymfonyConstraintsWithValidationGroups
/**
* @var array
*/
#[Property(type: 'array', items: new Items(type: 'string'))]
#[OAT\Property(type: 'array', items: new OAT\Items(type: 'string'))]
#[Assert\Valid]
public $propertyArray;
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/Functional/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional\Entity;

use OpenApi\Annotations as OA;
use OpenApi\Attributes\Property;
use OpenApi\Attributes as OAT;
use Symfony\Component\HttpKernel\Kernel;

if (Kernel::MAJOR_VERSION < 7) {
Expand Down Expand Up @@ -180,42 +180,42 @@ class User
/**
* @var int
*/
#[Property(description: 'User id', readOnly: true, title: 'userid', default: null)]
#[OAT\Property(description: 'User id', readOnly: true, title: 'userid', default: null)]
private $id;

#[Property(type: 'string', readOnly: false)]
#[OAT\Property(type: 'string', readOnly: false)]
private $email;

/**
* User Roles Comment.
*
* @var string[]
*/
#[Property(description: 'User roles', title: 'roles', example: ['ADMIN', 'SUPERUSER'], default: ['USER'])]
#[OAT\Property(description: 'User roles', title: 'roles', example: ['ADMIN', 'SUPERUSER'], default: ['USER'])]
private $roles;

/**
* User Location.
*/
#[Property(type: 'string')]
#[OAT\Property(type: 'string')]
private $location;

/**
* @var int
*/
#[Property(type: 'string')]
#[OAT\Property(type: 'string')]
private $friendsNumber;

/**
* @var float
*/
#[Property(default: 0.0)]
#[OAT\Property(default: 0.0)]
private $money;

/**
* @var \DateTime
*/
#[Property(property: 'creationDate')]
#[OAT\Property(property: 'creationDate')]
private $createdAt;

/**
Expand All @@ -236,7 +236,7 @@ class User
/**
* @var string
*/
#[Property(enum: ['disabled', 'enabled'])]
#[OAT\Property(enum: ['disabled', 'enabled'])]
private $status;

/**
Expand All @@ -249,7 +249,7 @@ public function setMoney(float $money)
$this->money = $money;
}

#[Property(example: 1)]
#[OAT\Property(example: 1)]
public function setId(int $id)
{
$this->id = $id;
Expand Down
15 changes: 10 additions & 5 deletions Tests/Functional/WebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,19 @@ public function assertNotHasProperty($property, OA\AbstractAnnotation $annotatio
}

/**
* BC symfony < 5.3.
* BC symfony < 5.3 and symfony >= 7
*
* KernelTestCase::getContainer has a Container return type object in symfony 7
* which is incompatible with the return type of previous versions or
* at least the return type of overridden method (which was added for BC compatibility),
* hence moving it to the magic method.
*/
protected static function getContainer(): ContainerInterface
public static function __callStatic(string $name, array $arguments)
{
if (method_exists(parent::class, 'getContainer')) {
return parent::getContainer();
if ('getContainer' === $name) {
return static::$container;
}

return static::$container;
return null;
}
}
Loading

0 comments on commit 4988cfe

Please sign in to comment.