From d1001d4bac9d3f87dbc8506856745f3603818939 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Fri, 3 Feb 2017 16:24:41 +0100 Subject: [PATCH] [SecurityBundle] Add AutowiringTypesTest --- .../Tests/Functional/AutowiringTypesTest.php | 17 --------- .../AutowiringTypes/AutowiredServices.php | 10 +---- .../app/AutowiringTypes/bundles.php | 2 - .../Functional/app/AutowiringTypes/config.yml | 7 ---- .../Bundle/FrameworkBundle/composer.json | 5 +-- .../Tests/Functional/AutowiringTypesTest.php | 38 +++++++++++++++++++ .../AutowiringBundle/AutowiredServices.php | 29 ++++++++++++++ .../AutowiringBundle/AutowiringBundle.php | 18 +++++++++ .../app/AutowiringTypes/bundles.php | 16 ++++++++ .../Functional/app/AutowiringTypes/config.yml | 14 +++++++ 10 files changed, 118 insertions(+), 38 deletions(-) create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/AutowiringTypesTest.php create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiredServices.php create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiringBundle.php create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/bundles.php create mode 100644 src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/config.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php index 42d8eab1b2346..fa92514a9c14c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/AutowiringTypesTest.php @@ -14,8 +14,6 @@ use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\CachedReader; use Symfony\Component\Cache\Adapter\FilesystemAdapter; -use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; -use Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager; use Symfony\Component\Templating\EngineInterface as ComponentEngineInterface; use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher; use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher; @@ -66,21 +64,6 @@ public function testEventDispatcherAutowiring() $this->assertInstanceOf(TraceableEventDispatcher::class, $autowiredServices->getDispatcher(), 'The debug.event_dispatcher service should be injected if the debug is enabled'); } - public function testAccessDecisionManagerAutowiring() - { - static::bootKernel(array('debug' => false)); - $container = static::$kernel->getContainer(); - - $autowiredServices = $container->get('test.autowiring_types.autowired_services'); - $this->assertInstanceOf(AccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The security.access.decision_manager service should be injected in debug mode'); - - static::bootKernel(array('debug' => true)); - $container = static::$kernel->getContainer(); - - $autowiredServices = $container->get('test.autowiring_types.autowired_services'); - $this->assertInstanceOf(TraceableAccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The debug.security.access.decision_manager service should be injected in non-debug mode'); - } - public function testCacheAutowiring() { static::bootKernel(); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php index ff2c64b42c730..7168e4902c53b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/TestBundle/AutowiringTypes/AutowiredServices.php @@ -14,7 +14,6 @@ use Doctrine\Common\Annotations\Reader; use Psr\Cache\CacheItemPoolInterface; use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface as FrameworkBundleEngineInterface; -use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; use Symfony\Component\Templating\EngineInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -24,16 +23,14 @@ class AutowiredServices private $frameworkBundleEngine; private $engine; private $dispatcher; - private $accessDecisionManager; private $cachePool; - public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine, EventDispatcherInterface $dispatcher, AccessDecisionManagerInterface $accessDecisionManager, CacheItemPoolInterface $cachePool) + public function __construct(Reader $annotationReader = null, FrameworkBundleEngineInterface $frameworkBundleEngine, EngineInterface $engine, EventDispatcherInterface $dispatcher, CacheItemPoolInterface $cachePool) { $this->annotationReader = $annotationReader; $this->frameworkBundleEngine = $frameworkBundleEngine; $this->engine = $engine; $this->dispatcher = $dispatcher; - $this->accessDecisionManager = $accessDecisionManager; $this->cachePool = $cachePool; } @@ -57,11 +54,6 @@ public function getDispatcher() return $this->dispatcher; } - public function getAccessDecisionManager() - { - return $this->accessDecisionManager; - } - public function getCachePool() { return $this->cachePool; diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php index d6d74a53cb25b..a73987bcc986a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/bundles.php @@ -11,10 +11,8 @@ use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; -use Symfony\Bundle\SecurityBundle\SecurityBundle; return array( new FrameworkBundle(), - new SecurityBundle(), new TestBundle(), ); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml index 3bf3a9302d7aa..a44078cc499b3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Functional/app/AutowiringTypes/config.yml @@ -8,10 +8,3 @@ services: framework: templating: engines: ['php'] -security: - providers: - dummy: - memory: ~ - firewalls: - dummy: - security: false diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index 068cd6a039985..e658a3dab6742 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -40,7 +40,7 @@ "symfony/css-selector": "~2.8|~3.0", "symfony/dom-crawler": "~2.8|~3.0", "symfony/polyfill-intl-icu": "~1.0", - "symfony/security": "~3.3", + "symfony/security": "~2.8|~3.0", "symfony/form": "~2.8.16|~3.1.9|^3.2.2", "symfony/expression-language": "~2.8|~3.0", "symfony/process": "~2.8|~3.0", @@ -55,8 +55,7 @@ "doctrine/annotations": "~1.0", "phpdocumentor/reflection-docblock": "^3.0", "twig/twig": "~1.26|~2.0", - "sensio/framework-extra-bundle": "^3.0.2", - "symfony/security-bundle": "~3.3" + "sensio/framework-extra-bundle": "^3.0.2" }, "conflict": { "phpdocumentor/reflection-docblock": "<3.0", diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AutowiringTypesTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AutowiringTypesTest.php new file mode 100644 index 0000000000000..a0bee3c01c1ca --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/AutowiringTypesTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Tests\Functional; + +use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; +use Symfony\Component\Security\Core\Authorization\TraceableAccessDecisionManager; + +class AutowiringTypesTest extends WebTestCase +{ + public function testAccessDecisionManagerAutowiring() + { + static::bootKernel(array('debug' => false)); + $container = static::$kernel->getContainer(); + + $autowiredServices = $container->get('test.autowiring_types.autowired_services'); + $this->assertInstanceOf(AccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The security.access.decision_manager service should be injected in debug mode'); + + static::bootKernel(array('debug' => true)); + $container = static::$kernel->getContainer(); + + $autowiredServices = $container->get('test.autowiring_types.autowired_services'); + $this->assertInstanceOf(TraceableAccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The debug.security.access.decision_manager service should be injected in non-debug mode'); + } + + protected static function createKernel(array $options = array()) + { + return parent::createKernel(array('test_case' => 'AutowiringTypes') + $options); + } +} diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiredServices.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiredServices.php new file mode 100644 index 0000000000000..30aa62f1f66ec --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiredServices.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AutowiringBundle; + +use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; + +class AutowiredServices +{ + private $accessDecisionManager; + + public function __construct(AccessDecisionManagerInterface $accessDecisionManager) + { + $this->accessDecisionManager = $accessDecisionManager; + } + + public function getAccessDecisionManager() + { + return $this->accessDecisionManager; + } +} diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiringBundle.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiringBundle.php new file mode 100644 index 0000000000000..d57031a018fe9 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/Bundle/AutowiringBundle/AutowiringBundle.php @@ -0,0 +1,18 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AutowiringBundle; + +use Symfony\Component\HttpKernel\Bundle\Bundle; + +class AutowiringBundle extends Bundle +{ +} diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/bundles.php b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/bundles.php new file mode 100644 index 0000000000000..68e5afb125f85 --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/bundles.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return array( + new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), + new Symfony\Bundle\SecurityBundle\SecurityBundle(), + new Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AutowiringBundle\AutowiringBundle(), +); diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/config.yml b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/config.yml new file mode 100644 index 0000000000000..bb3ef5a2dc70f --- /dev/null +++ b/src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/AutowiringTypes/config.yml @@ -0,0 +1,14 @@ +imports: + - { resource: ../config/framework.yml } + +services: + test.autowiring_types.autowired_services: + class: Symfony\Bundle\SecurityBundle\Tests\Functional\Bundle\AutowiringBundle\AutowiredServices + autowire: true +security: + providers: + dummy: + memory: ~ + firewalls: + dummy: + security: false