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.
Passed
Pull Request — master (#54)
by joseph
17:02
created

TestEntityGeneratorFunctionalTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
dl 0
loc 94
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testItCanGenerateMultipleEntities() 0 11 1
A getTestEntityGenerator() 0 9 1
A testItGeneratesEntitiesAndAssociatedEntities() 0 15 2
B buildFullSuiteOfEntities() 0 24 6
A testItCanGenerateASingleEntity() 0 12 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing;
4
5
use EdmondsCommerce\DoctrineStaticMeta\AbstractFunctionalTest;
6
use EdmondsCommerce\DoctrineStaticMeta\AbstractIntegrationTest;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\EntitySaverFactory;
8
use EdmondsCommerce\DoctrineStaticMeta\FullProjectBuildFunctionalTest;
9
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
10
11
class TestEntityGeneratorFunctionalTest extends AbstractFunctionalTest
12
{
13
    public const WORK_DIR = AbstractIntegrationTest::VAR_PATH.'/'.self::TEST_TYPE.'/TestEntityGeneratorFunctionalTest';
14
15
    private const TEST_ENTITIES = FullProjectBuildFunctionalTest::TEST_ENTITIES;
16
17
    private const TEST_RELATIONS = FullProjectBuildFunctionalTest::TEST_RELATIONS;
18
19
    private const TEST_FIELD_FQN_BASE = FullProjectBuildFunctionalTest::TEST_FIELD_NAMESPACE_BASE.'\\Traits';
20
21
    private $built = false;
22
23
24
    protected function buildFullSuiteOfEntities()
25
    {
26
        if (false === $this->built) {
27
            $entityGenerator    = $this->getEntityGenerator();
28
            $fieldGenerator     = $this->getFieldGenerator();
29
            $relationsGenerator = $this->getRelationsGenerator();
30
            $fields             = [];
31
            foreach (MappingHelper::COMMON_TYPES as $type) {
32
                $fields[] = $fieldGenerator->generateField(
33
                    self::TEST_FIELD_FQN_BASE.'\\'.ucwords($type),
34
                    $type
35
                );
36
            }
37
            foreach (self::TEST_ENTITIES as $entityFqn) {
38
                $entityGenerator->generateEntity($entityFqn);
39
                foreach ($fields as $fieldFqn) {
40
                    $fieldGenerator->setEntityHasField($entityFqn, $fieldFqn);
41
                }
42
            }
43
            foreach (self::TEST_RELATIONS as $relation) {
44
                $relationsGenerator->setEntityHasRelationToEntity(...$relation);
45
            }
46
        }
47
        $this->setupCopiedWorkDirAndCreateDatabase();
48
    }
49
50
    protected function getTestEntityGenerator(string $entityFqn): TestEntityGenerator
51
    {
52
        $testedEntityReflectionClass = new \ReflectionClass($entityFqn);
53
54
        return new TestEntityGenerator(
55
            AbstractEntityTest::SEED,
56
            [],
57
            $testedEntityReflectionClass,
58
            $this->container->get(EntitySaverFactory::class)
59
        );
60
    }
61
62
    public function testItCanGenerateASingleEntity(): void
63
    {
64
        $entityFqn = current(self::TEST_ENTITIES);
65
        $this->getEntityGenerator()->generateEntity($entityFqn);
66
        $this->setupCopiedWorkDirAndCreateDatabase();
67
        $entityFqn           = $this->getCopiedFqn($entityFqn);
68
        $testEntityGenerator = $this->getTestEntityGenerator($entityFqn);
69
        $entityManager       = $this->getEntityManager();
70
        $entity              = $testEntityGenerator->generateEntity($entityManager, $entityFqn);
71
        $entityManager->persist($entity);
72
        $entityManager->flush($entity);
73
        $this->assertTrue(true);
74
75
    }
76
77
    public function testItGeneratesEntitiesAndAssociatedEntities(): void
78
    {
79
        $this->buildFullSuiteOfEntities();
80
        $entities      = [];
81
        $entityManager = $this->getEntityManager();
82
        foreach (self::TEST_ENTITIES as $entityFqn) {
83
            $entityFqn           = $this->getCopiedFqn($entityFqn);
84
            $testEntityGenerator = $this->getTestEntityGenerator($entityFqn);
85
            $entity              = $testEntityGenerator->generateEntity($entityManager, $entityFqn);
86
            $this->assertInstanceOf($entityFqn, $entity);
87
            $testEntityGenerator->addAssociationEntities($entityManager, $entity);
88
            $entities[] = $entity;
89
        }
90
        $this->getEntitySaver()->saveAll($entities);
91
        $this->assertTrue(true);
92
    }
93
94
    public function testItCanGenerateMultipleEntities(): void
95
    {
96
        $this->buildFullSuiteOfEntities();
97
        $entityFqn = $this->getCopiedFqn(current(self::TEST_ENTITIES));
98
        $actual    = $this->getTestEntityGenerator($entityFqn)->generateEntities(
99
            $this->getEntityManager(),
100
            $entityFqn,
101
            100
102
        );
103
        $this->assertCount(100, $actual);
104
        $this->assertInstanceOf($entityFqn, current($actual));
105
    }
106
107
}
108