GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e2b05d...198715 )
by Ross
12s queued 10s
created

EntityGeneratorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 103
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGenerateEntity() 0 18 1
A testGenerateRepository() 0 16 1
B testGenerateEntityWithDeepNesting() 0 30 1
A testGenerateWithEntitiesInProjectNamespace() 0 16 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Generator;
4
5
use EdmondsCommerce\DoctrineStaticMeta\AbstractTest;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Command\AbstractCommand;
7
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
8
9
class EntityGeneratorTest extends AbstractTest
10
{
11
    public const WORK_DIR = AbstractTest::VAR_PATH.'/EntityGeneratorTest/';
12
13
    /**
14
     */
15
    public function testGenerateEntity()
16
    {
17
        $fqn = static::TEST_PROJECT_ROOT_NAMESPACE
18
               .'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME
19
               .'\\Yet\\Another\\TestEntity';
20
        $this->getEntityGenerator()->generateEntity($fqn);
21
        $createdFile = static::WORK_DIR
22
                       .'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER
23
                       .'/'.AbstractGenerator::ENTITIES_FOLDER_NAME
24
                       .'/Yet/Another/TestEntity.php';
25
        $this->assertNoMissedReplacements($createdFile);
26
27
        $createdFile = static::WORK_DIR
28
                       .'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER
29
                       .'/'.AbstractGenerator::ENTITY_REPOSITORIES_FOLDER_NAME
30
                       .'/Yet/Another/TestEntityRepository.php';
31
        $this->assertNoMissedReplacements($createdFile);
32
        $this->qaGeneratedCode();
33
    }
34
35
    /**
36
     * Ensure we create the correct custom repository and also that Doctrine is properly configured to use it
37
     *
38
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
39
     */
40
    public function testGenerateRepository(): void
41
    {
42
        $entityFqn = static::TEST_PROJECT_ROOT_NAMESPACE
43
                     .'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME
44
                     .'\\Some\\Other\\TestEntity';
45
46
        $repositoryFqn = '\\'.static::TEST_PROJECT_ROOT_NAMESPACE
47
                         .AbstractGenerator::ENTITY_REPOSITORIES_NAMESPACE
48
                         .'\\Some\\Other\\TestEntityRepository';
49
50
        $this->getEntityGenerator()->generateEntity($entityFqn);
51
        $this->setupCopiedWorkDir();
52
53
        $entityManager = $this->getEntityManager();
54
        $repository    = $entityManager->getRepository($this->getCopiedFqn($entityFqn));
55
        $this->assertInstanceOf($this->getCopiedFqn($repositoryFqn), $repository);
56
    }
57
58
    /**
59
     * If the project namespace root has the word Entities in there, make sure it does not cause issues
60
     *
61
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
62
     */
63
    public function testGenerateWithEntitiesInProjectNamespace()
64
    {
65
        $namespaceRoot = 'My\\Test\\ProjectWithEntities';
66
        $generator     = $this->getEntityGenerator()
67
                              ->setProjectRootNamespace($namespaceRoot);
68
        $entityFqnDeep = $namespaceRoot
69
                         .'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME
70
                         .'\\Some\\Other\\TestEntity';
71
        $generator->generateEntity($entityFqnDeep);
72
73
        $entityFqnRoot = $namespaceRoot
74
                         .'\\'.AbstractGenerator::ENTITIES_FOLDER_NAME
75
                         .'\\RootLevelEntity';
76
        $generator->generateEntity($entityFqnRoot);
77
78
        $this->qaGeneratedCode($namespaceRoot);
79
    }
80
81
82
    public function testGenerateEntityWithDeepNesting()
83
    {
84
        $entityNamespace          = static::TEST_PROJECT_ROOT_NAMESPACE.'\\'
85
                                    .AbstractGenerator::ENTITIES_FOLDER_NAME
86
                                    .'\\Human\\Head\\Eye';
87
        $entityFullyQualifiedName = $entityNamespace.'\\Lash';
88
        $this->getEntityGenerator()
89
             ->setProjectRootNamespace(static::TEST_PROJECT_ROOT_NAMESPACE)
90
             ->generateEntity($entityFullyQualifiedName);
91
92
        $createdFile = static::WORK_DIR
93
                       .'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER
94
                       .'/'.AbstractGenerator::ENTITIES_FOLDER_NAME
95
                       .'/Human/Head/Eye/Lash.php';
96
        $this->assertNoMissedReplacements($createdFile);
97
        $this->assertContains("namespace $entityNamespace;", file_get_contents($createdFile));
98
99
        $createdFile = static::WORK_DIR
100
                       .'/'.AbstractCommand::DEFAULT_SRC_SUBFOLDER
101
                       .'/'.AbstractGenerator::ENTITY_REPOSITORIES_FOLDER_NAME
102
                       .'/Human/Head/Eye/LashRepository.php';
103
        $this->assertNoMissedReplacements($createdFile);
104
        $entityFullyQualifiedName = $this->container->get(NamespaceHelper::class)->tidy(
105
            static::TEST_PROJECT_ROOT_NAMESPACE.'\\'
106
            .AbstractGenerator::ENTITY_REPOSITORIES_NAMESPACE
107
            .'\\Human\\Head\\Eye'
108
        );
109
        $this->assertContains("namespace $entityFullyQualifiedName;", file_get_contents($createdFile));
110
111
        $this->qaGeneratedCode();
112
    }
113
}
114