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
16 changes: 6 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ jobs:
fail-fast: false
matrix:
include:
- php: 7.4
- php: 8.1
composer-flags: --prefer-lowest
- php: 7.4
SYMFONY_REQUIRE: 5.4.*
- php: 8.0
- php: 8.1
SYMFONY_REQUIRE: 6.4.*
- php: 8.2
SYMFONY_REQUIRE: 7.1.*
- php: 8.3
SYMFONY_REQUIRE: 7.1.*
- php: 8.4
SYMFONY_REQUIRE: 7.3.*
- php: 8.4
stability: dev

steps:
Expand Down Expand Up @@ -62,7 +58,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
php-version: "8.4"

- name: Install dependencies
run: composer update --prefer-dist
Expand All @@ -80,7 +76,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
php-version: "8.4"

- name: Install dependencies
run: composer update --prefer-dist
Expand Down
29 changes: 14 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"symfony/framework-bundle": "^5.4 || ^6.4 || ^7.1",
"symfony/twig-bundle": "^5.4 || ^6.4 || ^7.1",
"twig/twig": "^1.35 || ^2.4.4 || ^3.0"
"php": ">=8.1",
"symfony/framework-bundle": "^6.4 || ^7.3",
"symfony/twig-bundle": "^6.4 || ^7.3",
"twig/twig": "^2.4.4 || ^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.27",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.5",
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^8.5 || ^9.5",
"symfony/browser-kit": "^5.4 || ^6.4 || ^7.1",
"symfony/css-selector": "^5.4 || ^6.4 || ^7.1",
"symfony/expression-language": "^5.4 || ^6.4 || ^7.1",
"symfony/phpunit-bridge": "^7.1",
"symfony/security-bundle": "^5.4 || ^6.4 || ^7.1",
"symfony/yaml": "5.4 || ^6.4 || ^7.1"
"friendsofphp/php-cs-fixer": "^v3.88.2",
"phpstan/extension-installer": "^1.4.3",
"phpstan/phpstan": "^2.1.30",
"phpstan/phpstan-symfony": "^2.0.8",
"phpunit/phpunit": "^10.5.58",
"symfony/browser-kit": "^6.4 || ^7.3",
"symfony/css-selector": "^6.4 || ^7.3",
"symfony/expression-language": "^6.4 || ^7.3",
"symfony/security-bundle": "^6.4 || ^7.3",
"symfony/yaml": "^6.4 || ^7.3"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/NodeVisitor/NodeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class NodeFilter implements NodeVisitorInterface

public function __construct(
TokenStorageInterface $tokenStorage,
AuthorizationCheckerInterface $authChecker
AuthorizationCheckerInterface $authChecker,
) {
$this->tokenStorage = $tokenStorage;
$this->authChecker = $authChecker;
Expand Down
19 changes: 15 additions & 4 deletions tests/Functional/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

namespace Tests\Functional;

use DAMA\MenuBundle\DAMAMenuBundle;
use Psr\Log\NullLogger;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
public function registerBundles(): iterable
{
return [
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
new \Symfony\Bundle\TwigBundle\TwigBundle(),
new \DAMA\MenuBundle\DAMAMenuBundle(),
new FrameworkBundle(),
new SecurityBundle(),
new TwigBundle(),
new DAMAMenuBundle(),
];
}

Expand All @@ -27,4 +33,9 @@ public function registerContainerConfiguration(LoaderInterface $loader): void
$loader->load(__DIR__.'/config.yml');
$loader->load(__DIR__.'/config.php');
}

protected function build(ContainerBuilder $container): void
{
$container->register('logger', NullLogger::class);
}
}
32 changes: 15 additions & 17 deletions tests/NodeVisitor/NodeActivatorTest.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
<?php

declare(strict_types=1);

namespace Tests\NodeVisitor;

use DAMA\MenuBundle\Node\Node;
use DAMA\MenuBundle\NodeVisitor\NodeActivator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class NodeActivatorTest extends TestCase
{
/**
* @var Node
*/
protected $node;
protected Node $node;

public function setUp(): void
{
$this->node = new Node();
}

/**
* @dataProvider getTestData
*
* @param string $route
*/
public function testVisit($route, array $routes, $requestRoute, $expectedIsActive): void
#[DataProvider('getTestData')]
public function testVisit(?string $route, array $routes, $requestRoute, $expectedIsActive): void
{
$this->node->setRoute($route);
$this->node->setAdditionalActiveRoutes($routes);
$requestStack = $this->getRequestStackMock($requestRoute);
$requestStack = $this->getRequestStack($requestRoute);
$activator = new NodeActivator($requestStack);

$activator->visit($this->node);

$this->assertEquals($expectedIsActive, $this->node->isActive());
}

public function getTestData()
public static function getTestData(): array
{
return [
[null, [], 'some_route', false],
Expand All @@ -45,13 +43,13 @@ public function getTestData()
];
}

private function getRequestStackMock($requestRoute)
private function getRequestStack(string $requestRoute): RequestStack
{
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
$request->expects($this->any())->method('get')->with('_route')->will($this->returnValue($requestRoute));
$request = new Request();
$request->attributes->set('_route', $requestRoute);

$requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
$requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue($request));
$requestStack = new RequestStack();
$requestStack->push($request);

return $requestStack;
}
Expand Down
65 changes: 24 additions & 41 deletions tests/NodeVisitor/NodeFilterTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

