Skip to content

Commit

Permalink
bug #3375 Fix PHP 7.2 compatibility, add test for legacy controller (…
Browse files Browse the repository at this point in the history
…IonBazan)

This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Fix PHP 7.2 compatibility, add test for legacy controller

This change fixes PHP 7.2 compatibility (using NowDoc) and adds test to assure it will not break in future. It also adjusts PHP-CS-Fixer config to avoid this issue again.

Additional changes include coverage config and code style fixes.

Replaces #3367

Commits
-------

6a60cdf Fix PHP 7.2 compatibility, add test for legacy controller
  • Loading branch information
javiereguiluz committed Jun 23, 2020
2 parents d2482c8 + 6a60cdf commit fb1ec2b
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.php_cs.cache
composer.lock
.phpunit.result.cache
/phpunit.xml
vendor/*
build/

Expand Down
3 changes: 1 addition & 2 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ return PhpCsFixer\Config::create()
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced', 'strict' => true],
// Part of future @Symfony ruleset in PHP-CS-Fixer To be removed from the config file once upgrading
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
// part of `PHPUnitXYMigration:risky` ruleset, to be enabled when PHPUnit 4.x support will be dropped, as we don't want to rewrite exceptions handling twice
'php_unit_no_expectation_annotation' => false,
'single_line_throw' => false,
))
;
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<exclude>tests/Form/</exclude>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src/</directory>
</whitelist>
</filter>
</phpunit>
6 changes: 3 additions & 3 deletions src/Command/MakeAdminMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class MakeAdminMigrationCommand extends Command
private $projectDir;
/** @var InputInterface */
private $input;
/** @var ConsoleSectionOutput $progressSection */
/** @var ConsoleSectionOutput */
private $progressSection;
private $progressSectionLines = [];
/** @var ConsoleSectionOutput $temporarySection */
/** @var ConsoleSectionOutput */
private $temporarySection;

public function __construct(Migrator $migrator, string $projectDir, string $name = null)
Expand Down Expand Up @@ -64,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->addStep('<info>Step 1/3.</info> Find the file with the EasyAdmin 2 config backup.');
$ea2ConfigBackupPath = $input->getArgument('ea2-backup-file') ?: $this->projectDir.'/easyadmin-config.backup';

if(!$fs->exists($ea2ConfigBackupPath)) {
if (!$fs->exists($ea2ConfigBackupPath)) {
$this->temporarySection->write(sprintf(
'<error> ERROR </error> The config backup file was not found in %s. To generate this file, run the <comment>make:admin:migration</comment> command in your application BEFORE upgrading to EasyAdmin 3 (the command must be run while still using EasyAdmin 2).',
$ea2ConfigBackupPath
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/EasyAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __call($name, $arguments)
throw new \RuntimeException(<<<HELP
If you are seeing this error, you are probably upgrading your application
from EasyAdmin 2 to EasyAdmin 3. The new version of this bundle is a complete
refactorization and most of the previous classes have been moved or deleted.
refactoring and most of the previous classes have been moved or deleted.
One of those removed classes is "EasyAdminController", which was used in EasyAdmin 2
as the base controller of the entire backend. In EasyAdmin 3 each Doctrine entity has
Expand All @@ -31,6 +31,7 @@ public function __call($name, $arguments)
If you need more help, read the EasyAdmin 3 documentation at:
https://symfony.com/doc/master/bundles/EasyAdminBundle/index.html
HELP);
HELP
);
}
}
1 change: 0 additions & 1 deletion src/DependencyInjection/EasyAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\DashboardControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Filter\FilterConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\EventListener\ExceptionListener;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/CrudDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class CrudDto
private $controllerFqcn;
private $pageName;
private $actionName;
/** @var $actions ActionConfigDto */
/** @var ActionConfigDto */
private $actionConfigDto;
private $filters;
private $entityFqcn;
Expand Down
2 changes: 1 addition & 1 deletion src/Dto/UserMenuDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ final class UserMenuDto
private $displayAvatar;
private $name;
private $avatarUrl;
/** @var MenuItem[] $items */
/** @var MenuItem[] */
private $items;

public function __construct()
Expand Down
2 changes: 1 addition & 1 deletion src/Field/Configurator/ArrayConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $c
if (null !== $value && Crud::PAGE_INDEX === $context->getCrud()->getCurrentPage()) {
$values = $field->getValue();
if ($values instanceof PersistentCollection) {
$values = array_map(function($item) { return (string) $item; }, $values->getValues());
$values = array_map(function ($item) { return (string) $item; }, $values->getValues());
}

$field->setFormattedValue(u(', ')->join($values));
Expand Down
2 changes: 1 addition & 1 deletion src/Orm/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function addSearchClause(QueryBuilder $queryBuilder, SearchDto $searchDt
$numAssociatedProperties = \count($associatedProperties);

if ($numAssociatedProperties > 2) {
throw new \RuntimeException(sprintf('Nested associations of more than two levels (e.g. "%s") are not supported yet. We\'ll add support for them in the future, but meanwhile you can only use two-level associations (e.g. "%s")', $propertyName, implode('.', array_slice($associatedProperties, 0, 2))));
throw new \RuntimeException(sprintf('Nested associations of more than two levels (e.g. "%s") are not supported yet. We\'ll add support for them in the future, but meanwhile you can only use two-level associations (e.g. "%s")', $propertyName, implode('.', \array_slice($associatedProperties, 0, 2))));
}

for ($i = 0; $i < $numAssociatedProperties - 1; ++$i) {
Expand Down
18 changes: 18 additions & 0 deletions tests/Controller/EasyAdminControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace EasyCorp\Bundle\EasyAdminBundle\Tests\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class EasyAdminControllerTest extends TestCase
{
public function testCall()
{
$controller = new EasyAdminController();
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('If you are seeing this error, you are probably upgrading your application');
$controller->index();
}
}

0 comments on commit fb1ec2b

Please sign in to comment.