| Conditions | 1 |
| Paths | 1 |
| Total Lines | 77 |
| 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 |
||
| 28 | public function testRepositoryServiceWiring() : void |
||
| 29 | { |
||
| 30 | $container = new ContainerBuilder(new ParameterBag([ |
||
| 31 | 'kernel.name' => 'app', |
||
| 32 | 'kernel.debug' => false, |
||
| 33 | 'kernel.bundles' => ['RepositoryServiceBundle' => RepositoryServiceBundle::class], |
||
| 34 | 'kernel.cache_dir' => sys_get_temp_dir(), |
||
| 35 | 'kernel.environment' => 'test', |
||
| 36 | 'kernel.root_dir' => __DIR__ . '/../../../../', // src dir |
||
| 37 | 'kernel.project_dir' => __DIR__ . '/../../../../', // src dir |
||
| 38 | 'kernel.bundles_metadata' => [], |
||
| 39 | 'kernel.charset' => 'UTF-8', |
||
| 40 | 'kernel.container_class' => ContainerBuilder::class, |
||
| 41 | 'kernel.secret' => 'test', |
||
| 42 | 'container.build_id' => uniqid(), |
||
| 43 | 'env(base64:default::SYMFONY_DECRYPTION_SECRET)' => 'foo', |
||
| 44 | ])); |
||
| 45 | $container->set('annotation_reader', new AnnotationReader()); |
||
| 46 | |||
| 47 | $extension = new FrameworkExtension(); |
||
| 48 | $container->registerExtension($extension); |
||
| 49 | $extension->load(['framework' => []], $container); |
||
| 50 | |||
| 51 | $extension = new DoctrineExtension(); |
||
| 52 | $container->registerExtension($extension); |
||
| 53 | $extension->load([ |
||
| 54 | [ |
||
| 55 | 'dbal' => [ |
||
| 56 | 'driver' => 'pdo_sqlite', |
||
| 57 | 'charset' => 'UTF8', |
||
| 58 | ], |
||
| 59 | 'orm' => [ |
||
| 60 | 'mappings' => [ |
||
| 61 | 'RepositoryServiceBundle' => [ |
||
| 62 | 'type' => 'annotation', |
||
| 63 | 'dir' => __DIR__ . '/DependencyInjection/Fixtures/Bundles/RepositoryServiceBundle/Entity', |
||
| 64 | 'prefix' => 'Fixtures\Bundles\RepositoryServiceBundle\Entity', |
||
| 65 | ], |
||
| 66 | ], |
||
| 67 | ], |
||
| 68 | ], |
||
| 69 | ], $container); |
||
| 70 | |||
| 71 | $def = $container->register(TestCustomServiceRepoRepository::class, TestCustomServiceRepoRepository::class) |
||
| 72 | ->setPublic(false); |
||
| 73 | // create a public alias so we can use it below for testing |
||
| 74 | $container->setAlias('test_alias__' . TestCustomServiceRepoRepository::class, new Alias(TestCustomServiceRepoRepository::class, true)); |
||
| 75 | |||
| 76 | $def->setAutowired(true); |
||
| 77 | $def->setAutoconfigured(true); |
||
| 78 | |||
| 79 | $container->addCompilerPass(new ServiceRepositoryCompilerPass()); |
||
| 80 | $container->compile(); |
||
| 81 | |||
| 82 | $em = $container->get('doctrine.orm.default_entity_manager'); |
||
| 83 | |||
| 84 | // traditional custom class repository |
||
| 85 | $customClassRepo = $em->getRepository(TestCustomClassRepoEntity::class); |
||
| 86 | $this->assertInstanceOf(TestCustomClassRepoRepository::class, $customClassRepo); |
||
| 87 | // a smoke test, trying some methods |
||
| 88 | $this->assertSame(TestCustomClassRepoEntity::class, $customClassRepo->getClassName()); |
||
| 89 | $this->assertInstanceOf(QueryBuilder::class, $customClassRepo->createQueryBuilder('tc')); |
||
| 90 | |||
| 91 | // generic EntityRepository |
||
| 92 | $genericRepository = $em->getRepository(TestDefaultRepoEntity::class); |
||
| 93 | $this->assertInstanceOf(EntityRepository::class, $genericRepository); |
||
| 94 | $this->assertSame($genericRepository, $genericRepository = $em->getRepository(TestDefaultRepoEntity::class)); |
||
| 95 | // a smoke test, trying one of the methods |
||
| 96 | $this->assertSame(TestDefaultRepoEntity::class, $genericRepository->getClassName()); |
||
| 97 | |||
| 98 | // custom service repository |
||
| 99 | $customServiceRepo = $em->getRepository(TestCustomServiceRepoEntity::class); |
||
| 100 | $this->assertSame($customServiceRepo, $container->get('test_alias__' . TestCustomServiceRepoRepository::class)); |
||
| 101 | // a smoke test, trying some methods |
||
| 102 | $this->assertSame(TestCustomServiceRepoEntity::class, $customServiceRepo->getClassName()); |
||
| 103 | $this->assertInstanceOf(QueryBuilder::class, $customServiceRepo->createQueryBuilder('tc')); |
||
| 104 | } |
||
| 105 | } |
||
| 106 |