Completed
Push — master ( 1e9a17...80ace9 )
by David
11:17
created

HttplugExtensionTest   B

Complexity

Total Complexity 43

Size/Duplication

Total Lines 558
Duplicated Lines 38.53 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 43
lcom 1
cbo 6
dl 215
loc 558
rs 8.96
c 0
b 0
f 0

28 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A getContainerExtensions() 0 6 1
A testConstants() 0 4 1
A testConfigLoadDefault() 3 8 2
A testConfigLoadClass() 0 14 2
A testConfigLoadService() 3 15 2
B testClientPlugins() 0 91 2
A testNoProfilingWhenToolbarIsDisabled() 18 18 1
A testNoProfilingWhenNotInDebugMode() 16 16 1
A testProfilingWhenToolbarIsSpecificallyOn() 19 19 1
A testOverrideProfilingFormatter() 0 13 1
A testCachePluginConfigCacheKeyGeneratorReference() 20 20 1
A testCachePluginConfigCacheListenersDefinition() 22 22 1
A testContentTypePluginAllowedOptions() 0 25 1
A testUsingServiceKeyForClients() 0 14 1
A verifyProfilingDisabled() 0 13 2
A testClientShouldHaveDefaultVisibility() 0 18 2
A testFlexibleClientShouldBePrivateByDefault() 13 13 1
A testHttpMethodsClientShouldBePrivateByDefault() 13 13 1
A testBatchClientShouldBePrivateByDefault() 13 13 1
A testClientCanBePublic() 18 18 2
A testFlexibleClientCanBePublic() 19 19 2
A testHttpMethodsClientCanBePublic() 19 19 2
A testBatchClientCanBePublic() 19 19 2
A testClientIsTaggedWithHttplugClientTag() 0 18 1
A testVcrPluginConfiguration() 0 20 5
A testIsNotLoadedUnlessNeeded() 0 9 2
A provideVcrPluginConfig() 0 32 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like HttplugExtensionTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use HttplugExtensionTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\HttplugBundle\Tests\Unit\DependencyInjection;
6
7
use Http\Adapter\Guzzle7\Client;
8
use Http\Client\HttpClient;
9
use Http\Client\Plugin\Vcr\Recorder\InMemoryRecorder;
10
use Http\HttplugBundle\Collector\PluginClientFactoryListener;
11
use Http\HttplugBundle\DependencyInjection\HttplugExtension;
12
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
13
use Symfony\Component\DependencyInjection\Reference;
14
use Symfony\Component\HttpKernel\Kernel;
15
16
/**
17
 * @author David Buchmann <[email protected]>
18
 * @author Tobias Nyholm <[email protected]>
19
 */
20
class HttplugExtensionTest extends AbstractExtensionTestCase
21
{
22
    protected function setUp(): void
23
    {
24
        parent::setUp();
25
26
        $this->setParameter('kernel.debug', true);
27
    }
28
29
    protected function getContainerExtensions(): array
30
    {
31
        return [
32
            new HttplugExtension(),
33
        ];
34
    }
35
36
    public function testConstants(): void
37
    {
38
        self::assertSame('httplug.client', HttplugExtension::HTTPLUG_CLIENT_TAG);
39
    }
40
41
    public function testConfigLoadDefault(): void
42
    {
43
        $this->load();
44
45 View Code Duplication
        foreach (['client', 'message_factory', 'uri_factory', 'stream_factory'] as $type) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
            $this->assertContainerBuilderHasAlias("httplug.$type", "httplug.$type.default");
47
        }
48
    }
49
50
    public function testConfigLoadClass(): void
51
    {
52
        if (!class_exists(Client::class)) {
53
            $this->markTestSkipped('Guzzle 7 adapter is not installed');
54
        }
55
56
        $this->load([
57
            'classes' => [
58
                'client' => Client::class,
59
            ],
60
        ]);
61
62
        $this->assertContainerBuilderHasService('httplug.client.default', Client::class);
63
    }
64
65
    public function testConfigLoadService(): void
