"Fossies" - the Fresh Open Source Software Archive

Member "contao-4.4.48/core-bundle/tests/DependencyInjection/Compiler/AddSessionBagsPassTest.php" (2 Apr 2020, 2242 Bytes) of package /linux/www/contao-4.4.48.tar.gz:


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 Contao.
    5  *
    6  * (c) Leo Feyer
    7  *
    8  * @license LGPL-3.0-or-later
    9  */
   10 
   11 namespace Contao\CoreBundle\Tests\DependencyInjection\Compiler;
   12 
   13 use Contao\CoreBundle\DependencyInjection\Compiler\AddSessionBagsPass;
   14 use Contao\CoreBundle\Session\Attribute\ArrayAttributeBag;
   15 use PHPUnit\Framework\TestCase;
   16 use Symfony\Component\DependencyInjection\ContainerBuilder;
   17 use Symfony\Component\DependencyInjection\Definition;
   18 use Symfony\Component\HttpFoundation\Session\Session;
   19 
   20 /**
   21  * Tests the AddSessionBagsPass class.
   22  *
   23  * @author Leo Feyer <https:/github.com/leofeyer>
   24  */
   25 class AddSessionBagsPassTest extends TestCase
   26 {
   27     /**
   28      * Tests adding the session bags.
   29      */
   30     public function testAddsTheSessionBags()
   31     {
   32         $container = new ContainerBuilder();
   33         $container->setDefinition('session', new Definition(Session::class));
   34 
   35         $container->setDefinition(
   36             'contao.session.contao_backend',
   37             new Definition(ArrayAttributeBag::class)
   38         );
   39 
   40         $container->setDefinition(
   41             'contao.session.contao_frontend',
   42             new Definition(ArrayAttributeBag::class)
   43         );
   44 
   45         $pass = new AddSessionBagsPass();
   46         $pass->process($container);
   47 
   48         $methodCalls = $container->findDefinition('session')->getMethodCalls();
   49 
   50         $this->assertCount(2, $methodCalls);
   51         $this->assertSame('registerBag', $methodCalls[0][0]);
   52         $this->assertSame('registerBag', $methodCalls[1][0]);
   53         $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $methodCalls[0][1][0]);
   54         $this->assertInstanceOf('Symfony\Component\DependencyInjection\Reference', $methodCalls[1][1][0]);
   55         $this->assertSame('contao.session.contao_backend', (string) $methodCalls[0][1][0]);
   56         $this->assertSame('contao.session.contao_frontend', (string) $methodCalls[1][1][0]);
   57     }
   58 
   59     /**
   60      * Tests processing the pass without a session.
   61      */
   62     public function testDoesNotAddsTheSessionBagsIfThereIsNoSession()
   63     {
   64         $container = new ContainerBuilder();
   65 
   66         $pass = new AddSessionBagsPass();
   67         $pass->process($container);
   68 
   69         $this->assertFalse($container->hasDefinition('session'));
   70     }
   71 }