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
Pull Request — master (#113)
by joseph
90:04 queued 87:23
created

itCanGenerateASingleEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\Entity\Testing;
4
5
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Savers\EntitySaverFactory;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\AbstractEntityTest;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\TestEntityGenerator;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Validation\EntityValidatorFactory;
10
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
11
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest;
12
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
13
use EdmondsCommerce\DoctrineStaticMeta\Tests\Large\FullProjectBuildLargeTest;
14
15
/**
16
 * @large
17
 * @coversDefaultClass \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\TestEntityGenerator
18
 */
19
class TestEntityGeneratorLargeTest extends AbstractLargeTest
20
{
21
    public const WORK_DIR = AbstractTest::VAR_PATH .
22
                            self::TEST_TYPE_LARGE .
23
                            '/TestEntityGeneratorLargeTest';
24
25
    private const TEST_ENTITIES = FullProjectBuildLargeTest::TEST_ENTITIES;
26
27
    private const TEST_RELATIONS = FullProjectBuildLargeTest::TEST_RELATIONS;
28
29
    private const TEST_FIELD_FQN_BASE = FullProjectBuildLargeTest::TEST_FIELD_NAMESPACE_BASE . '\\Traits';
30
31
    protected static $buildOnce = true;
32
33
    public function setup(): void
34
    {
35
        parent::setup();
36
        if (false === self::$built) {
37
            $entityGenerator    = $this->getEntityGenerator();
38
            $fieldGenerator     = $this->getFieldGenerator();
39
            $relationsGenerator = $this->getRelationsGenerator();
40
            $fields             = [];
41
            foreach (MappingHelper::COMMON_TYPES as $type) {
42
                $fields[] = $fieldGenerator->generateField(
43
                    self::TEST_FIELD_FQN_BASE . '\\' . ucwords($type),
44
                    $type
45
                );
46
            }
47
            foreach (self::TEST_ENTITIES as $entityFqn) {
48
                $entityGenerator->generateEntity($entityFqn);
49
                foreach ($fields as $fieldFqn) {
50
                    $this->getFieldSetter()->setEntityHasField($entityFqn, $fieldFqn);
51
                }
52
            }
53
            foreach (self::TEST_RELATIONS as $relation) {
54
                $relationsGenerator->setEntityHasRelationToEntity(...$relation);
55
            }
56
            self::$built = true;
57
        }
58
        $this->setupCopiedWorkDirAndCreateDatabase();
59
    }
60
61
    /**
62
     * @test
63
     * @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\TestEntityGenerator
64
     * @return EntityInterface
65
     * @throws \Doctrine\ORM\Mapping\MappingException
66
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
67
     * @throws \ReflectionException
68
     */
69
    public function itCanGenerateASingleEntity(): EntityInterface
70
    {
71
        $entityFqn           = current(self::TEST_ENTITIES);
72
        $entityFqn           = $this->getCopiedFqn($entityFqn);
73
        $testEntityGenerator = $this->getTestEntityGenerator($entityFqn);
74
        $entityManager       = $this->getEntityManager();
75
        $entity              = $testEntityGenerator->generateEntity($entityManager, $entityFqn);
76
        $entityManager->persist($entity);
77
        $entityManager->flush();
78
        self::assertTrue(true);
79
80
        return $entity;
81
    }
82
83
    protected function getTestEntityGenerator(string $entityFqn): TestEntityGenerator
84
    {
85
        $testedEntityReflectionClass = new \ts\Reflection\ReflectionClass($entityFqn);
86
87
        return new TestEntityGenerator(
88
            AbstractEntityTest::SEED,
89
            [],
90
            $testedEntityReflectionClass,
91
            $this->container->get(EntitySaverFactory::class),
92
            $this->container->get(EntityValidatorFactory::class)
93
        );
94
    }
95
96
    /**
97
     * @test
98
     * @covers  \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\TestEntityGenerator
99
     *
100
     * @param EntityInterface $originalEntity
101
     *
102
     * @throws \Doctrine\ORM\Mapping\MappingException
103
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
104
     * @throws \ReflectionException
105
     * @depends itCanGenerateASingleEntity
106
     */
107
    public function itCanGenerateAnOffsetEntity(EntityInterface $originalEntity): void
108
    {
109
        $entityFqn           = \get_class($originalEntity);
110
        $testEntityGenerator = $this->getTestEntityGenerator($entityFqn);
111
        $entityManager       = $this->getEntityManager();
112
        $newEntity           = $testEntityGenerator->generateEntity($entityManager, $entityFqn, 1);
113
        self::assertNotEquals($this->dump($newEntity), $this->dump($originalEntity));
114
    }
115
116
    /**
117
     * @test
118
     * @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\TestEntityGenerator
119
     * @throws \Doctrine\ORM\Mapping\MappingException
120
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
121
     * @throws \ErrorException
122
     * @throws \ReflectionException
123
     */
124
    public function itGeneratesEntitiesAndAssociatedEntities(): void
125
    {
126
        $entities      = [];
127
        $entityManager = $this->getEntityManager();
128
        $limit         = ($this->isQuickTests() ? 2 : null);
129
        foreach (self::TEST_ENTITIES as $key => $entityFqn) {
130
            if ($limit !== null && $key === $limit) {
131
                break;
132
            }
133
            $entityFqn           = $this->getCopiedFqn($entityFqn);
134
            $testEntityGenerator = $this->getTestEntityGenerator($entityFqn);
135
            $entity              = $testEntityGenerator->generateEntity($entityManager, $entityFqn);
136
            self::assertInstanceOf($entityFqn, $entity);
137
            $testEntityGenerator->addAssociationEntities($entityManager, $entity);
138
            $entities[] = $entity;
139
        }
140
        $this->getEntitySaver()->saveAll($entities);
141
        self::assertTrue(true);
142
    }
143
144
145
    /**
146
     * @test
147
     * @covers ::generateEntities
148
     * @throws \Doctrine\ORM\Mapping\MappingException
149
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
150
     * @throws \ReflectionException
151
     */
152
    public function itCanGenerateMultipleEntities(): void
153
    {
154
        $entityFqn = $this->getCopiedFqn(current(self::TEST_ENTITIES));
155
        $count     = $this->isQuickTests() ? 2 : 100;
156
        $actual    = $this->getTestEntityGenerator($entityFqn)->generateEntities(
157
            $this->getEntityManager(),
158
            $entityFqn,
159
            $count
160
        );
161
        self::assertCount($count, $actual);
162
        self::assertInstanceOf($entityFqn, current($actual));
163
    }
164
165
    /**
166
     * @test
167
     * @covers ::create
168
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
169
     * @throws \ReflectionException
170
     */
171
    public function itCanCreateAnEmptyEntityUsingTheFactory(): void
172
    {
173
        $entityFqn = $this->getCopiedFqn(current(self::TEST_ENTITIES));
174
        $entity    = $this->getTestEntityGenerator($entityFqn)->create($this->getEntityManager());
175
        self::assertInstanceOf($entityFqn, $entity);
176
    }
177
178
    /**
179
     * @test
180
     * @covers ::create
181
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
182
     * @throws \ReflectionException
183
     */
184
    public function itCanCreateAnEntityWithValuesSet(): void
185
    {
186
        $entityFqn = $this->getCopiedFqn(current(self::TEST_ENTITIES));
187
        $values    = [
188
            'string' => 'this has been set',
189
        ];
190
        $entity    = $this->getTestEntityGenerator($entityFqn)->create($this->getEntityManager(), $values);
191
        self::assertSame($values['string'], $entity->getString());
0 ignored issues
show
Bug introduced by
The method getString() does not exist on EdmondsCommerce\Doctrine...erfaces\EntityInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

191
        self::assertSame($values['string'], $entity->/** @scrutinizer ignore-call */ getString());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
192
    }
193
}
194