66
    {
67
        $this->load([
68
            'main_alias' => [
69
                'client' => 'my_client_service',
70
                'message_factory' => 'my_message_factory_service',
71
                'uri_factory' => 'my_uri_factory_service',
72
                'stream_factory' => 'my_stream_factory_service',
73
            ],
74
        ]);
75
76 View Code Duplication
        foreach (['client', 'message_factory', 'uri_factory', 'stream_factory'] as $type) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
            $this->assertContainerBuilderHasAlias("httplug.$type", "my_{$type}_service");
78
        }
79
    }
80
81
    public function testClientPlugins(): void
82
    {
83
        $this->load([
84
            'clients' => [
85
                'acme' => [
86
                    'factory' => 'httplug.factory.curl',
87
                    'plugins' => [
88
                        [
89
                            'decoder' => [
90
                                'use_content_encoding' => false,
91
                            ],
92
                        ],
93
                        'httplug.plugin.redirect',
94
                        [
95
                            'add_host' => [
96
                                'host' => 'http://localhost:8000',
97
                            ],
98
                        ],
99
                        [
100
                            'content_type' => [
101
                                'skip_detection' => true,
102
                            ],
103
                        ],
104
                        [
105
                            'header_append' => [
106
                                'headers' => ['X-FOO' => 'bar'],
107
                            ],
108
                        ],
109
                        [
110
                            'header_defaults' => [
111
                                'headers' => ['X-FOO' => 'bar'],
112
                            ],
113
                        ],
114
                        [
115
                            'header_set' => [
116
                                'headers' => ['X-FOO' => 'bar'],
117
                            ],
118
                        ],
119
                        [
120
                            'header_remove' => [
121
                                'headers' => ['X-FOO'],
122
                            ],
123
                        ],
124
                        [
125
                            'query_defaults' => [
126
                                'parameters' => ['locale' => 'en'],
127
                            ],
128
                        ],
129
                        [
130
                            'authentication' => [
131
                                'my_basic' => [
132
                                    'type' => 'basic',
133
                                    'username' => 'foo',
134
                                    'password' => 'bar',
135
                                ],
136
                            ],
137
                        ],
138
                        [
139
                            'cache' => [
140
                                'cache_pool' => 'my_cache_pool',
141
                            ],
142
                        ],
143
                    ],
144
                ],
145
            ],
146
        ]);
147
148
        $plugins = [
149
            'httplug.client.acme.plugin.decoder',
150
            'httplug.plugin.redirect',
151
            'httplug.client.acme.plugin.add_host',
152
            'httplug.client.acme.plugin.content_type',
153
            'httplug.client.acme.plugin.header_append',
154
            'httplug.client.acme.plugin.header_defaults',
155
            'httplug.client.acme.plugin.header_set',
156
            'httplug.client.acme.plugin.header_remove',
157
            'httplug.client.acme.plugin.query_defaults',
158
            'httplug.client.acme.authentication.my_basic',
159
            'httplug.client.acme.plugin.cache',
160
        ];
161
        $pluginReferences = array_map(function ($id) {
162
            return new Reference($id);
163
        }, $plugins);
164
165
        $this->assertContainerBuilderHasService('httplug.client.acme');
166
        foreach ($plugins as $id) {
167
            $this->assertContainerBuilderHasService($id);
168
        }
169
        $this->assertContainerBuilderHasServiceDefinitionWithArgument('httplug.client.acme', 1, $pluginReferences);
170
        $this->assertContainerBuilderHasService('httplug.client.mock');
171
    }
172
173
    /**
174
     * @group legacy
175
     */
