Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump dependencies to PHP 8.1 and Symfony 7.1 / 6.4. Update attribute handling logic to leverage work already done by the framework. #25

Merged
merged 1 commit into from
Aug 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
Expand All @@ -29,6 +28,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: xdebug
ini-values: "zend.assertions=1"

- name: "Cache dependencies installed with composer"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/var
phpunit.xml
composer.lock
.phpunit.result.cache
.phpunit.cache
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
}
],
"require": {
"php": ">=8.0.0",
"symfony/framework-bundle": "^5.4|^6.3|^7.0|^7.1",
"symfony/property-access": "^5.4|^6.3|^7.0|^7.1",
"symfony/translation": "^5.4|^6.3|^7.0|^7.1",
"symfony/yaml": "^5.4|^6.3|^7.0|^7.1",
"php": ">=8.1.0",
"symfony/framework-bundle": "^6.4|^7.0|^7.1",
"symfony/property-access": "^6.4|^7.0|^7.1",
"symfony/translation": "^6.4|^7.0|^7.1",
"symfony/yaml": "^6.4|^7.0|^7.1",
"twig/twig": "^2.10|^3.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
"phpunit/phpunit": "8.5.15",
"symfony/dependency-injection": "^5.4|^6.3|^7.0|^7.1",
"phpunit/php-code-coverage": "10.1.16",
"phpunit/phpunit": "10.5.30",
"symfony/dependency-injection": "^6.4|^7.0|^7.1",
"symfony/monolog-bundle": "^3.7"
},
"autoload": {
Expand Down
21 changes: 12 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Tests">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
20 changes: 1 addition & 19 deletions src/EventListener/BreadcrumbListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,7 @@ public function __construct(BreadcrumbBuilder $breadcrumbBuilder)

public function onKernelController(ControllerEvent $event): void
{
// In case controller is not an array (e.g. a closure or an invokable class), we can't do anything.
if (!is_array($event->getController())) {
return;
}

list($controller, $action) = $event->getController();

$class = new \ReflectionClass($controller);
$method = new \ReflectionMethod($controller, $action);

$breadcrumbs = [];
if (($classAttribute = $class->getAttributes(Breadcrumb::class)[0] ?? null)) {
$breadcrumbs[] = $classAttribute->newInstance();
}
if (($methodAttribute = $method->getAttributes(Breadcrumb::class)[0] ?? null)) {
$breadcrumbs[] = $methodAttribute->newInstance();
}

foreach ($breadcrumbs as $breadcrumb) {
foreach ($event->getAttributes(Breadcrumb::class) as $breadcrumb) {
foreach ($breadcrumb->items as $item) {
$this->breadcrumbBuilder->addItem(
$item['label'],
Expand Down
15 changes: 5 additions & 10 deletions tests/Unit/Service/BreadcrumbBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SlopeIt\Tests\BreadcrumbBundle\Unit\Service;

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use PHPUnit\Framework\TestCase;
use SlopeIt\BreadcrumbBundle\Model\BreadcrumbItem;
use SlopeIt\BreadcrumbBundle\Service\BreadcrumbBuilder;
Expand All @@ -15,15 +16,9 @@ class BreadcrumbBuilderTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @var BreadcrumbBuilder
*/
private $builder;
private BreadcrumbBuilder $builder;

/**
* @var BreadcrumbItemFactory|\Mockery\MockInterface
*/
private $itemFactory;
private BreadcrumbItemFactory|MockInterface $itemFactory;

protected function setUp(): void
{
Expand All @@ -48,9 +43,9 @@ public function test_getItems_emptyBreadcrumb()
public function test_getItems_nonEmptyBreadcrumb()
{
$item1 = \Mockery::mock(BreadcrumbItem::class);
$this->itemFactory->shouldReceive('create')->with('aLabel', 'aRoute', null, null)->andReturn($item1);
$this->itemFactory->expects('create')->with('aLabel', 'aRoute', null, null)->andReturn($item1);
$item2 = \Mockery::mock(BreadcrumbItem::class);
$this->itemFactory->shouldReceive('create')->with('anotherLabel', 'anotherRoute', [ 'a' => 'b' ], null)
$this->itemFactory->expects('create')->with('anotherLabel', 'anotherRoute', [ 'a' => 'b' ], null)
->andReturn($item2);

$this->builder->addItem('aLabel', 'aRoute');
Expand Down
12 changes: 4 additions & 8 deletions tests/Unit/Service/BreadcrumbItemFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
namespace SlopeIt\Tests\BreadcrumbBundle\Unit\Service;

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SlopeIt\BreadcrumbBundle\Model\BreadcrumbItem;
use SlopeIt\BreadcrumbBundle\Service\BreadcrumbItemFactory;

/**
* @coversDefaultClass \SlopeIt\BreadcrumbBundle\Service\BreadcrumbItemFactory
*/
#[CoversClass(BreadcrumbItemFactory::class)]
class BreadcrumbItemFactoryTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @covers ::create
*/
public function test_create()
{
$factory = new BreadcrumbItemFactory();

$item = $factory->create('aLabel', 'aRoute');

$this->assertTrue($item instanceof BreadcrumbItem);
$this->assertSame('aLabel', $item->getLabel());
$this->assertSame('aRoute', $item->getRoute());
}
}
49 changes: 8 additions & 41 deletions tests/Unit/Service/BreadcrumbItemProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace SlopeIt\Tests\BreadcrumbBundle\Unit\Service;

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use SlopeIt\BreadcrumbBundle\Model\BreadcrumbItem;
use SlopeIt\BreadcrumbBundle\Service\BreadcrumbItemProcessor;
Expand All @@ -14,37 +16,20 @@
use Symfony\Component\Routing\RequestContext;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @coversDefaultClass \SlopeIt\BreadcrumbBundle\Service\BreadcrumbItemProcessor
*/
#[CoversClass(BreadcrumbItemProcessor::class)]
class BreadcrumbItemProcessorTest extends TestCase
{
use MockeryPHPUnitIntegration;

/**
* @var BreadcrumbItemProcessor
*/
private $SUT;
private BreadcrumbItemProcessor $SUT;

/**
* @var PropertyAccessorInterface|\Mockery\MockInterface
*/
private $propertyAccessor;
private PropertyAccessorInterface|MockInterface $propertyAccessor;

/**
* @var RequestStack|\Mockery\MockInterface
*/
private $requestStack;
private RequestStack|MockInterface $requestStack;

/**
* @var UrlGeneratorInterface|\Mockery\MockInterface
*/
private $urlGenerator;
private UrlGeneratorInterface|MockInterface $urlGenerator;

/**
* @var TranslatorInterface|\Mockery\MockInterface
*/
private $translator;
private TranslatorInterface|MockInterface $translator;

protected function setUp(): void
{
Expand All @@ -70,9 +55,6 @@ protected function setUp(): void
);
}

/**
* @covers ::process
*/
public function test_process_item_with_label_as_simple_variable()
{
$item = new BreadcrumbItem('$variableName');
Expand All @@ -82,9 +64,6 @@ public function test_process_item_with_label_as_simple_variable()
$this->assertSame('variableValue', $processedItems[0]->getTranslatedLabel());
}

/**
* @covers ::process
*/
public function test_process_item_with_label_as_variable_with_property_path()
{
$item = new BreadcrumbItem('$variableName.property.nestedProperty');
Expand All @@ -99,9 +78,6 @@ public function test_process_item_with_label_as_variable_with_property_path()
$this->assertSame('propertyValue', $processedItems[0]->getTranslatedLabel());
}

/**
* @covers ::process
*/
public function test_process_item_with_label_not_to_be_translated()
{
$item = new BreadcrumbItem('Already translated label', null, null, false);
Expand All @@ -111,9 +87,6 @@ public function test_process_item_with_label_not_to_be_translated()
$this->assertSame('Already translated label', $processedItems[0]->getTranslatedLabel());
}

/**
* @covers ::process
*/
public function test_process_item_with_label_to_be_translated_with_default_translation_domain()
{
$item = new BreadcrumbItem('translatable_key');
Expand All @@ -126,9 +99,6 @@ public function test_process_item_with_label_to_be_translated_with_default_trans
$this->assertSame('Translated label', $processedItems[0]->getTranslatedLabel());
}

/**
* @covers ::process
*/
public function test_process_item_with_label_to_be_translated_with_specific_translation_domain()
{
$item = new BreadcrumbItem('translatable_key', null, null, 'custom_domain');
Expand All @@ -141,9 +111,6 @@ public function test_process_item_with_label_to_be_translated_with_specific_tran
$this->assertSame('Translated label', $processedItems[0]->getTranslatedLabel());
}

/**
* @covers ::process
*/
public function test_process_item_with_null_label()
{
$item = new BreadcrumbItem();
Expand Down
Loading