Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$header = <<<'HEADER'
This file is part of the API Platform project.

Expand All @@ -18,13 +20,7 @@ return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'@PHPUnit60Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => [
Expand All @@ -34,12 +30,18 @@ return PhpCsFixer\Config::create()
'allow_single_line_closure' => true,
],
'declare_strict_types' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'header_comment' => [
'header' => $header,
'location' => 'after_open',
],
'modernize_types_casting' => true,
// 'native_function_invocation' => true,
'no_extra_consecutive_blank_lines' => [
'break',
'continue',
Expand All @@ -54,9 +56,6 @@ return PhpCsFixer\Config::create()
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
// 'phpdoc_add_missing_param_annotation' => [
// 'only_untyped' => false,
// ],
'phpdoc_order' => true,
'psr4' => true,
'semicolon_after_instruction' => true,
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- if [[ $lint = 1 ]]; then
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.4/php-cs-fixer.phar;
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.12.0/php-cs-fixer.phar;
fi
- if [[ $lint = 1 ]]; then
composer global require --dev 'phpstan/phpstan:^0.8';
Expand Down
21 changes: 9 additions & 12 deletions tests/Annotation/ApiFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,27 @@
*/
class ApiFilterTest extends TestCase
{
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage This annotation needs a value representing the filter class.
*/
public function testInvalidConstructor()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('This annotation needs a value representing the filter class.');

$resource = new ApiFilter();
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The filter class "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy" does not implement "ApiPlatform\Core\Api\FilterInterface".
*/
public function testInvalidFilter()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The filter class "ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Entity\\Dummy" does not implement "ApiPlatform\\Core\\Api\\FilterInterface".');

$resource = new ApiFilter(['value' => Dummy::class]);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Property "foo" does not exist on the ApiFilter annotation.
*/
public function testInvalidProperty()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Property "foo" does not exist on the ApiFilter annotation.');

$resource = new ApiFilter(['value' => DummyFilter::class, 'foo' => 'bar']);
}

Expand Down
10 changes: 6 additions & 4 deletions tests/Api/FilterLocatorTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,24 @@ public function testSetFilterLocatorWithNullAndNullAllowed()

/**
* @group legacy
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "$filterLocator" argument is expected to be an implementation of the "Psr\Container\ContainerInterface" interface.
*/
public function testSetFilterLocatorWithNullAndNullNotAllowed()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "$filterLocator" argument is expected to be an implementation of the "Psr\\Container\\ContainerInterface" interface.');

$filterLocatorTraitImpl = $this->getFilterLocatorTraitImpl();
$filterLocatorTraitImpl->setFilterLocator(null);
}

/**
* @group legacy
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The "$filterLocator" argument is expected to be an implementation of the "Psr\Container\ContainerInterface" interface or null.
*/
public function testSetFilterLocatorWithInvalidFilterLocator()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The "$filterLocator" argument is expected to be an implementation of the "Psr\\Container\\ContainerInterface" interface or null.');

$filterLocatorTraitImpl = $this->getFilterLocatorTraitImpl();
$filterLocatorTraitImpl->setFilterLocator(new \ArrayObject(), true);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Api/IdentifiersExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Core\Api\IdentifiersExtractor;
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
use ApiPlatform\Core\Exception\RuntimeException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
Expand Down Expand Up @@ -152,12 +153,11 @@ public function testGetRelatedIdentifiersFromItem($item, $expected)
$this->assertSame($expected, $identifiersExtractor->getIdentifiersFromItem($item));
}

/**
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
* @expectedMessage No identifier found in "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy" through relation "relatedDummy" of "ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy" used as identifier
*/
public function testThrowNoIdentifierFromItem()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('No identifier found in "ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Entity\\RelatedDummy" through relation "relatedDummy" of "ApiPlatform\\Core\\Tests\\Fixtures\\TestBundle\\Entity\\Dummy" used as identifier');

$prophecies = $this->getMetadataFactoryProphecies(Dummy::class, ['id', 'relatedDummy']);
list($propertyNameCollectionFactoryProphecy, $propertyMetadataFactoryProphecy) = $this->getMetadataFactoryProphecies(RelatedDummy::class, [], $prophecies);

