Skip to content

Commit

Permalink
Merge pull request #710 from soyuka/coverage-improvements
Browse files Browse the repository at this point in the history
Improve coverage file configuration metadata
  • Loading branch information
dunglas committed Aug 29, 2016
2 parents c7c64b7 + a6573a1 commit 90f8688
Show file tree
Hide file tree
Showing 14 changed files with 460 additions and 247 deletions.
3 changes: 2 additions & 1 deletion src/Metadata/Resource/Factory/XmlResourceMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace ApiPlatform\Core\Metadata\Resource\Factory;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;

Expand Down Expand Up @@ -66,7 +67,7 @@ public function create(string $resourceClass) : ResourceMetadata
$internalErrors = libxml_use_internal_errors(true);

if (false === @$resources->schemaValidate(self::RESOURCE_SCHEMA)) {
throw new \InvalidArgumentException(sprintf('XML Schema loaded from path %s is not valid! Errors: %s', realpath($path), implode("\n", $this->getXmlErrors($internalErrors))));
throw new InvalidArgumentException(sprintf('XML Schema loaded from path %s is not valid! Errors: %s', realpath($path), implode("\n", $this->getXmlErrors($internalErrors))));
}

libxml_clear_errors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace ApiPlatform\Core\Metadata\Resource\Factory;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ public function create() : ResourceNameCollection
$internalErrors = libxml_use_internal_errors(true);

if (false === @$resources->schemaValidate(self::RESOURCE_SCHEMA)) {
throw new \InvalidArgumentException(sprintf('XML Schema loaded from path %s is not valid! Errors: %s', realpath($path), implode("\n", $this->getXmlErrors($internalErrors))));
throw new InvalidArgumentException(sprintf('XML Schema loaded from path %s is not valid! Errors: %s', realpath($path), implode("\n", $this->getXmlErrors($internalErrors))));
}

libxml_clear_errors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace ApiPlatform\Core\Metadata\Resource\Factory;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use Symfony\Component\Yaml\Parser as YamlParser;
Expand Down Expand Up @@ -66,7 +67,7 @@ public function create(string $resourceClass) : ResourceMetadata

foreach ($resources as $resource) {
if (!isset($resource['class'])) {
throw new \InvalidArgumentException('Resource must represent a class, none found!');
throw new InvalidArgumentException('Resource must represent a class, none found!');
}

if ($resourceClass !== $resource['class']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace ApiPlatform\Core\Metadata\Resource\Factory;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
use Symfony\Component\Yaml\Parser as YamlParser;

Expand Down Expand Up @@ -56,7 +57,7 @@ public function create() : ResourceNameCollection

foreach ($resources as $resource) {
if (!isset($resource['class'])) {
throw new \InvalidArgumentException('Resource must represent a class, none found!');
throw new InvalidArgumentException('Resource must represent a class, none found!');
}

$classes[$resource['class']] = true;
Expand Down
2 changes: 1 addition & 1 deletion src/schema/metadata.xsd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="resources">
<xs:complexType>
<xs:sequence>
<xs:sequence minOccurs="1" maxOccurs="unbounded">
<xs:element name="resource">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
Expand Down
3 changes: 3 additions & 0 deletions tests/Fixtures/FileConfigurations/resourcenoclass.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
configdummy:
attributes: []
1 change: 1 addition & 0 deletions tests/Fixtures/FileConfigurations/resources.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<resource class="ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy" />
<resource class="ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy" shortName="thedummyshortname" description="Dummy resource" iri="someirischema">
<itemOperations>
<operation key="my_op_name" method="GET" />
Expand Down
4 changes: 3 additions & 1 deletion tests/Fixtures/FileConfigurations/resources.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
resources:
dummy:
class: 'ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy'
configdummy:
shortName: 'thedummyshortname'
description: 'Dummy resource'
class: 'ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\FileConfigDummy'
itemOperations:
my_op_name:
my_op_name:
method: 'GET'
my_other_op_name:
method: 'POST'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

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

namespace ApiPlatform\Core\Tests\Metadata\Resource\Factory;

use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;

/**
* Resource metadata provider for file configurated factories tests.
*
* @author Antoine Bluchet <soyuka@gmail.com>
*/
abstract class FileConfigurationMetadataFactoryProvider extends \PHPUnit_Framework_TestCase
{
public function resourceMetadataProvider()
{
$resourceMetadata = new ResourceMetadata();

$metadata = [
'shortName' => 'thedummyshortname',
'description' => 'Dummy resource',
'itemOperations' => [
'my_op_name' => ['method' => 'GET'],
'my_other_op_name' => ['method' => 'POST'],
],
'collectionOperations' => [
'my_collection_op' => ['method' => 'POST', 'path' => 'the/collection/path'],
],
'iri' => 'someirischema',
'attributes' => [
'normalization_context' => [
'groups' => ['default'],
],
'denormalization_context' => [
'groups' => ['default'],
],
'hydra_context' => [
'@type' => 'hydra:Operation',
'@hydra:title' => 'File config Dummy',
],
],
];

foreach (['shortName', 'description', 'itemOperations', 'collectionOperations', 'iri', 'attributes'] as $property) {
$wither = 'with'.ucfirst($property);
$resourceMetadata = $resourceMetadata->$wither($metadata[$property]);
}

return [[$resourceMetadata]];
}

public function optionalResourceMetadataProvider()
{
$resourceMetadata = new ResourceMetadata();

$resourceMetadata = $resourceMetadata->withItemOperations([
'my_op_name' => ['method' => 'POST'],
]);

return [[$resourceMetadata]];
}
}
Loading

0 comments on commit 90f8688

Please sign in to comment.