declare(strict_types=1);

namespace Tests\NodeVisitor;

use DAMA\MenuBundle\MenuTree\MenuTreeTraverserInterface;
use DAMA\MenuBundle\Node\Node;
use DAMA\MenuBundle\Node\NodeFactory;
use DAMA\MenuBundle\NodeVisitor\NodeFilter;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\ExpressionLanguage\Expression;
Expand All @@ -15,58 +19,39 @@

class NodeFilterTest extends TestCase
{
/**
* @var NodeFilter
*/
private $filter;

/**
* @var TokenStorageInterface|MockObject
*/
private $tokenStorage;

/**
* @var AuthorizationCheckerInterface|MockObject
*/
private $authChecker;

/**
* @var Node
*/
private $node;

/**
* @var Node|MockObject
*/
private $parent;
private NodeFilter $filter;
private TokenStorageInterface&MockObject $tokenStorage;
private AuthorizationCheckerInterface&MockObject $authChecker;
private Node $node;
private Node&MockObject $parent;
private TokenInterface&MockObject $token;

public function setUp(): void
{
$this->tokenStorage = $this->createMock(TokenStorageInterface::class);
$this->authChecker = $this->createMock(AuthorizationCheckerInterface::class);
$this->filter = new NodeFilter($this->tokenStorage, $this->authChecker);
$this->node = new Node();
$this->parent = $this->getMockBuilder(Node::class)->getMock();
$this->parent = $this->createMock(Node::class);
$this->node->setParent($this->parent);
$this->token = $this->createMock(TokenInterface::class);
}

/**
* @dataProvider getTestData
*/
public function testVisit(array $permissions, $getTokenReturn, $isGrantedReturn, $expectsFiltered): void
#[DataProvider('getTestData')]
public function testVisit(array $permissions, bool $hasToken, $isGrantedReturn, $expectsFiltered): void
{
$this->node->setRequiredPermissions($permissions);

$this->tokenStorage
->expects($this->any())
->method('getToken')
->will($this->returnValue($getTokenReturn))
->willReturn($hasToken ? $this->token : null)
;

$this->authChecker
->expects($this->any())
->method('isGranted')
->will($this->returnValue($isGrantedReturn))
->willReturn($isGrantedReturn)
;

if ($expectsFiltered) {
Expand All @@ -84,10 +69,8 @@ public function testVisit(array $permissions, $getTokenReturn, $isGrantedReturn,
}
}

/**
* @testWith [true]
* [false]
*/
#[TestWith([true])]
#[TestWith([false])]
public function testRemoveParentIfNoActiveChildren(bool $remove): void
{
$tree = (new NodeFactory())->create();
Expand Down Expand Up @@ -117,14 +100,14 @@ public function testRemoveParentIfNoActiveChildren(bool $remove): void
$this->assertCount($remove ? 0 : 1, $tree->getChildren());
}

public function getTestData()
public static function getTestData(): array
{
return [
[[], $this->createMock(TokenInterface::class), true, false],
[['FOO'], $this->createMock(TokenInterface::class), true, false],
[['FOO'], $this->createMock(TokenInterface::class), false, true],
[['FOO'], null, true, true],
[[new Expression('something')], null, true, true],
[[], true, true, false],
[['FOO'], true, true, false],
[['FOO'], true, false, true],
[['FOO'], false, true, true],
[[new Expression('something')], false, true, true],
];
}
}
27 changes: 8 additions & 19 deletions tests/NodeVisitor/NodeRoutePropagatorTest.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
<?php

declare(strict_types=1);

namespace Tests\NodeVisitor;

use DAMA\MenuBundle\Node\Node;
use DAMA\MenuBundle\NodeVisitor\NodeActivator;
use DAMA\MenuBundle\NodeVisitor\NodeRoutePropagator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

class NodeRoutePropagatorTest extends TestCase
{
/**
* @var NodeActivator
*/
protected $propagator;

/**
* @var Node
*/
protected $node;

/**
* @var Node
*/
protected $parent;
private NodeRoutePropagator $propagator;
private Node $node;
private Node $parent;

public function setUp(): void
{
Expand All @@ -32,9 +23,7 @@ public function setUp(): void
$this->parent->addChild($this->node);
}

/**
* @dataProvider getTestData
*/
#[DataProvider('getTestData')]
public function testVisit($childRoute, $parentRoute, $expectedParentRoute): void
{
$this->node->setRoute($childRoute);
Expand All @@ -45,7 +34,7 @@ public function testVisit($childRoute, $parentRoute, $expectedParentRoute): void
$this->assertEquals($expectedParentRoute, $this->parent->getRoute());
}

public function getTestData()
public static function getTestData(): array
{
return [
[null, 'some_route', 'some_route'],
Expand Down
Loading