Expand Down
22 changes: 10 additions & 12 deletions tests/Api/ResourceClassResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use ApiPlatform\Core\Api\ResourceClassResolver;
use ApiPlatform\Core\DataProvider\PaginatorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
Expand Down Expand Up @@ -93,25 +94,23 @@ public function testGetResourceClassWithPaginatorInterfaceAsValue()
$this->assertEquals($resourceClass, Dummy::class);
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage No resource class found for object of type "stdClass".
*/
public function testGetResourceClassWithWrongClassName()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('No resource class found for object of type "stdClass".');

$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
$resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection([Dummy::class]))->shouldBeCalled();

$resourceClassResolver = new ResourceClassResolver($resourceNameCollectionFactoryProphecy->reveal());
$resourceClassResolver->getResourceClass(new \stdClass(), null);
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage No resource class found.
*/
public function testGetResourceClassWithNoResourceClassName()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('No resource class found.');

$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);

$resourceClassResolver = new ResourceClassResolver($resourceNameCollectionFactoryProphecy->reveal());
Expand Down Expand Up @@ -140,12 +139,11 @@ public function testIsResourceClassWithWrongClassName()
$this->assertFalse($resourceClass);
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage No resource class found.
*/
public function testGetResourceClassWithNoResourceClassNameAndNoObject()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('No resource class found.');

$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);

$resourceClassResolver = new ResourceClassResolver($resourceNameCollectionFactoryProphecy->reveal());
Expand Down
8 changes: 4 additions & 4 deletions tests/Bridge/Doctrine/Orm/CollectionDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Core\Exception\RuntimeException;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
Expand Down Expand Up @@ -80,12 +81,11 @@ public function testQueryResultExtension()
$this->assertEquals([], $dataProvider->getCollection(Dummy::class, 'foo'));
}

/**
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
* @expectedExceptionMessage The repository class must have a "createQueryBuilder" method.
*/
public function testCannotCreateQueryBuilder()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('The repository class must have a "createQueryBuilder" method.');

$repositoryProphecy = $this->prophesize(ObjectRepository::class);

$managerProphecy = $this->prophesize(ObjectManager::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
use ApiPlatform\Core\Exception\PropertyNotFoundException;
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Exception\RuntimeException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
Expand Down Expand Up @@ -326,12 +327,11 @@ public function testDenormalizeItemWithExistingGroups()
$eagerExtensionTest->applyToItem($queryBuilderProphecy->reveal(), new QueryNameGenerator(), RelatedDummy::class, ['id' => 1], 'item_operation', [AbstractNormalizer::GROUPS => 'some_groups']);
}

/**
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
* @expectedExceptionMessage The total number of joined relations has exceeded the specified maximum. Raise the limit if necessary, or use the "max_depth" option of the Symfony serializer.
*/
public function testMaxJoinsReached()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('The total number of joined relations has exceeded the specified maximum. Raise the limit if necessary, or use the "max_depth" option of the Symfony serializer.');

$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
$resourceMetadataFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadata());

Expand Down
6 changes: 4 additions & 2 deletions tests/Bridge/Doctrine/Orm/Extension/FilterExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\FilterExtension;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\FilterInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
Expand Down Expand Up @@ -78,11 +79,12 @@ public function testApplyToCollectionWithValidFiltersAndDeprecatedFilterCollecti

/**
* @group legacy
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage The "$filterLocator" argument is expected to be an implementation of the "Psr\Container\ContainerInterface" interface.
*/
public function testConstructWithInvalidFilterLocator()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('The "$filterLocator" argument is expected to be an implementation of the "Psr\\Container\\ContainerInterface" interface.');

new FilterExtension($this->prophesize(ResourceMetadataFactoryInterface::class)->reveal(), new \ArrayObject());
}

