• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 10643656040

31 Aug 2024 07:58AM UTC coverage: 7.668% (+0.001%) from 7.667%
10643656040

push

github

web-flow
test: remove phpunitbundle (#6567)

0 of 2 new or added lines in 1 file covered. (0.0%)

15 existing lines in 1 file now uncovered.

12514 of 163200 relevant lines covered (7.67%)

22.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/tests/Fixtures/app/AppKernel.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.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
declare(strict_types=1);
13

14
use ApiPlatform\Symfony\Bundle\ApiPlatformBundle;
15
use ApiPlatform\Tests\Behat\DoctrineContext;
16
use ApiPlatform\Tests\Fixtures\TestBundle\Document\User as UserDocument;
17
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\User;
18
use ApiPlatform\Tests\Fixtures\TestBundle\TestBundle;
19
use Doctrine\Bundle\DoctrineBundle\ConnectionFactory;
20
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
21
use Doctrine\Bundle\MongoDBBundle\Command\TailCursorDoctrineODMCommand;
22
use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle;
23
use FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle;
24
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
25
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
26
use Symfony\Bundle\MakerBundle\MakerBundle;
27
use Symfony\Bundle\MercureBundle\MercureBundle;
28
use Symfony\Bundle\SecurityBundle\SecurityBundle;
29
use Symfony\Bundle\TwigBundle\TwigBundle;
30
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
31
use Symfony\Component\Config\Loader\LoaderInterface;
32
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
33
use Symfony\Component\DependencyInjection\ContainerBuilder;
34
use Symfony\Component\ErrorHandler\ErrorRenderer\ErrorRendererInterface;
35
use Symfony\Component\HttpClient\Messenger\PingWebhookMessageHandler;
36
use Symfony\Component\HttpFoundation\Session\SessionFactory;
37
use Symfony\Component\HttpKernel\Kernel;
38
use Symfony\Component\PasswordHasher\Hasher\NativePasswordHasher;
39
use Symfony\Component\Security\Core\Authorization\Strategy\AccessDecisionStrategyInterface;
40
use Symfony\Component\Security\Core\User\User as SymfonyCoreUser;
41
use Symfony\Component\Security\Core\User\UserInterface;
42

43
/**
44
 * AppKernel for tests.
45
 *
46
 * @author Kévin Dunglas <dunglas@gmail.com>
47
 */
48
class AppKernel extends Kernel
49
{
50
    use MicroKernelTrait;
51

52
    public function __construct(string $environment, bool $debug)
53
    {
54
        parent::__construct($environment, $debug);
×
55

56
        // patch for behat/symfony2-extension not supporting %env(APP_ENV)%
57
        $this->environment = $_SERVER['APP_ENV'] ?? $environment;
×
58
    }
59

60
    public function registerBundles(): array
61
    {
62
        $bundles = [
×
63
            new ApiPlatformBundle(),
×
64
            new TwigBundle(),
×
65
            new DoctrineBundle(),
×
66
            new MercureBundle(),
×
67
            new SecurityBundle(),
×
68
            new WebProfilerBundle(),
×
69
            new FrameworkBundle(),
×
70
            new MakerBundle(),
×
71
        ];
×
72

73
        if (null === ($_ENV['APP_PHPUNIT'] ?? null)) {
×
74
            $bundles[] = new FriendsOfBehatSymfonyExtensionBundle();
×
75
        }
76

77
        if (class_exists(DoctrineMongoDBBundle::class)) {
×
78
            $bundles[] = new DoctrineMongoDBBundle();
×
79
        }
80

81
        $bundles[] = new TestBundle();
×
82

83
        return $bundles;
×
84
    }
85

86
    public function shutdown(): void
87
    {
NEW
88
        parent::shutdown();
×
NEW
89
        restore_exception_handler();
×
90
    }
91

92
    public function getProjectDir(): string
93
    {
94
        return __DIR__;
×
95
    }
96

97
    protected function configureRoutes($routes): void
98
    {
99
        $routes->import(__DIR__."/config/routing_{$this->getEnvironment()}.yml");
×
100
    }
101

102
    protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void
103
    {
104
        $c->setParameter('kernel.project_dir', __DIR__);
×
105

106
        $loader->load(__DIR__."/config/config_{$this->getEnvironment()}.yml");
×
107

108
        $c->getDefinition(DoctrineContext::class)->setArgument('$passwordHasher', class_exists(NativePasswordHasher::class) ? 'security.user_password_encoder' : 'security.user_password_hasher');
×
109

110
        $messengerConfig = [
×
111
            'default_bus' => 'messenger.bus.default',
×
112
            'buses' => [
×
113
                'messenger.bus.default' => ['default_middleware' => 'allow_no_handlers'],
×
114
            ],
×
115
        ];
×
116

117
        $cookie = ['cookie_secure' => true, 'cookie_samesite' => 'lax', 'handler_id' => 'session.handler.native_file'];
×
118
        // This class is introduced in Symfony 6.4 just using it to use the new configuration and to avoid unnecessary deprecations
119
        if (class_exists(PingWebhookMessageHandler::class)) {
×
120
            $config = [
×
121
                'secret' => 'dunglas.fr',
×
122
                'validation' => ['enable_attributes' => true, 'email_validation_mode' => 'html5'],
×
123
                'serializer' => ['enable_attributes' => true],
×
124
                'test' => null,
×
125
                'session' => class_exists(SessionFactory::class) ? ['storage_factory_id' => 'session.storage.factory.mock_file'] + $cookie : ['storage_id' => 'session.storage.mock_file'] + $cookie,
×
126
                'profiler' => [
×
127
                    'enabled' => true,
×
128
                    'collect' => false,
×
129
                ],
×
130
                'php_errors' => ['log' => true],
×
131
                'messenger' => $messengerConfig,
×
132
                'router' => ['utf8' => true],
×
133
                'http_method_override' => false,
×
134
                'annotations' => false,
×
135
                'handle_all_throwables' => true,
×
136
                'uid' => ['default_uuid_version' => 7, 'time_based_uuid_version' => 7],
×
137
            ];
×
138
        } else {
139
            $config = [
×
140
                'secret' => 'dunglas.fr',
×
141
                'validation' => ['enable_annotations' => true],
×
142
                'serializer' => ['enable_annotations' => true],
×
143
                'test' => null,
×
144
                'session' => class_exists(SessionFactory::class) ? ['storage_factory_id' => 'session.storage.factory.mock_file'] : ['storage_id' => 'session.storage.mock_file'],
×
145
                'profiler' => [
×
146
                    'enabled' => true,
×
147
                    'collect' => false,
×
148
                ],
×
149
                'messenger' => $messengerConfig,
×
150
                'router' => ['utf8' => true],
×
151
                'http_method_override' => false,
×
152
                'annotations' => false,
×
153
            ];
×
154
        }
155

156
        $c->prependExtensionConfig('framework', $config);
×
157

158
        $alg = class_exists(NativePasswordHasher::class, false) || class_exists('Symfony\Component\Security\Core\Encoder\NativePasswordEncoder') ? 'auto' : 'bcrypt';
×
159
        $securityConfig = [
×
160
            class_exists(NativePasswordHasher::class) ? 'password_hashers' : 'encoders' => [
×
161
                User::class => $alg,
×
162
                UserDocument::class => $alg,
×
163
                // Don't use plaintext in production!
164
                UserInterface::class => 'plaintext',
×
165
            ],
×
166
            'providers' => [
×
167
                'chain_provider' => [
×
168
                    'chain' => [
×
169
                        'providers' => ['in_memory', 'entity'],
×
170
                    ],
×
171
                ],
×
172
                'in_memory' => [
×
173
                    'memory' => [
×
174
                        'users' => [
×
175
                            'dunglas' => ['password' => 'kevin', 'roles' => 'ROLE_USER'],
×
176
                            'admin' => ['password' => 'kitten', 'roles' => 'ROLE_ADMIN'],
×
177
                        ],
×
178
                    ],
×
179
                ],
×
180
                'entity' => [
×
181
                    'entity' => [
×
182
                        'class' => User::class,
×
183
                        'property' => 'email',
×
184
                    ],
×
185
                ],
×
186
            ],
×
187
            'firewalls' => [
×
188
                'dev' => [
×
189
                    'pattern' => '^/(_(profiler|wdt|error)|css|images|js)/',
×
190
                    'security' => false,
×
191
                ],
×
192
                'default' => [
×
193
                    'provider' => 'chain_provider',
×
194
                    'stateless' => true,
×
195
                    'http_basic' => null,
×
196
                    'anonymous' => null,
×
197
                    'entry_point' => 'app.security.authentication_entrypoint',
×
198
                ],
×
199
            ],
×
200
            'access_control' => [
×
201
                ['path' => '^/', 'role' => interface_exists(AccessDecisionStrategyInterface::class) ? 'PUBLIC_ACCESS' : 'IS_AUTHENTICATED_ANONYMOUSLY'],
×
202
            ],
×
203
        ];
×
204

205
        if (!class_exists(SymfonyCoreUser::class)) {
×
206
            $securityConfig['role_hierarchy'] = [
×
207
                'ROLE_ADMIN' => ['ROLE_USER'],
×
208
            ];
×
209
            unset($securityConfig['firewalls']['default']['anonymous']);
×
210
            $securityConfig['firewalls']['default']['http_basic'] = [
×
211
                'realm' => 'Secured Area',
×
212
            ];
×
213
        }
214

215
        if (class_exists(NativePasswordHasher::class)) {
×
216
            unset($securityConfig['firewalls']['default']['anonymous']);
×
217
        }
218

219
        $c->prependExtensionConfig('security', $securityConfig);
×
220

221
        if (class_exists(DoctrineMongoDBBundle::class)) {
×
222
            $c->prependExtensionConfig('doctrine_mongodb', [
×
223
                'connections' => [
×
224
                    'default' => null,
×
225
                ],
×
226
                'document_managers' => [
×
227
                    'default' => [
×
228
                        'auto_mapping' => true,
×
229
                    ],
×
230
                ],
×
231
            ]);
×
232
        }
233

234
        $twigConfig = ['strict_variables' => '%kernel.debug%'];
×
235
        if (interface_exists(ErrorRendererInterface::class)) {
×
236
            $twigConfig['exception_controller'] = null;
×
237
        }
238
        $c->prependExtensionConfig('twig', $twigConfig);
×
239

240
        $useSymfonyListeners = (bool) ($_SERVER['USE_SYMFONY_LISTENERS'] ?? false);
×
241

242
        $c->prependExtensionConfig('api_platform', [
×
243
            'mapping' => [
×
244
                'paths' => ['%kernel.project_dir%/../TestBundle/Resources/config/api_resources'],
×
245
            ],
×
246
            'graphql' => [
×
247
                'graphql_playground' => false,
×
248
            ],
×
249
            'use_symfony_listeners' => $useSymfonyListeners,
×
250
            'defaults' => [
×
251
                'pagination_client_enabled' => true,
×
252
                'pagination_client_items_per_page' => true,
×
253
                'pagination_client_partial' => true,
×
254
                'pagination_items_per_page' => 3,
×
255
                'cache_headers' => [
×
256
                    'max_age' => 60,
×
257
                    'shared_max_age' => 3600,
×
258
                    'vary' => ['Accept', 'Cookie'],
×
259
                    'public' => true,
×
260
                ],
×
261
                'normalization_context' => ['skip_null_values' => false],
×
262
                'extra_properties' => [
×
263
                    'standard_put' => true,
×
264
                ],
×
265
            ],
×
266
        ]);
×
267

268
        // TODO: remove this check and move this config in config_common.yml when dropping support for DoctrineBundle <2.10
269
        if (defined(ConnectionFactory::class.'::DEFAULT_SCHEME_MAP')) {
×
270
            $c->prependExtensionConfig('doctrine', [
×
271
                'orm' => [
×
272
                    'report_fields_where_declared' => true,
×
273
                    'controller_resolver' => ['auto_mapping' => false],
×
274
                    'enable_lazy_ghost_objects' => true,
×
275
                ],
×
276
            ]);
×
277
        }
278

279
        $loader->load(__DIR__.'/config/config_swagger.php');
×
280

281
        // We reduce the amount of resources to the strict minimum to speed up tests
282
        if (null !== ($_ENV['APP_PHPUNIT'] ?? null)) {
×
283
            $loader->load(__DIR__.'/config/phpunit.yml');
×
284
        }
285

286
        if ('mongodb' === $this->environment) {
×
287
            $c->prependExtensionConfig('api_platform', [
×
288
                'mapping' => [
×
289
                    'paths' => ['%kernel.project_dir%/../TestBundle/Resources/config/api_resources_odm'],
×
290
                ],
×
291
            ]);
×
292

293
            return;
×
294
        }
295

296
        $c->prependExtensionConfig('api_platform', [
×
297
            'mapping' => [
×
298
                'paths' => ['%kernel.project_dir%/../TestBundle/Resources/config/api_resources_orm'],
×
299
            ],
×
300
        ]);
×
301
    }
302

303
    protected function build(ContainerBuilder $container): void
304
    {
305
        $container->addCompilerPass(new class implements CompilerPassInterface {
×
306
            public function process(ContainerBuilder $container): void
307
            {
308
                if ($container->hasDefinition(TailCursorDoctrineODMCommand::class)) { // @phpstan-ignore-line
×
309
                    // Deprecated command triggering a Symfony depreciation
310
                    $container->removeDefinition(TailCursorDoctrineODMCommand::class); // @phpstan-ignore-line
×
311
                }
312
            }
313
        });
×
314
    }
315
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc