Skip to content

Commit

Permalink
Merge pull request #14 from szymach/sf4
Browse files Browse the repository at this point in the history
Allowed Symfony 4+ components
  • Loading branch information
rn0 authored Dec 20, 2017
2 parents 51b895e + cf4ba35 commit 7f7efba
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 67 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ matrix:

before_script:
- phpenv config-rm xdebug.ini
- composer update $COMPOSER_FLAGS
- travis_wait 40 composer update $COMPOSER_FLAGS
- composer validate

script:
- bin/phpspec run -f pretty
38 changes: 6 additions & 32 deletions Controller/ReorderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -78,23 +68,15 @@ 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);

return $repository;
}

/**
* @param EntityRepository $repository
* @throws InvalidArgumentException
*/
private function assertCorrectRepositoryType($repository)
private function assertCorrectRepositoryType(EntityRepository $repository): void
{
if (!$repository instanceof NestedTreeRepository) {
throw new InvalidArgumentException(
Expand All @@ -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');
Expand Down
15 changes: 6 additions & 9 deletions DependencyInjection/FSiAdminTreeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FSi\Bundle\AdminTreeBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
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');
}
}
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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');
}

Expand All @@ -98,48 +109,48 @@ 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);
}

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
) {
$query->get('redirect_uri')->willReturn('some_redirect_uri');
$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');
}
}
6 changes: 4 additions & 2 deletions spec/FSi/Bundle/AdminTreeBundle/FSiAdminTreeBundleSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 7f7efba

Please sign in to comment.