Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Aug 11, 2023
1 parent 3af3e93 commit 01a11a4
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 291 deletions.
4 changes: 2 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ parameters:
-
message: '#expects ApiPlatform\\Metadata\\GraphQl\\Operation\|null, ApiPlatform\\Metadata\\Operation given#'
paths:
- tests/GraphQl/Resolver/Factory/
- src/GraphQl/Tests/Resolver/Factory/
- '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy<(\\?[a-zA-Z0-9_]+)+>::\$[a-zA-Z0-9_]+#'
# https://github.com/willdurand/Negotiation/issues/89#issuecomment-513283286
-
Expand All @@ -65,7 +65,7 @@ parameters:
# https://github.com/phpstan/phpstan-symfony/issues/76
-
message: '#Service "test" is not registered in the container\.#'
path: tests/GraphQl/Type/TypesContainerTest.php
path: src/GraphQl/Tests/Type/TypesContainerTest.php

# Expected, due to optional interfaces
- '#Method Symfony\\Component\\Serializer\\NameConverter\\NameConverterInterface::denormalize\(\) invoked with (2|3|4) parameters, 1 required\.#'
Expand Down
1 change: 1 addition & 0 deletions src/Api/CompositeIdentifierParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Normalizes a composite identifier.
*
* @author Antoine Bluchet <[email protected]>
* @deprecated
*/
final class CompositeIdentifierParser
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/ResourceClassResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class_exists(\ApiPlatform\Metadata\ResourceClassResolverInterface::class);

if (false) {
if (false) { // @phpstan-ignore-line
interface ResourceClassResolverInterface extends \ApiPlatform\Metadata\ResourceClassResolverInterface
{
}
Expand Down
6 changes: 1 addition & 5 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@

namespace ApiPlatform\Exception;

use ApiPlatform\Metadata\Exception\InvalidArgumentException as MetadataInvalidArgumentException;

/**
* Invalid argument exception.
*
* @author Kévin Dunglas <[email protected]>
*
* @deprecated use \ApiPlatform\Metadata\Exception\InvalidArgumentException
*/
class InvalidArgumentException extends MetadataInvalidArgumentException
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidIdentifierException.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*
* @author Antoine Bluchet <[email protected]>
*/
final class InvalidIdentifierException extends \Exception implements ExceptionInterface
class InvalidIdentifierException extends \Exception implements ExceptionInterface
{
}
2 changes: 0 additions & 2 deletions src/Exception/InvalidUriVariableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* Identifier is not valid exception.
*
* @author Antoine Bluchet <[email protected]>
*
* @final
*/
class InvalidUriVariableException extends \Exception implements ExceptionInterface
{
Expand Down
120 changes: 0 additions & 120 deletions src/GraphQl/.php-cs-fixer.dist.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/GraphQl/Tests/Fixtures/ApiResource/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
namespace ApiPlatform\GraphQl\Tests\Fixtures\ApiResource;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedOwnedDummy;
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedOwningDummy;
use Doctrine\Common\Collections\Collection;

/**
* Dummy.
Expand Down Expand Up @@ -194,44 +190,6 @@ public function getArrayData()
return $this->arrayData;
}

public function getRelatedDummy(): ?RelatedDummy
{
return $this->relatedDummy;
}

public function setRelatedDummy(RelatedDummy $relatedDummy): void
{
$this->relatedDummy = $relatedDummy;
}

public function addRelatedDummy(RelatedDummy $relatedDummy): void
{
$this->relatedDummies->add($relatedDummy);
}

public function getRelatedOwnedDummy()
{
return $this->relatedOwnedDummy;
}

public function setRelatedOwnedDummy(RelatedOwnedDummy $relatedOwnedDummy): void
{
$this->relatedOwnedDummy = $relatedOwnedDummy;
if ($this !== $this->relatedOwnedDummy->getOwningDummy()) {
$this->relatedOwnedDummy->setOwningDummy($this);
}
}

public function getRelatedOwningDummy()
{
return $this->relatedOwningDummy;
}

public function setRelatedOwningDummy(RelatedOwningDummy $relatedOwningDummy): void
{
$this->relatedOwningDummy = $relatedOwningDummy;
}

public function isDummyBoolean(): ?bool
{
return $this->dummyBoolean;
Expand All @@ -254,9 +212,4 @@ public function getDummy()
{
return $this->dummy;
}

public function getRelatedDummies(): Collection|iterable
{
return $this->relatedDummies;
}
}
31 changes: 31 additions & 0 deletions src/Metadata/Exception/InvalidIdentifierException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Metadata\Exception;

use ApiPlatform\Exception\InvalidIdentifierException as LegacyInvalidIdentifierException;

if (class_exists(LegacyInvalidIdentifierException::class)) {
class InvalidIdentifierException extends LegacyInvalidIdentifierException
{
}
} else {
/**
* Identifier is not valid exception.
*
* @author Antoine Bluchet <[email protected]>
*/
final class InvalidIdentifierException extends \Exception implements ExceptionInterface
{
}
}
2 changes: 2 additions & 0 deletions src/Metadata/IdentifiersExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@

namespace ApiPlatform\Metadata;

use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
use ApiPlatform\Metadata\Exception\RuntimeException;
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
use ApiPlatform\Metadata\Util\CompositeIdentifierParser;
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
use Symfony\Component\PropertyAccess\PropertyAccess;
Expand Down
5 changes: 5 additions & 0 deletions src/Metadata/IriConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

namespace ApiPlatform\Metadata;

use ApiPlatform\Metadata\Exception\InvalidArgumentException;
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
use ApiPlatform\Metadata\Exception\RuntimeException;


/**
* Converts item and resources to IRI and vice versa.
*
Expand Down
64 changes: 64 additions & 0 deletions src/Metadata/Util/CompositeIdentifierParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Metadata\Util;

/**
* Normalizes a composite identifier.
*
* @internal
* @author Antoine Bluchet <[email protected]>
*/
final class CompositeIdentifierParser
{
public const COMPOSITE_IDENTIFIER_REGEXP = '/(\w+)=(?<=\w=)(.*?)(?=;\w+=)|(\w+)=([^;]*);?$/';

private function __construct()
{
}

/*
* Normalize takes a string and gives back an array of identifiers.
*
* For example: foo=0;bar=2 returns ['foo' => 0, 'bar' => 2].
*/
public static function parse(string $identifier): array
{
$matches = [];
$identifiers = [];
$num = preg_match_all(self::COMPOSITE_IDENTIFIER_REGEXP, $identifier, $matches, \PREG_SET_ORDER);

foreach ($matches as $i => $match) {
if ($i === $num - 1) {
$identifiers[$match[3]] = $match[4];
continue;
}
$identifiers[$match[1]] = $match[2];
}

return $identifiers;
}

/**
* Renders composite identifiers to string using: key=value;key2=value2.
*/
public static function stringify(array $identifiers): string
{
$composite = [];
foreach ($identifiers as $name => $value) {
$composite[] = sprintf('%s=%s', $name, $value);
}

return implode(';', $composite);
}
}
2 changes: 1 addition & 1 deletion src/Metadata/Util/ResourceClassInfoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ trait ResourceClassInfoTrait
use ClassInfoTrait;

/**
* @var LegacyResourceClassResolverInterface|ResourceClassResolverInterface
* @var LegacyResourceClassResolverInterface|ResourceClassResolverInterface|null
*/
private $resourceClassResolver;
private ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory = null;
Expand Down
1 change: 1 addition & 0 deletions src/Serializer/AbstractItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Serializer;

/**
* Base item normalizer.
Expand Down
Loading

0 comments on commit 01a11a4

Please sign in to comment.