Conditions | 3 |
Paths | 3 |
Total Lines | 84 |
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 |
||
23 | public function testProcess(): void |
||
24 | { |
||
25 | // Create ContainerBuilder and set up basic sonata_media config with formats |
||
26 | $container = new ContainerBuilder(); |
||
27 | $extension = new SonataMediaExtension(); |
||
28 | $container->registerExtension($extension); |
||
29 | $container->loadFromExtension( |
||
30 | $extension->getAlias(), |
||
31 | [ |
||
32 | 'db_driver' => 'doctrine_orm', |
||
33 | 'default_context' => 'default', |
||
34 | 'providers' => [ |
||
35 | 'image' => [ |
||
36 | 'filesystem' => 'foo_filesystem', |
||
37 | ], |
||
38 | ], |
||
39 | 'contexts' => [ |
||
40 | 'default' => [ |
||
41 | 'providers' => [ |
||
42 | 'foo_provider', |
||
43 | ], |
||
44 | 'formats' => '%foo_formats%', |
||
45 | ], |
||
46 | ], |
||
47 | ] |
||
48 | ); |
||
49 | |||
50 | // Define 'foo_formats' parameter, parameter reference in 'sonata_media' config should resolve to this value. |
||
51 | $container->setParameter('foo_formats', [ |
||
52 | 'foo_format' => [ |
||
53 | 'width' => 350, |
||
54 | 'height' => 200, |
||
55 | 'quality' => 70, |
||
56 | ], |
||
57 | ]); |
||
58 | |||
59 | // Register parameters and services needed by compiler pass |
||
60 | $container->setParameter('sonata.media.admin_format', [ |
||
61 | 'width' => 200, |
||
62 | 'height' => false, |
||
63 | 'quality' => 90, |
||
64 | ]); |
||
65 | $container |
||
66 | ->register('foo_filesystem') |
||
67 | ->setPublic(false); |
||
68 | $container |
||
69 | ->register('foo_provider') |
||
70 | ->setPublic(false); |
||
71 | $container |
||
72 | ->register('sonata.media.pool') |
||
73 | ->setPublic(false); |
||
74 | |||
75 | (new AddProviderCompilerPass())->process($container); |
||
76 | |||
77 | // 'foo_provider' should have 1 'addFormat' method call with correctly resolved config values. |
||
78 | $calls = $container->getDefinition('foo_provider')->getMethodCalls(); |
||
79 | $callFound = false; |
||
80 | $expectedCall = [ |
||
81 | 'default_foo_format', |
||
82 | [ |
||
83 | 'width' => 350, |
||
84 | 'height' => 200, |
||
85 | 'quality' => 70, |
||
86 | 'format' => 'jpg', |
||
87 | 'constraint' => true, |
||
88 | 'resizer' => false, |
||
89 | 'resizer_options' => [], |
||
90 | ], |
||
91 | ]; |
||
92 | foreach ($calls as $call) { |
||
93 | if ('addFormat' === $call[0]) { |
||
94 | $callFound = true; |
||
95 | $this->assertSame( |
||
96 | $expectedCall, |
||
97 | $call[1], |
||
98 | 'Format config of "foo_provider" doesn\'t match the expected config.' |
||
99 | ); |
||
100 | } |
||
101 | } |
||
102 | $this->assertTrue( |
||
103 | $callFound, |
||
104 | 'Expected "addFormat" method call on "foo_provider" service was not registered.' |
||
105 | ); |
||
106 | } |
||
107 | } |
||
108 |