"Fossies" - the Fresh Open Source Software Archive

Member "Symfony/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php" (30 Mar 2020, 1879 Bytes) of package /linux/www/Symfony_Standard_Vendors_3.4.39.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 <?php
    2 
    3 /*
    4  * This file is part of the Symfony package.
    5  *
    6  * (c) Fabien Potencier <fabien@symfony.com>
    7  *
    8  * For the full copyright and license information, please view the LICENSE
    9  * file that was distributed with this source code.
   10  */
   11 
   12 namespace Symfony\Bundle\FrameworkBundle\Tests\Controller;
   13 
   14 use Psr\Container\ContainerInterface;
   15 use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
   16 
   17 class AbstractControllerTest extends ControllerTraitTest
   18 {
   19     protected function createController()
   20     {
   21         return new TestAbstractController();
   22     }
   23 }
   24 
   25 class TestAbstractController extends AbstractController
   26 {
   27     use TestControllerTrait;
   28 
   29     private $throwOnUnexpectedService;
   30 
   31     public function __construct($throwOnUnexpectedService = true)
   32     {
   33         $this->throwOnUnexpectedService = $throwOnUnexpectedService;
   34     }
   35 
   36     public function setContainer(ContainerInterface $container)
   37     {
   38         if (!$this->throwOnUnexpectedService) {
   39             return parent::setContainer($container);
   40         }
   41 
   42         $expected = self::getSubscribedServices();
   43 
   44         foreach ($container->getServiceIds() as $id) {
   45             if ('service_container' === $id) {
   46                 continue;
   47             }
   48             if (!isset($expected[$id])) {
   49                 throw new \UnexpectedValueException(sprintf('Service "%s" is not expected, as declared by "%s::getSubscribedServices()".', $id, AbstractController::class));
   50             }
   51             $type = substr($expected[$id], 1);
   52             if (!$container->get($id) instanceof $type) {
   53                 throw new \UnexpectedValueException(sprintf('Service "%s" is expected to be an instance of "%s", as declared by "%s::getSubscribedServices()".', $id, $type, AbstractController::class));
   54             }
   55         }
   56 
   57         return parent::setContainer($container);
   58     }
   59 
   60     public function fooAction()
   61     {
   62     }
   63 }