176 View Code Duplication
    public function testNoProfilingWhenToolbarIsDisabled(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
177
    {
178
        $this->load(
179
            [
180
                'toolbar' => [
181
                    'enabled' => false,
182
                ],
183
                'clients' => [
184
                    'acme' => [
185
                        'factory' => 'httplug.factory.curl',
186
                        'plugins' => ['foo'],
187
                    ],
188
                ],
189
            ]
190
        );
191
192
        $this->verifyProfilingDisabled();
193
    }
194
195 View Code Duplication
    public function testNoProfilingWhenNotInDebugMode(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
196
    {
197
        $this->setParameter('kernel.debug', false);
198
        $this->load(
199
            [
200
                'clients' => [
201
                    'acme' => [
202
                        'factory' => 'httplug.factory.curl',
203
                        'plugins' => ['foo'],
204
                    ],
205
                ],
206
            ]
207
        );
208
209
        $this->verifyProfilingDisabled();
210
    }
211
212
    /**
213
     * @group legacy
214
     */
215 View Code Duplication
    public function testProfilingWhenToolbarIsSpecificallyOn(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
216
    {
217
        $this->setParameter('kernel.debug', false);
218
        $this->load(
219
            [
220
                'toolbar' => [
221
                    'enabled' => true,
222
                ],
223
                'clients' => [
224
                    'acme' => [
225
                        'factory' => 'httplug.factory.curl',
226
                        'plugins' => ['foo'],
227
                    ],
228
                ],
229
            ]
230
        );
231
232
        $this->assertContainerBuilderHasService(PluginClientFactoryListener::class);
233
    }
234
235
    public function testOverrideProfilingFormatter(): void
236
    {
237
        $this->load(
238
            [
239
                'profiling' => [
240
                    'formatter' => 'acme.formatter',
241
                ],
242
            ]
243
        );
244
245
        $def = $this->container->findDefinition('httplug.collector.formatter');
246
        $this->assertEquals('acme.formatter', (string) $def->getArgument(0));
247
    }
248
249 View Code Duplication
    public function testCachePluginConfigCacheKeyGeneratorReference(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
    {
251
        $this->load([
252
            'plugins' => [
253
                'cache' => [
254
                    'cache_pool' => 'my_cache_pool',
255
                    'config' => [
256
                        'cache_key_generator' => 'header_cache_key_generator',
257
                    ],
258
                ],
259
            ],
260
        ]);
261
262
        $cachePlugin = $this->container->findDefinition('httplug.plugin.cache');
263
264
        $config = $cachePlugin->getArgument(2);
265
        $this->assertArrayHasKey('cache_key_generator', $config);
266
        $this->assertInstanceOf(Reference::class, $config['cache_key_generator']);
267
        $this->assertSame('header_cache_key_generator', (string) $config['cache_key_generator']);
268
    }
269
270 View Code Duplication
    public function testCachePluginConfigCacheListenersDefinition(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
271
    {
272
        $this->load([
273
            'plugins' => [
274
                'cache' => [
275
                    'cache_pool' => 'my_cache_pool',
276
                    'config' => [
277
                        'cache_listeners' => [
278
                            'httplug.plugin.cache.listeners.add_header',
279
                        ],
280
                    ],
281
                ],
282
            ],
283
        ]);
284
285
        $cachePlugin = $this->container->findDefinition('httplug.plugin.cache');
286
287
        $config = $cachePlugin->getArgument(2);
288
        $this->assertArrayHasKey('cache_listeners', $config);
289
        $this->assertContainsOnlyInstancesOf(Reference::class, $config['cache_listeners']);
290
        $this->assertSame('httplug.plugin.cache.listeners.add_header', (string) $config['cache_listeners'][0]);
291
    }
292
293
    public function testContentTypePluginAllowedOptions(): void
294
    {
295
        $this->load([
296
            'clients' => [
297
                'acme' => [
298
                    'plugins' => [
299
                        [
300
                            'content_type' => [
301
                                'skip_detection' => true,
302
                                'size_limit' => 200000,
303
                            ],
304
                        ],
305
                    ],
306
                ],
307
            ],
308
        ]);
309
310
        $cachePlugin = $this->container->findDefinition('httplug.client.acme.plugin.content_type');
311
312
        $config = $cachePlugin->getArgument(0);
313
        $this->assertEquals([
314
            'skip_detection' => true,
315
            'size_limit' => 200000,
316
        ], $config);
317
    }
318
319
    public function testUsingServiceKeyForClients(): void
320
    {
321
        $this->load([
322
            'clients' => [
323
                'acme' => [
324
                    'service' => 'my_custom_client',
325
                ],
326
            ],
327
        ]);
328
329
        $client = $this->container->getAlias('httplug.client.acme.client');
330
        $this->assertEquals('my_custom_client', (string) $client);
331
        $this->assertFalse($client->isPublic());
332
    }
333
334
    private function verifyProfilingDisabled(): void
335
    {
336
        $def = $this->container->findDefinition('httplug.client');
337
        $this->assertTrue(is_subclass_of($def->getClass(), HttpClient::class));
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Http\Client\HttpClient::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
338
        $arguments = $def->getArguments();
339
340
        if (isset($arguments[3])) {
341
            $this->assertEmpty(
342
                $arguments[3],
343
                'Parameter 3 to the PluginClient must not contain any debug_plugin information when profiling is disabled'
344
            );
345
        }
346
    }
347
348
    public function testClientShouldHaveDefaultVisibility(): void
349
    {
350
        $this->load([
351
            'clients' => [
352
                'acme' => [],
353
            ],
354
        ]);
355
356
        $this->assertContainerBuilderHasService('httplug.client.acme');
357
358
        if (version_compare(Kernel::VERSION, '3.4', '>=')) {
359
            // Symfony made services private by default starting from 3.4
360
            $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPrivate());
361
        } else {
362
            // Legacy Symfony
363
            $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic());
364
        }
365
    }
366
367 View Code Duplication
    public function testFlexibleClientShouldBePrivateByDefault(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
368
    {
369
        $this->load([
370
            'clients' => [
371
                'acme' => [
372
                    'flexible_client' => true,
373
                ],
374
            ],
375
        ]);
376
377
        $this->assertContainerBuilderHasService('httplug.client.acme');
378
        $this->assertFalse($this->container->getDefinition('httplug.client.acme.flexible')->isPublic());
379
    }
380
381 View Code Duplication
    public function testHttpMethodsClientShouldBePrivateByDefault(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
382
    {
383
        $this->load([
384
            'clients' => [
385
                'acme' => [
386
                    'http_methods_client' => true,
387
                ],
388
            ],
389
        ]);
390
391
        $this->assertContainerBuilderHasService('httplug.client.acme');
392
        $this->assertFalse($this->container->getDefinition('httplug.client.acme.http_methods')->isPublic());
393
    }
394
395 View Code Duplication
    public function testBatchClientShouldBePrivateByDefault(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
    {
397
        $this->load([
398
            'clients' => [
399
                'acme' => [
400
                    'batch_client' => true,
401
                ],
402
            ],
403
        ]);
404
405
        $this->assertContainerBuilderHasService('httplug.client.acme');
406
        $this->assertFalse($this->container->getDefinition('httplug.client.acme.batch_client')->isPublic());
407
    }
408
409 View Code Duplication
    public function testClientCanBePublic(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
410
    {
411
        $this->load([
412
            'clients' => [
413
                'acme' => [
414
                    'public' => true,
415
                ],
416
            ],
417
        ]);
418
419
        $this->assertContainerBuilderHasService('httplug.client.acme');
420
        $this->assertTrue($this->container->getDefinition('httplug.client.acme')->isPublic());
421
422
        if (version_compare(Kernel::VERSION, '3.4', '>=')) {
423
            // Symfony made services private by default starting from 3.4
424
            $this->assertFalse($this->container->getDefinition('httplug.client.acme')->isPrivate());
425
        }
426
    }
427
428 View Code Duplication
    public function testFlexibleClientCanBePublic(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
429
    {
430
        $this->load([
431
            'clients' => [
432
                'acme' => [
433
                    'public' => true,
434
                    'flexible_client' => true,
435
                ],
436
            ],
437
        ]);
438
439
        $this->assertContainerBuilderHasService('httplug.client.acme');
440
        $this->assertTrue($this->container->getDefinition('httplug.client.acme.flexible')->isPublic());
441
442
        if (version_compare(Kernel::VERSION, '3.4', '>=')) {
443
            // Symfony made services private by default starting from 3.4
444
            $this->assertFalse($this->container->getDefinition('httplug.client.acme.flexible')->isPrivate());
445
        }
446
    }
447
448 View Code Duplication
    public function testHttpMethodsClientCanBePublic(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
449
    {
450
        $this->load([
451
            'clients' => [
452
                'acme' => [
453
                    'public' => true,
454
                    'http_methods_client' => true,
455
                ],
456
            ],
457
        ]);
458
459
        $this->assertContainerBuilderHasService('httplug.client.acme');
460
        $this->assertTrue($this->container->getDefinition('httplug.client.acme.http_methods')->isPublic());
461
462
        if (version_compare(Kernel::VERSION, '3.4', '>=')) {
463
            // Symfony made services private by default starting from 3.4
464
            $this->assertFalse($this->container->getDefinition('httplug.client.acme.http_methods')->isPrivate());
465
        }
466
    }
467
468 View Code Duplication
    public function testBatchClientCanBePublic(): void
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
469
    {
470
        $this->load([
471
            'clients' => [
472
                'acme' => [
473
                    'public' => true,
474
                    'batch_client' => true,
475
                ],
476
            ],
477
        ]);
478
479
        $this->assertContainerBuilderHasService('httplug.client.acme');
480
        $this->assertTrue($this->container->getDefinition('httplug.client.acme.batch_client')->isPublic());
481
482
        if (version_compare(Kernel::VERSION, '3.4', '>=')) {
483
            // Symfony made services private by default starting from 3.4
484
            $this->assertFalse($this->container->getDefinition('httplug.client.acme.batch_client')->isPrivate());
485
        }
486
    }
487
488
    public function testClientIsTaggedWithHttplugClientTag(): void
489
    {
490
        $this->load([
491
            'clients' => [
492
                'acme' => null,
493
            ],
494
        ]);
495
496
        $serviceId = 'httplug.client.acme';
497
498
        $this->assertContainerBuilderHasService($serviceId);
499
500
        $this->assertTrue($this->container->getDefinition($serviceId)->hasTag(HttplugExtension::HTTPLUG_CLIENT_TAG), sprintf(
501
            'Failed asserting that client with service identifier "%s" has been tagged with "%s".',
502
            $serviceId,
503
            HttplugExtension::HTTPLUG_CLIENT_TAG
504
        ));
505
    }
506
507
    /**
508
     * @dataProvider provideVcrPluginConfig
509
     * @group vcr-plugin
510
     */
511
    public function testVcrPluginConfiguration(array $config, array $services, array $arguments = []): void
512
    {
513
        if (!class_exists(InMemoryRecorder::class)) {
514
            $this->markTestSkipped('VCR plugin is not installed.');
515
        }
516
517
        $prefix = 'httplug.client.acme.vcr';
518
        $this->load(['clients' => ['acme' => ['plugins' => [['vcr' => $config]]]]]);
519
        $this->assertContainerBuilderHasService('httplug.plugin.vcr.recorder.in_memory', InMemoryRecorder::class);
520
521
        foreach ($services as $service) {
522
            $this->assertContainerBuilderHasService($prefix.'.'.$service);
523
        }
524
525
        foreach ($arguments as $id => $args) {
526
            foreach ($args as $index => $value) {
527
                $this->assertContainerBuilderHasServiceDefinitionWithArgument($prefix.'.'.$id, $index, $value);
528
            }
529
        }
530
    }
531
532
    /**
533
     * @group vcr-plugin
534
     */
535
    public function testIsNotLoadedUnlessNeeded(): void
536
    {
537
        if (!class_exists(InMemoryRecorder::class)) {
538
            $this->markTestSkipped('VCR plugin is not installed.');
539
        }
540
541
        $this->load(['clients' => ['acme' => ['plugins' => []]]]);
542
        $this->assertContainerBuilderNotHasService('httplug.plugin.vcr.recorder.in_memory');
543
    }
544
545
    public function provideVcrPluginConfig()
546
    {
547
        $config = [
548
            'mode' => 'record',
549
            'recorder' => 'in_memory',
550
            'naming_strategy' => 'app.naming_strategy',
551
        ];
552
        yield [$config, ['record']];
553
554
        $config['mode'] = 'replay';
555
        yield [$config, ['replay']];
556
557
        $config['mode'] = 'replay_or_record';
558
        yield [$config, ['replay', 'record']];
559
560
        $config['recorder'] = 'filesystem';
561
        $config['fixtures_directory'] = __DIR__;
562
        unset($config['naming_strategy']);
563
564
        yield [$config, ['replay', 'record', 'recorder', 'naming_strategy'], ['replay' => [2 => false]]];
565
566
        $config['naming_strategy_options'] = [
567
            'hash_headers' => ['X-FOO'],
568
            'hash_body_methods' => ['PATCH'],
569
        ];
570
571
        yield [
572
            $config,
573
            ['replay', 'record', 'recorder', 'naming_strategy'],
574
            ['naming_strategy' => [$config['naming_strategy_options']]],
575
        ];
576
    }
577
}
578