| Conditions | 2 |
| Paths | 2 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 17 | public function testSchemaSubscriberWiring() : void |
||
| 18 | { |
||
| 19 | if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) { |
||
| 20 | $this->markTestSkipped('This test requires Symfony 5.1 or higher'); |
||
| 21 | } |
||
| 22 | |||
| 23 | $container = new ContainerBuilder(new ParameterBag([ |
||
| 24 | 'kernel.name' => 'app', |
||
| 25 | 'kernel.debug' => false, |
||
| 26 | 'kernel.bundles' => [], |
||
| 27 | 'kernel.cache_dir' => sys_get_temp_dir(), |
||
| 28 | 'kernel.environment' => 'test', |
||
| 29 | 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
||
| 30 | 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir |
||
| 31 | 'kernel.bundles_metadata' => [], |
||
| 32 | 'kernel.charset' => 'UTF-8', |
||
| 33 | 'kernel.container_class' => ContainerBuilder::class, |
||
| 34 | 'kernel.secret' => 'test', |
||
| 35 | 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', |
||
| 36 | ])); |
||
| 37 | |||
| 38 | $extension = new FrameworkExtension(); |
||
| 39 | $container->registerExtension($extension); |
||
| 40 | $extension->load([ |
||
| 41 | 'framework' => [ |
||
| 42 | 'cache' => [ |
||
| 43 | 'pools' => [ |
||
| 44 | 'my_cache_adapter' => ['adapter' => 'cache.adapter.pdo'], |
||
| 45 | ], |
||
| 46 | ], |
||
| 47 | ], |
||
| 48 | ], $container); |
||
| 49 | |||
| 50 | $extension = new DoctrineExtension(); |
||
| 51 | $container->registerExtension($extension); |
||
| 52 | $extension->load([ |
||
| 53 | [ |
||
| 54 | 'dbal' => [], |
||
| 55 | 'orm' => [], |
||
| 56 | ], |
||
| 57 | ], $container); |
||
| 58 | |||
| 59 | $container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true)); |
||
| 60 | // prevent my_cache_apapter from inlining |
||
| 61 | $container->register('uses_my_cache_adapter', 'stdClass') |
||
| 62 | ->addArgument(new Reference('my_cache_adapter')) |
||
| 63 | ->setPublic(true); |
||
| 64 | $container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_OPTIMIZE, -10); |
||
| 65 | $container->compile(); |
||
| 66 | |||
| 67 | // check that PdoAdapter service is injected as an argument |
||
| 68 | $definition = $container->findDefinition('test_subscriber_alias'); |
||
| 69 | $this->assertEquals([new Reference('my_cache_adapter')], $definition->getArgument(0)); |
||
| 70 | } |
||
| 71 | } |
||
| 72 |