From 5bf231870ecb7347a81129442a92f95c342a3c50 Mon Sep 17 00:00:00 2001 From: Piotr Szymaszek Date: Tue, 19 Dec 2017 10:32:42 +0100 Subject: [PATCH 1/2] Allowed Symfony 4+ components --- .travis.yml | 3 ++- composer.json | 13 +++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 62d139e..3ab3ab3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,8 @@ matrix: before_script: - phpenv config-rm xdebug.ini - - composer update $COMPOSER_FLAGS + - travis_wait 30 composer update $COMPOSER_FLAGS + - composer validate script: - bin/phpspec run -f pretty diff --git a/composer.json b/composer.json index 781a97d..23b76c6 100644 --- a/composer.json +++ b/composer.json @@ -1,8 +1,8 @@ { "name": "fsi/admin-tree-bundle", "type": "symfony-bundle", - "description": "FSi admin tree bundle.", - "keywords": ["admin", "symfony", "bundle", "tree", "fsi"], + "description": "Provides integration for fsi/admin bundle with gedmo/doctrine-extensions tree.", + "keywords": ["admin", "symfony", "bundle", "tree", "fsi", "gedmo", "doctrine-extensions"], "license": "MIT", "authors": [ { @@ -12,12 +12,17 @@ ], "require": { "php": ">=7.1", - "symfony/framework-bundle" : "^2.3|^3.0", + "symfony/framework-bundle" : "^2.3|^3.0|^4.0", "fsi/admin-bundle" : "^2.0|^3.0@dev", "gedmo/doctrine-extensions": "^2.4" }, "require-dev": { - "phpspec/phpspec": "^3.0" + "phpspec/phpspec": "^4.0", + "phpspec/prophecy": "^1.7.2", + "fsi/datagrid": "^2.0@dev", + "fsi/datagrid-bundle": "^2.0@dev", + "fsi/datasource": "^2.0@dev", + "fsi/datasource-bundle": "^2.0@dev" }, "config": { "bin-dir": "bin" From cf4ba3503288b9d4e0364a3fe34b222b388dcb83 Mon Sep 17 00:00:00 2001 From: Piotr Szymaszek Date: Tue, 19 Dec 2017 11:45:20 +0100 Subject: [PATCH 2/2] Utilized PHP 7.1 functionality --- .travis.yml | 2 +- Controller/ReorderController.php | 38 +++----------- DependencyInjection/FSiAdminTreeExtension.php | 15 +++--- .../Controller/ReorderControllerSpec.php | 49 ++++++++++++------- .../FSiAdminTreeBundleSpec.php | 6 ++- 5 files changed, 47 insertions(+), 63 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3ab3ab3..2663179 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,7 @@ matrix: before_script: - phpenv config-rm xdebug.ini - - travis_wait 30 composer update $COMPOSER_FLAGS + - travis_wait 40 composer update $COMPOSER_FLAGS - composer validate script: diff --git a/Controller/ReorderController.php b/Controller/ReorderController.php index fa5de3f..a74f068 100644 --- a/Controller/ReorderController.php +++ b/Controller/ReorderController.php @@ -7,6 +7,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace FSi\Bundle\AdminTreeBundle\Controller; use Doctrine\ORM\EntityRepository; @@ -31,12 +33,6 @@ public function __construct(RouterInterface $router) $this->router = $router; } - /** - * @param DataIndexerElement $element - * @param mixed $id - * @param Request $request - * @return RedirectResponse - */ public function moveUpAction(DataIndexerElement $element, $id, Request $request) { $this->getRepository($element)->moveUp($this->getEntity($element, $id)); @@ -46,12 +42,6 @@ public function moveUpAction(DataIndexerElement $element, $id, Request $request) return $this->getRedirectResponse($element, $request); } - /** - * @param DataIndexerElement $element - * @param mixed $id - * @param Request $request - * @return RedirectResponse - */ public function moveDownAction(DataIndexerElement $element, $id, Request $request) { $this->getRepository($element)->moveDown($this->getEntity($element, $id)); @@ -78,11 +68,7 @@ private function getEntity(DataIndexerElement $element, $id) return $entity; } - /** - * @param Element $element - * @return NestedTreeRepository - */ - private function getRepository(Element $element) + private function getRepository(Element $element): NestedTreeRepository { $repository = $element->getRepository(); $this->assertCorrectRepositoryType($repository); @@ -90,11 +76,7 @@ private function getRepository(Element $element) return $repository; } - /** - * @param EntityRepository $repository - * @throws InvalidArgumentException - */ - private function assertCorrectRepositoryType($repository) + private function assertCorrectRepositoryType(EntityRepository $repository): void { if (!$repository instanceof NestedTreeRepository) { throw new InvalidArgumentException( @@ -103,20 +85,12 @@ private function assertCorrectRepositoryType($repository) } } - /** - * @param Element $element - */ - private function flush(Element $element) + private function flush(Element $element): void { $element->getObjectManager()->flush(); } - /** - * @param DataIndexerElement $element - * @param Request $request - * @return RedirectResponse - */ - private function getRedirectResponse(DataIndexerElement $element, Request $request) + private function getRedirectResponse(DataIndexerElement $element, Request $request): RedirectResponse { if ($request->query->get('redirect_uri')) { $uri = $request->query->get('redirect_uri'); diff --git a/DependencyInjection/FSiAdminTreeExtension.php b/DependencyInjection/FSiAdminTreeExtension.php index de737d6..05a5f52 100644 --- a/DependencyInjection/FSiAdminTreeExtension.php +++ b/DependencyInjection/FSiAdminTreeExtension.php @@ -7,6 +7,8 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace FSi\Bundle\AdminTreeBundle\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -14,19 +16,14 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\Loader; -/** - * This is the class that loads and manages your bundle configuration - * - * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html} - */ class FSiAdminTreeExtension extends Extension { - /** - * {@inheritDoc} - */ public function load(array $configs, ContainerBuilder $container) { - $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new Loader\XmlFileLoader( + $container, + new FileLocator(__DIR__.'/../Resources/config') + ); $loader->load('services.xml'); } } diff --git a/spec/FSi/Bundle/AdminTreeBundle/Controller/ReorderControllerSpec.php b/spec/FSi/Bundle/AdminTreeBundle/Controller/ReorderControllerSpec.php index a20f631..06632d2 100644 --- a/spec/FSi/Bundle/AdminTreeBundle/Controller/ReorderControllerSpec.php +++ b/spec/FSi/Bundle/AdminTreeBundle/Controller/ReorderControllerSpec.php @@ -7,16 +7,23 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace spec\FSi\Bundle\AdminTreeBundle\Controller; use Doctrine\Common\Persistence\ObjectManager; use Doctrine\ORM\EntityRepository; +use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; +use FSi\Bundle\AdminTreeBundle\Controller\ReorderController; use FSi\Component\DataIndexer\DoctrineDataIndexer; +use FSi\Component\DataIndexer\Exception\RuntimeException; use Gedmo\Tree\Entity\Repository\NestedTreeRepository; -use FSi\Bundle\AdminBundle\Doctrine\Admin\CRUDElement; +use InvalidArgumentException; use PhpSpec\ObjectBehavior; use Prophecy\Argument; +use stdClass; use Symfony\Component\HttpFoundation\ParameterBag; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Router; @@ -44,13 +51,13 @@ function let( function it_is_initializable() { - $this->shouldHaveType('FSi\Bundle\AdminTreeBundle\Controller\ReorderController'); + $this->shouldHaveType(ReorderController::class); } function it_moves_up_item_when_move_up_action_called( CRUDElement $element, NestedTreeRepository $repository, - \stdClass $category, + stdClass $category, ObjectManager $om, Router $router, DoctrineDataIndexer $indexer, @@ -62,18 +69,20 @@ function it_moves_up_item_when_move_up_action_called( $om->flush()->shouldBeCalled(); - $router->generate('fsi_admin_crud_list', Argument::withEntry('element', 'category')) - ->willReturn('sample-path'); + $router->generate( + 'fsi_admin_crud_list', + Argument::withEntry('element', 'category') + )->willReturn('sample-path'); $response = $this->moveUpAction($element, 1, $request); - $response->shouldHaveType('Symfony\Component\HttpFoundation\RedirectResponse'); + $response->shouldHaveType(RedirectResponse::class); $response->getTargetUrl()->shouldReturn('sample-path'); } function it_moves_down_item_when_move_down_action_called( CRUDElement $element, NestedTreeRepository $repository, - \stdClass $category, + stdClass $category, ObjectManager $om, Router $router, DoctrineDataIndexer $indexer, @@ -85,11 +94,13 @@ function it_moves_down_item_when_move_down_action_called( $om->flush()->shouldBeCalled(); - $router->generate('fsi_admin_crud_list', Argument::withEntry('element', 'category')) - ->willReturn('sample-path'); + $router->generate( + 'fsi_admin_crud_list', + Argument::withEntry('element', 'category') + )->willReturn('sample-path'); $response = $this->moveDownAction($element, 1, $request); - $response->shouldHaveType('Symfony\Component\HttpFoundation\RedirectResponse'); + $response->shouldHaveType(RedirectResponse::class); $response->getTargetUrl()->shouldReturn('sample-path'); } @@ -98,12 +109,12 @@ function it_throws_runtime_exception_when_specified_entity_doesnt_exist( DoctrineDataIndexer $indexer, Request $request ) { - $indexer->getData(666)->willThrow('FSi\Component\DataIndexer\Exception\RuntimeException'); + $indexer->getData(666)->willThrow(RuntimeException::class); - $this->shouldThrow('FSi\Component\DataIndexer\Exception\RuntimeException') + $this->shouldThrow(RuntimeException::class) ->duringMoveUpAction($element, 666, $request); - $this->shouldThrow('FSi\Component\DataIndexer\Exception\RuntimeException') + $this->shouldThrow(RuntimeException::class) ->duringMoveDownAction($element, 666, $request); } @@ -111,23 +122,23 @@ function it_throws_exception_when_entity_doesnt_have_correct_repository( CRUDElement $element, EntityRepository $repository, DoctrineDataIndexer $indexer, - \stdClass $category, + stdClass $category, Request $request ) { $indexer->getData(666)->willReturn($category); $element->getRepository()->willReturn($repository); - $this->shouldThrow('\InvalidArgumentException') + $this->shouldThrow(InvalidArgumentException::class) ->duringMoveUpAction($element, 666, $request); - $this->shouldThrow('\InvalidArgumentException') + $this->shouldThrow(InvalidArgumentException::class) ->duringMoveDownAction($element, 666, $request); } function it_redirects_to_redirect_uri_parameter_after_operation( CRUDElement $element, DoctrineDataIndexer $indexer, - \stdClass $category, + stdClass $category, Request $request, ParameterBag $query ) { @@ -135,11 +146,11 @@ function it_redirects_to_redirect_uri_parameter_after_operation( $indexer->getData(1)->willReturn($category); $response = $this->moveUpAction($element, 1, $request); - $response->shouldHaveType('Symfony\Component\HttpFoundation\RedirectResponse'); + $response->shouldHaveType(RedirectResponse::class); $response->getTargetUrl()->shouldReturn('some_redirect_uri'); $response = $this->moveDownAction($element, 1, $request); - $response->shouldHaveType('Symfony\Component\HttpFoundation\RedirectResponse'); + $response->shouldHaveType(RedirectResponse::class); $response->getTargetUrl()->shouldReturn('some_redirect_uri'); } } diff --git a/spec/FSi/Bundle/AdminTreeBundle/FSiAdminTreeBundleSpec.php b/spec/FSi/Bundle/AdminTreeBundle/FSiAdminTreeBundleSpec.php index 086ea81..0a0282a 100644 --- a/spec/FSi/Bundle/AdminTreeBundle/FSiAdminTreeBundleSpec.php +++ b/spec/FSi/Bundle/AdminTreeBundle/FSiAdminTreeBundleSpec.php @@ -7,15 +7,17 @@ * file that was distributed with this source code. */ +declare(strict_types=1); + namespace spec\FSi\Bundle\AdminTreeBundle; use PhpSpec\ObjectBehavior; -use Prophecy\Argument; +use Symfony\Component\HttpKernel\Bundle\Bundle; class FSiAdminTreeBundleSpec extends ObjectBehavior { function it_is_bundle() { - $this->shouldHaveType('Symfony\Component\HttpKernel\Bundle\Bundle'); + $this->shouldHaveType(Bundle::class); } }