Expand Down
15 changes: 7 additions & 8 deletions tests/Bridge/Doctrine/Orm/Extension/PaginationExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
use ApiPlatform\Core\DataProvider\PaginatorInterface;
use ApiPlatform\Core\DataProvider\PartialPaginatorInterface;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use Doctrine\Common\Persistence\ManagerRegistry;
Expand Down Expand Up @@ -99,12 +100,11 @@ public function testApplyToCollectionWithItemPerPageZero()
$extension->applyToCollection($queryBuilder, new QueryNameGenerator(), 'Foo', 'op');
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage Page should not be greater than 1 if itemsPerPage is equal to 0
*/
public function testApplyToCollectionWithItemPerPageZeroAndPage2()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Page should not be greater than 1 if itemsPerPage is equal to 0');

$requestStack = new RequestStack();
$requestStack->push(new Request(['pagination' => true, 'itemsPerPage' => 0, '_page' => 2]));

Expand Down Expand Up @@ -135,12 +135,11 @@ public function testApplyToCollectionWithItemPerPageZeroAndPage2()
$extension->applyToCollection($queryBuilder, new QueryNameGenerator(), 'Foo', 'op');
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage Item per page parameter should not be less than 0
*/
public function testApplyToCollectionWithItemPerPageLessThen0()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Item per page parameter should not be less than 0');

$requestStack = new RequestStack();
$requestStack->push(new Request(['pagination' => true, 'itemsPerPage' => -20, '_page' => 2]));

Expand Down
14 changes: 7 additions & 7 deletions tests/Bridge/Doctrine/Orm/ItemDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryResultItemExtensionInterface;
use ApiPlatform\Core\Bridge\Doctrine\Orm\ItemDataProvider;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Core\Exception\PropertyNotFoundException;
use ApiPlatform\Core\Exception\RuntimeException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
Expand Down Expand Up @@ -124,11 +126,10 @@ public function testGetItemDoubleIdentifier()
$this->assertEquals([], $dataProvider->getItem(Dummy::class, 'ida=1;idb=2', 'foo'));
}

/**
* @expectedException \ApiPlatform\Core\Exception\PropertyNotFoundException
*/
public function testGetItemWrongCompositeIdentifier()
{
$this->expectException(PropertyNotFoundException::class);

list($propertyNameCollectionFactory, $propertyMetadataFactory) = $this->getMetadataFactories(Dummy::class, [
'ida',
'idb',
Expand Down Expand Up @@ -196,12 +197,11 @@ public function testUnsupportedClass()
$this->assertFalse($dataProvider->supports(Dummy::class, 'foo'));
}

/**
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
* @expectedExceptionMessage The repository class must have a "createQueryBuilder" method.
*/
public function testCannotCreateQueryBuilder()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('The repository class must have a "createQueryBuilder" method.');

$repositoryProphecy = $this->prophesize(ObjectRepository::class);
$classMetadataProphecy = $this->prophesize(ClassMetadata::class);
$classMetadataProphecy->getIdentifier()->willReturn([
Expand Down
15 changes: 7 additions & 8 deletions tests/Bridge/Doctrine/Orm/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm;

use ApiPlatform\Core\Bridge\Doctrine\Orm\Paginator;
use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Tests\Fixtures\Query;
use Doctrine\ORM\Tools\Pagination\Paginator as DoctrinePaginator;
use PHPUnit\Framework\TestCase;
Expand All @@ -32,21 +33,19 @@ public function testInitialize($firstResult, $maxResults, $totalItems, $currentP
$this->assertEquals($maxResults, $paginator->getItemsPerPage());
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage "Doctrine\ORM\Query::setFirstResult()" or/and "Doctrine\ORM\Query::setMaxResults()" was/were not applied to the query.
*/
public function testInitializeWithQueryFirstResultNotApplied()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"Doctrine\\ORM\\Query::setFirstResult()" or/and "Doctrine\\ORM\\Query::setMaxResults()" was/were not applied to the query.');

$this->getPaginatorWithMalformedQuery(false);
}

/**
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
* @expectedExceptionMessage "Doctrine\ORM\Query::setFirstResult()" or/and "Doctrine\ORM\Query::setMaxResults()" was/were not applied to the query.
*/
public function testInitializeWithQueryMaxResultsNotApplied()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('"Doctrine\\ORM\\Query::setFirstResult()" or/and "Doctrine\\ORM\\Query::setMaxResults()" was/were not applied to the query.');

$this->getPaginatorWithMalformedQuery(true);
}

Expand Down
Loading