-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Deprecate not registering filters #6976
Merged
jordisala1991
merged 1 commit into
sonata-project:3.x
from
franmomu:prepare_service_locator_filter
Mar 28, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,83 +13,112 @@ | |
|
||
namespace Sonata\AdminBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; | ||
use Sonata\AdminBundle\DependencyInjection\Compiler\AddFilterTypeCompilerPass; | ||
use Sonata\AdminBundle\Filter\FilterFactoryInterface; | ||
use Sonata\AdminBundle\Tests\Fixtures\Filter\BarFilter; | ||
use Sonata\AdminBundle\Tests\Fixtures\Filter\FooFilter; | ||
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
class AddFilterTypeCompilerPassTest extends TestCase | ||
{ | ||
private $filterFactory; | ||
|
||
private $fooFilter; | ||
|
||
private $barFilter; | ||
// NEXT_MAJOR: Uncomment next line. | ||
//use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; | ||
|
||
private $bazFilter; | ||
final class AddFilterTypeCompilerPassTest extends AbstractCompilerPassTestCase | ||
{ | ||
use ExpectDeprecationTrait; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->filterFactory = $this->createMock(Definition::class); | ||
$this->fooFilter = $this->createMock(Definition::class); | ||
$this->barFilter = $this->createMock(Definition::class); | ||
$this->bazFilter = $this->createMock(Definition::class); | ||
parent::setUp(); | ||
|
||
$filterFactoryDefinition = new Definition(FilterFactoryInterface::class, [ | ||
null, | ||
[], | ||
]); | ||
|
||
$this->container | ||
->setDefinition('sonata.admin.builder.filter.factory', $filterFactoryDefinition); | ||
} | ||
|
||
public function testProcess(): void | ||
{ | ||
$containerBuilderMock = $this->createMock(ContainerBuilder::class); | ||
|
||
$containerBuilderMock | ||
->method('getDefinition') | ||
->with($this->anything()) | ||
->willReturnMap([ | ||
['sonata.admin.builder.filter.factory', $this->filterFactory], | ||
['acme.demo.foo_filter', $this->fooFilter], | ||
['acme.demo.bar_filter', $this->barFilter], | ||
['acme.demo.baz_filter', $this->bazFilter], | ||
$fooFilter = new Definition(FooFilter::class); | ||
$fooFilter | ||
->addTag('sonata.admin.filter.type', [ | ||
'alias' => 'foo_filter_alias', | ||
]); | ||
|
||
$containerBuilderMock->expects($this->once()) | ||
->method('findTaggedServiceIds') | ||
->with($this->equalTo('sonata.admin.filter.type')) | ||
->willReturn([ | ||
'acme.demo.foo_filter' => [ | ||
'tag1' => [ | ||
'alias' => 'foo_filter_alias', | ||
], | ||
], | ||
'acme.demo.bar_filter' => [ | ||
'tag1' => [ | ||
'alias' => 'bar_filter_alias', | ||
], | ||
], | ||
'acme.demo.baz_filter' => [ | ||
'tag1' => [ | ||
], | ||
], | ||
]); | ||
$this->container | ||
->setDefinition('acme.demo.foo_filter', $fooFilter); | ||
|
||
$this->fooFilter->method('getClass') | ||
->willReturn('Acme\Filter\FooFilter'); | ||
$barFilter = new Definition(BarFilter::class); | ||
$barFilter | ||
->addTag('sonata.admin.filter.type'); | ||
|
||
$this->barFilter->method('getClass') | ||
->willReturn('Acme\Filter\BarFilter'); | ||
$this->container | ||
->setDefinition('acme.demo.bar_filter', $barFilter); | ||
|
||
$this->bazFilter->method('getClass') | ||
->willReturn('Acme\Filter\BazFilter'); | ||
$this->compile(); | ||
|
||
$this->filterFactory->expects($this->once()) | ||
->method('replaceArgument') | ||
->with(1, $this->equalTo([ | ||
$this->assertContainerBuilderHasServiceDefinitionWithArgument( | ||
'sonata.admin.builder.filter.factory', | ||
1, | ||
[ | ||
'foo_filter_alias' => 'acme.demo.foo_filter', | ||
'Acme\Filter\FooFilter' => 'acme.demo.foo_filter', | ||
'bar_filter_alias' => 'acme.demo.bar_filter', | ||
'Acme\Filter\BarFilter' => 'acme.demo.bar_filter', | ||
'Acme\Filter\BazFilter' => 'acme.demo.baz_filter', | ||
])); | ||
|
||
$extensionsPass = new AddFilterTypeCompilerPass(); | ||
$extensionsPass->process($containerBuilderMock); | ||
FooFilter::class => 'acme.demo.foo_filter', | ||
BarFilter::class => 'acme.demo.bar_filter', | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove legacy group. | ||
* | ||
* @group legacy | ||
*/ | ||
public function testServicesMustHaveAClassName(): void | ||
{ | ||
$filter = new Definition('not_existing_class'); | ||
$filter | ||
->addTag('sonata.admin.filter.type'); | ||
|
||
$this->container | ||
->setDefinition('acme.demo.foo_filter', $filter); | ||
|
||
// NEXT_MAJOR: Remove deprecation and uncomment exception. | ||
$this->expectDeprecation('Not declaring a filter with an existing class name is deprecated since sonata-project/admin-bundle 3.x and will not work in 4.0. You MUST register a service with an existing class name for service "acme.demo.foo_filter".'); | ||
// $this->expectException(InvalidArgumentException::class); | ||
// $this->expectExceptionMessage('Class "not_existing_class" used for service "acme.demo.foo_filter" cannot be found.'); | ||
|
||
$this->compile(); | ||
} | ||
|
||
/** | ||
* NEXT_MAJOR: Remove legacy group. | ||
* | ||
* @group legacy | ||
*/ | ||
public function testServicesMustImplementFilterInterface(): void | ||
{ | ||
$filter = new Definition(\stdClass::class); | ||
$filter | ||
->addTag('sonata.admin.filter.type'); | ||
|
||
$this->container | ||
->setDefinition('acme.demo.foo_filter', $filter); | ||
|
||
// NEXT_MAJOR: Remove deprecation and uncomment exception. | ||
$this->expectDeprecation('Registering service "acme.demo.foo_filter" without implementing interface "Sonata\AdminBundle\Filter\FilterInterface" is deprecated since sonata-project/admin-bundle 3.x and will be mandatory in 4.0.'); | ||
// $this->expectException(InvalidArgumentException::class); | ||
// $this->expectExceptionMessage('Service "acme.demo.foo_filter" MUST implement interface "Sonata\AdminBundle\Filter\FilterInterface".'); | ||
|
||
$this->compile(); | ||
} | ||
|
||
protected function registerCompilerPass(ContainerBuilder $container): void | ||
{ | ||
$container->addCompilerPass(new AddFilterTypeCompilerPass()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\AdminBundle\Tests\Fixtures\Filter; | ||
|
||
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; | ||
use Sonata\AdminBundle\Filter\Filter; | ||
use Sonata\AdminBundle\Form\Type\Filter\DefaultType; | ||
|
||
final class BarFilter extends Filter | ||
{ | ||
/** | ||
* NEXT_MAJOR: Remove this method. | ||
*/ | ||
public function filter(ProxyQueryInterface $query, $alias, $field, $value): void | ||
{ | ||
} | ||
|
||
// NEXT_MAJOR: Add type declarations | ||
public function apply($query, $value): void | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Next_major, add typehint ? |
||
{ | ||
} | ||
|
||
public function getDefaultOptions(): array | ||
{ | ||
return ['bar' => 'bar']; | ||
} | ||
|
||
public function getRenderSettings(): array | ||
{ | ||
return [DefaultType::class, [ | ||
'label' => 'label', | ||
]]; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This blank line should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is
php-cs-fixer
who adds that line.