Conditions | 3 |
Paths | 4 |
Total Lines | 57 |
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('This test requires Symfony 5.1 or higher'); |
||
22 | } |
||
23 | if (! interface_exists(EntityManagerInterface::class)) { |
||
24 | self::markTestSkipped('This test requires ORM'); |
||
25 | } |
||
26 | |||
27 | $container = new ContainerBuilder(new ParameterBag([ |
||
28 | 'kernel.name' => 'app', |
||
29 | 'kernel.debug' => false, |
||
30 | 'kernel.bundles' => [], |
||
31 | 'kernel.cache_dir' => sys_get_temp_dir(), |
||
32 | 'kernel.environment' => 'test', |
||
33 | 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
||
34 | 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir |
||
35 | 'kernel.bundles_metadata' => [], |
||
36 | 'kernel.charset' => 'UTF-8', |
||
37 | 'kernel.container_class' => ContainerBuilder::class, |
||
38 | 'kernel.secret' => 'test', |
||
39 | 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', |
||
40 | ])); |
||
41 | |||
42 | $extension = new FrameworkExtension(); |
||
43 | $container->registerExtension($extension); |
||
44 | $extension->load([ |
||
45 | 'framework' => [ |
||
46 | 'cache' => [ |
||
47 | 'pools' => [ |
||
48 | 'my_cache_adapter' => ['adapter' => 'cache.adapter.pdo'], |
||
49 | ], |
||
50 | ], |
||
51 | ], |
||
52 | ], $container); |
||
53 | |||
54 | $extension = new DoctrineExtension(); |
||
55 | $container->registerExtension($extension); |
||
56 | $extension->load([ |
||
57 | [ |
||
58 | 'dbal' => [], |
||
59 | 'orm' => [], |
||
60 | ], |
||
61 | ], $container); |
||
62 | |||
63 | $container->setAlias('test_subscriber_alias', new Alias('doctrine.orm.listeners.pdo_cache_adapter_doctrine_schema_subscriber', true)); |
||
64 | // prevent my_cache_apapter from inlining |
||
65 | $container->register('uses_my_cache_adapter', 'stdClass') |
||
66 | ->addArgument(new Reference('my_cache_adapter')) |
||
67 | ->setPublic(true); |
||
68 | $container->addCompilerPass(new CacheSchemaSubscriberPass(), PassConfig::TYPE_BEFORE_REMOVING, -10); |
||
69 | $container->compile(); |
||
70 | |||
71 | // check that PdoAdapter service is injected as an argument |
||
72 | $definition = $container->findDefinition('test_subscriber_alias'); |
||
73 | $this->assertEquals([new Reference('my_cache_adapter')], $definition->getArgument(0)); |
||
74 | } |
||
75 | } |
||
76 |