Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #39 from symfony-cmf/include-puli
Browse files Browse the repository at this point in the history
Use puli-light included int the component
  • Loading branch information
wouterj authored Jan 26, 2017
2 parents bdde75b + 7918af4 commit c65c7ad
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 94 deletions.
37 changes: 18 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm

Expand All @@ -11,39 +9,40 @@ sudo: false
cache:
directories:
- $HOME/.composer/cache/files
- .phpunit

env:
- SYMFONY_VERSION=2.7.*
matrix: SYMFONY_VERSION=3.2.*
global: SYMFONY_PHPUNIT_DIR="./.phpunit" SYMFONY_PHPUNIT_REMOVE="symfony/yaml" SYMFONY_PHPUNIT_VERSION=5.7

matrix:
allow_failures:
- env: SYMFONY_VERSION=dev-master
- php: hhvm
include:
- php: 7.1
env: SYMFONY_VERSION=3.3.* DEPS=dev
- php: 5.6
env: SYMFONY_VERSION=2.7.* SYMFONY_DEPRECATIONS_HELPER=weak
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=3.0.*
allow_failures:
- env: SYMFONY_VERSION=2.8.*
- env: SYMFONY_VERSION=3.0.*
env: SYMFONY_VERSION=2.8.* COMPOSER_FLAGS="--prefer-lowest"
- php: 7.1
env: SYMFONY_VERSION=3.1.*
fast_finish: true

before_install:
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
- if [[ "$TRAVIS_PHP_VERSION" != "hhvm" ]]; then echo "memory_limit = -1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini; fi
- phpenv config-rm xdebug.ini || true
- composer self-update
- composer require symfony/symfony:${SYMFONY_VERSION} --no-update
- if [ "$DEPS" = "dev" ]; then perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json; fi
- if [ "$SYMFONY_VERSION" != "" ]; then composer require symfony/symfony:${SYMFONY_VERSION} --no-update; fi

install: composer update --prefer-dist
install: composer update --prefer-dist $COMPOSER_FLAGS

before_script: vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh
before_script:
- mv vendor/phpunit ./phpunit
- composer dump-autoload
- vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh

script:
- phpunit
- vendor/bin/simple-phpunit
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then ./vendor/symfony-cmf/testing/bin/server & fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then mv ./phpunit vendor/phpunit; composer dump-autoload; fi
- if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then ./vendor/bin/behat; fi

notifications:
Expand Down
14 changes: 2 additions & 12 deletions Controller/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@

namespace Symfony\Cmf\Bundle\ResourceRestBundle\Controller;

use Puli\Repository\Api\EditableRepository;
use Puli\Repository\Api\ResourceRepository;
use Symfony\Cmf\Component\Resource\Puli\Api\ResourceRepository;
use Symfony\Cmf\Component\Resource\Puli\Api\ResourceNotFoundException;
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use JMS\Serializer\SerializerInterface;
use JMS\Serializer\SerializationContext;
use Puli\Repository\Api\ResourceNotFoundException;

