‪TYPO3CMS  10.4
MiddlewareStackResolverTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use ArrayObject;
21 use Prophecy\Argument;
22 use Psr\Container\ContainerInterface;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
31 class ‪MiddlewareStackResolverTest extends UnitTestCase
32 {
37  {
38  $middlewares = new ArrayObject(array_replace_recursive(
39  [],
40  require __DIR__ . '/Fixtures/Package1/Configuration/RequestMiddlewares.php',
41  require __DIR__ . '/Fixtures/Package2/Configuration/RequestMiddlewares.php'
42  ));
43  $containerProphecy = $this->prophesize();
44  $containerProphecy->willImplement(ContainerInterface::class);
45  $containerProphecy->get('middlewares')->willReturn($middlewares);
46  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
47  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
48  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
49  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
50  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
51 
52  $subject = new ‪MiddlewareStackResolver(
53  $containerProphecy->reveal(),
54  $dependencyOrderingServiceProphecy->reveal(),
55  $phpFrontendCacheProphecy->reveal()
56  );
57  $expected = [
58  'secondMiddleware' => 'anotherClassName',
59  'firstMiddleware' => 'aClassName',
60  ];
61  self::assertEquals($expected, $subject->resolve('testStack'));
62  }
63 
68  {
69  $middlewares = new ArrayObject();
70  $containerProphecy = $this->prophesize();
71  $containerProphecy->willImplement(ContainerInterface::class);
72  $containerProphecy->get('middlewares')->willReturn($middlewares);
73  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
74  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
75  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
76  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
77  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
78 
79  $subject = new ‪MiddlewareStackResolver(
80  $containerProphecy->reveal(),
81  $dependencyOrderingServiceProphecy->reveal(),
82  $phpFrontendCacheProphecy->reveal()
83  );
84  // empty array expected
85  $expected = [];
86  self::assertEquals($expected, $subject->resolve('testStack'));
87  }
88 
93  {
94  $middlewares = new ArrayObject(array_replace_recursive(
95  [],
96  require __DIR__ . '/Fixtures/Package1/Configuration/RequestMiddlewares.php',
97  require __DIR__ . '/Fixtures/Package2Disables1/Configuration/RequestMiddlewares.php'
98  ));
99  $containerProphecy = $this->prophesize();
100  $containerProphecy->willImplement(ContainerInterface::class);
101  $containerProphecy->get('middlewares')->willReturn($middlewares);
102  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
103  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
104  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
105  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
106  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
107 
108  $subject = new ‪MiddlewareStackResolver(
109  $containerProphecy->reveal(),
110  $dependencyOrderingServiceProphecy->reveal(),
111  $phpFrontendCacheProphecy->reveal()
112  );
113  $expected = [
114  // firstMiddleware is missing, RequestMiddlewares.php of Package2 sets disables=true on firstMiddleware
115  'secondMiddleware' => 'anotherClassName',
116  ];
117  self::assertEquals($expected, $subject->resolve('testStack'));
118  }
119 
124  {
125  $middlewares = new ArrayObject(array_replace_recursive(
126  [],
127  require __DIR__ . '/Fixtures/Package1/Configuration/RequestMiddlewares.php',
128  require __DIR__ . '/Fixtures/Package2Replaces1/Configuration/RequestMiddlewares.php'
129  ));
130  $containerProphecy = $this->prophesize();
131  $containerProphecy->willImplement(ContainerInterface::class);
132  $containerProphecy->get('middlewares')->willReturn($middlewares);
133  $dependencyOrderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
134  $dependencyOrderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
135  $phpFrontendCacheProphecy = $this->prophesize(PhpFrontend::class);
136  $phpFrontendCacheProphecy->has(Argument::cetera())->willReturn(false);
137  $phpFrontendCacheProphecy->set(Argument::cetera())->willReturn(false);
138 
139  $subject = new ‪MiddlewareStackResolver(
140  $containerProphecy->reveal(),
141  $dependencyOrderingServiceProphecy->reveal(),
142  $phpFrontendCacheProphecy->reveal()
143  );
144  $expected = [
145  // firstMiddleware has been replaced, RequestMiddlewares.php of $package2 sets a new value for firstMiddleware
146  'firstMiddleware' => 'replacedClassName',
147  'secondMiddleware' => 'anotherClassName',
148  ];
149  self::assertEquals($expected, $subject->resolve('testStack'));
150  }
151 }
‪TYPO3\CMS\Core\Tests\Unit\Http
Definition: ApplicationTypeTest.php:16
‪TYPO3\CMS\Core\Cache\Frontend\PhpFrontend
Definition: PhpFrontend.php:25
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveReturnsMiddlewareStack
‪resolveReturnsMiddlewareStack()
Definition: MiddlewareStackResolverTest.php:36
‪TYPO3\CMS\Core\Http\MiddlewareStackResolver
Definition: MiddlewareStackResolver.php:33
‪TYPO3\CMS\Core\Service\DependencyOrderingService
Definition: DependencyOrderingService.php:32
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest
Definition: MiddlewareStackResolverTest.php:32
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveAllowsDisablingAMiddleware
‪resolveAllowsDisablingAMiddleware()
Definition: MiddlewareStackResolverTest.php:92
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveAllowsReplacingAMiddleware
‪resolveAllowsReplacingAMiddleware()
Definition: MiddlewareStackResolverTest.php:123
‪TYPO3\CMS\Core\Tests\Unit\Http\MiddlewareStackResolverTest\resolveReturnsEmptyMiddlewareStackForZeroPackages
‪resolveReturnsEmptyMiddlewareStackForZeroPackages()
Definition: MiddlewareStackResolverTest.php:67