| Conditions | 2 | 
| Paths | 2 | 
| Total Lines | 52 | 
| 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 | ||
| 18 | public function testSchemaSubscriberWiring() : void | ||
| 19 |     { | ||
| 20 |         if (! class_exists(PdoCacheAdapterDoctrineSchemaSubscriber::class)) { | ||
| 21 | $this->markTestSkipped(); | ||
| 22 | } | ||
| 23 | |||
| 24 | $container = new ContainerBuilder(new ParameterBag([ | ||
| 25 | 'kernel.name' => 'app', | ||
| 26 | 'kernel.debug' => false, | ||
| 27 | 'kernel.bundles' => [], | ||
| 28 | 'kernel.cache_dir' => sys_get_temp_dir(), | ||
| 29 | 'kernel.environment' => 'test', | ||
| 30 | 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir | ||
| 31 | 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir | ||
| 32 | 'kernel.bundles_metadata' => [], | ||
| 33 | 'kernel.charset' => 'UTF-8', | ||
| 34 | 'kernel.container_class' => ContainerBuilder::class, | ||
| 35 | 'kernel.secret' => 'test', | ||
| 36 | 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', | ||
| 37 | ])); | ||
| 38 | |||
| 39 | $extension = new FrameworkExtension(); | ||
| 40 | $container->registerExtension($extension); | ||
| 41 | $extension->load([ | ||
| 42 | 'framework' => [ | ||
| 43 | 'cache' => ['app' => 'cache.adapter.pdo'], | ||
| 44 | ], | ||
| 45 | ], $container); | ||
| 46 | |||
| 47 | $extension = new DoctrineExtension(); | ||
| 48 | $container->registerExtension($extension); | ||
| 49 | $extension->load([ | ||
| 50 | [ | ||
| 51 | 'dbal' => [], | ||
| 52 | 'orm' => [], | ||
| 53 | ], | ||
| 54 | ], $container); | ||
| 55 | |||
| 56 |         $container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true)); | ||
| 57 | // prevents cache.app from inlining, which affects the assertion | ||
| 58 |         $container->register('test_needs_cache_app', 'stdClass') | ||
| 59 |             ->setArgument(0, new Reference('cache.app')); | ||
| 60 | $container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_OPTIMIZE, -10); | ||
| 61 | $container->compile(); | ||
| 62 | |||
| 63 | // sanity check | ||
| 64 |         $this->assertSame(PdoAdapter::class, $container->getDefinition('cache.app')->getClass()); | ||
| 65 | // check that PdoAdapter service is injected as an argument | ||
| 66 |         $definition = $container->findDefinition('test_subscriber_alias'); | ||
| 67 | var_dump($definition->getArgument(0)); | ||
|  | |||
| 68 |         $this->assertEquals([new Reference('cache.app')], $definition->getArgument(0)); | ||
| 69 | } | ||
| 70 | } | ||
| 71 |