class ResourceController
{
Expand Down Expand Up @@ -88,7 +87,6 @@ public function getResourceAction($repositoryName, $path)
public function patchResourceAction($repositoryName, $path, Request $request)
{
$repository = $this->registry->get($repositoryName);
$this->failOnNotEditable($repository, $repositoryName);

$path = '/'.ltrim($path, '/');

Expand Down Expand Up @@ -127,7 +125,6 @@ public function patchResourceAction($repositoryName, $path, Request $request)
public function deleteResourceAction($repositoryName, $path)
{
$repository = $this->registry->get($repositoryName);
$this->failOnNotEditable($repository, $repositoryName);

$path = '/'.ltrim($path, '/');

Expand All @@ -136,13 +133,6 @@ public function deleteResourceAction($repositoryName, $path)
return $this->createResponse('', Response::HTTP_NO_CONTENT);
}

private function failOnNotEditable(ResourceRepository $repository, $repositoryName)
{
if (!$repository instanceof EditableRepository) {
throw new RouteNotFoundException(sprintf('Repository "%s" is not editable.', $repositoryName));
}
}

/**
* @param string $message
*
Expand Down
2 changes: 1 addition & 1 deletion Enhancer/DescriptionEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Cmf\Bundle\ResourceRestBundle\Enhancer;

use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;
use Symfony\Cmf\Component\Resource\Description\DescriptionFactory;

/**
Expand Down
2 changes: 1 addition & 1 deletion Enhancer/EnhancerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Cmf\Bundle\ResourceRestBundle\Enhancer;

use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;

/**
* Enhancer classes enhance the REST response for resources.
Expand Down
2 changes: 1 addition & 1 deletion Enhancer/PayloadEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Cmf\Bundle\ResourceRestBundle\Enhancer;

use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;

/**
* Serialize the payload.
Expand Down
2 changes: 1 addition & 1 deletion Enhancer/SonataAdminEnhancer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Sonata\AdminBundle\Admin\Pool;
use Doctrine\Common\Util\ClassUtils;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;

/**
* Add links and meta-info from Sonata Admin.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ resources as provided by the

## Requirements

* Symfony 2.2.x
* Symfony 2.8+
* See also the `require` section of [composer.json](composer.json)

## Documentation
Expand Down
2 changes: 1 addition & 1 deletion Registry/PayloadAliasRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\Cmf\Bundle\ResourceRestBundle\Registry;

use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
use Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource;

Expand Down
2 changes: 1 addition & 1 deletion Serializer/Jms/EventSubscriber/ResourceSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
use JMS\Serializer\EventDispatcher\Events;
use JMS\Serializer\EventDispatcher\PreSerializeEvent;
use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;

/**
* Force instaces of ResourceCollection to type "ResourceCollection".
Expand Down
9 changes: 2 additions & 7 deletions Serializer/Jms/Handler/ResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
use JMS\Serializer\Context;
use PHPCR\NodeInterface;
use PHPCR\Util\PathHelper;
use Puli\Repository\Api\Resource\BodyResource;
use Puli\Repository\Api\Resource\PuliResource;
use Symfony\Cmf\Component\Resource\Puli\Api\PuliResource;
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry;
use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\EnhancerRegistry;
Expand Down Expand Up @@ -76,7 +75,7 @@ public function serializeResource(
private function doSerializeResource(PuliResource $resource, $depth = 0)
{
$data = array();
$repositoryAlias = $this->registry->getRepositoryAlias($resource->getRepository());
$repositoryAlias = $this->registry->getRepositoryName($resource->getRepository());

$data['repository_alias'] = $repositoryAlias;
$data['repository_type'] = $this->registry->getRepositoryType($resource->getRepository());
Expand All @@ -103,10 +102,6 @@ private function doSerializeResource(PuliResource $resource, $depth = 0)
}
$data['children'] = $children;

if ($resource instanceof BodyResource) {
$data['body'] = $resource->getBody();
}

foreach ($enhancers as $enhancer) {
$data = $enhancer->enhance($data, $resource);
}
Expand Down
64 changes: 32 additions & 32 deletions Tests/Features/resource_api_filesystem.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ Feature: Filesystem resource repository
As a webservice user
I need to be able to query the webservice

Background:
Given the test application has the following configuration:
"""
cmf_resource:
repositories:
default:
type: filesystem
base_dir: "%kernel.root_dir%/Resources/views/snippets"
"""
And there is a file named "%kernel.root_dir%/Resources/views/snippets/snippet1.html" with:
"""
<h1>Snippet 1</h1>
"""


Scenario: Retrieve filesystem resource
When I send a GET request to "/api/default/snippet1.html"
Then the response should contain json:
"""
{
"repository_alias": "default",
"repository_type": "filesystem",
"payload_alias": null,
"payload_type": null,
"path": "\/snippet1.html",
"node_name": "snippet1.html",
"label": "snippet1.html",
"repository_path": "\/snippet1.html",
"children": [],
"body": "<h1>Snippet 1</h1>"
}
"""
# Background:
# Given the test application has the following configuration:
# """
# cmf_resource:
# repositories:
# default:
# type: filesystem
# base_dir: "%kernel.root_dir%/Resources/views/snippets"
# """
# And there is a file named "%kernel.root_dir%/Resources/views/snippets/snippet1.html" with:
# """
# <h1>Snippet 1</h1>
# """
#
#
# Scenario: Retrieve filesystem resource
# When I send a GET request to "/api/default/snippet1.html"
# Then the response should contain json:
# """
# {
# "repository_alias": "default",
# "repository_type": "filesystem",
# "payload_alias": null,
# "payload_type": null,
# "path": "\/snippet1.html",
# "node_name": "snippet1.html",
# "label": "snippet1.html",
# "repository_path": "\/snippet1.html",
# "children": [],
# "body": "<h1>Snippet 1</h1>"
# }
# """
1 change: 1 addition & 0 deletions Tests/Resources/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Symfony\Cmf\Component\Testing\HttpKernel\TestKernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Cmf\Bundle\ResourceRestBundle\Tests\Features\Context\ResourceContext;
use Symfony\Bundle\WebServerBundle\WebServerBundle;

/**
* This is the kernel used by the application being tested.
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Enhancer/SonataAdminEnhancerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SonataAdminEnhancerTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
$this->admin = $this->prophesize('Sonata\AdminBundle\Admin\Admin');
$this->admin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
$this->pool = $this->prophesize('Sonata\AdminBundle\Admin\Pool');
$this->visitor = $this->prophesize('JMS\Serializer\GenericSerializationVisitor');
$this->generator = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Unit/Registry/PayloadAliasRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function setUp()
{
$this->repositoryRegistry = $this->prophesize('Symfony\Cmf\Component\Resource\RepositoryRegistryInterface');
$this->resource = $this->prophesize('Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource');
$this->repository = $this->prophesize('Puli\Repository\Api\ResourceRepository');
$this->repository = $this->prophesize('Symfony\Cmf\Component\Resource\Puli\Api\ResourceRepository');
}

public function provideRegistry()
Expand Down
6 changes: 3 additions & 3 deletions Tests/Unit/Serializer/Jms/Handler/ResourceHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function setUp()
$this->resource = $this->prophesize('Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource');
$this->childResource = $this->prophesize('Symfony\Cmf\Component\Resource\Repository\Resource\CmfResource');

$this->repository = $this->prophesize('Puli\Repository\Api\ResourceRepository');
$this->repository = $this->prophesize('Symfony\Cmf\Component\Resource\Puli\Api\ResourceRepository');
$this->payload = new \stdClass();
$this->context = $this->prophesize('JMS\Serializer\Context');

Expand All @@ -43,7 +43,7 @@ public function setUp()

public function testHandler()
{
$this->repositoryRegistry->getRepositoryAlias($this->repository)->willReturn('repo');
$this->repositoryRegistry->getRepositoryName($this->repository)->willReturn('repo');
$this->repositoryRegistry->getRepositoryType($this->repository)->willReturn('repo_type');
$this->payloadAliasRegistry->getPayloadAlias($this->resource->reveal())->willReturn('alias');
$this->resource->getPayloadType()->willReturn('payload_type');
Expand All @@ -64,7 +64,7 @@ public function testHandler()
$this->enhancerRegistry->getEnhancers('repo')->willReturn(array(
$this->enhancer,
));
$this->enhancer->enhance(Argument::type('array'), Argument::type('Puli\Repository\Api\Resource\PuliResource'))
$this->enhancer->enhance(Argument::type('array'), Argument::type('Symfony\Cmf\Component\Resource\Puli\Api\PuliResource'))
->will(function ($data, $resource) {
return $data[0];
});
Expand Down
26 changes: 14 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
}
],
"require": {
"php": "^5.5.6|^7.0",
"symfony-cmf/resource-bundle": "^1.0",
"puli/repository": "@beta",
"jms/serializer-bundle": "1.*"
"php": "^5.6|^7.0",
"symfony-cmf/resource": "1.0.*@dev",
"symfony-cmf/resource-bundle": "1.0.*@dev",
"jms/serializer-bundle": "^1.0"
},
"require-dev": {
"symfony-cmf/testing": "^1.3",
"symfony-cmf/testing": "^2.0",
"symfony/phpunit-bridge": "^3.2",
"doctrine/phpcr-odm": "^1.3",
"behat/behat": "^3.0",
"behat/web-api-extension" : "1.*",
"behat/symfony2-extension": "2.*@dev",
"matthiasnoback/symfony-dependency-injection-test": "~0.1",
"matthiasnoback/symfony-config-test": "~0.1",
"sonata-project/doctrine-phpcr-admin-bundle": "^1.2"
"jms/serializer": "^1.2",
"behat/behat": "^3.0.6",
"behat/web-api-extension" : "^1.0@dev",
"behat/symfony2-extension": "^2.0",
"matthiasnoback/symfony-dependency-injection-test": "~0.6",
"matthiasnoback/symfony-config-test": "^1.3.1",
"sonata-project/admin-bundle": "^3.1"
},
"minimum-stability": "dev",
"minimum-stability": "RC",
"prefer-stable": true,
"suggest": {
"doctrine/phpcr-odm": "To enable support for the PHPCR ODM documents (^1.2)",
Expand Down

0 comments on commit c65c7ad

Please sign in to comment.