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 (#194)
by joseph
188:50 queued 186:13
created

php$1 ➔ canCreateValidEntityWithRequiredRelations()   A

Complexity

Conditions 1

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 47
rs 9.1563
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Medium\Entity\Traits;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\DataTransferObjects\AbstractEntityCreationUuidDto;
8
use EdmondsCommerce\DoctrineStaticMeta\Exception\ValidationException;
9
use EdmondsCommerce\DoctrineStaticMeta\Schema\Database;
10
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
11
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator;
12
13
/**
14
 * @medium
15
 * @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Traits\AlwaysValidTrait
16
 * @SuppressWarnings(PHPMD.StaticAccess)
17
 */
18
class AlwaysValidTraitTest extends AbstractTest
19
{
20
    public const WORK_DIR = self::VAR_PATH . '/' . self::TEST_TYPE_MEDIUM . '/AlwaysValidTraitTest';
21
22
    protected static $buildOnce = true;
23
24
    public function setup()
25
    {
26
        parent::setUp();
27
        if (false === self::$built) {
28
            $this->getTestCodeGenerator()
29
                 ->copyTo(self::WORK_DIR);
30
            self::$built = true;
31
        }
32
        $this->setupCopiedWorkDir();
33
    }
34
35
    /**
36
     * @test
37
     */
38
    public function mustIncludeRequiredRelationsWhenCreating(): void
39
    {
40
        $companyFqn = $this->getCopiedFqn(
41
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_COMPANY
42
        );
43
        $this->expectException(ValidationException::class);
44
        $this->expectExceptionMessage('Found 3 errors validating');
45
        $this->getEntityFactory()->create(
46
            $companyFqn,
47
            new class($companyFqn, $this->getUuidFactory()) extends AbstractEntityCreationUuidDto
48
            {
49
            }
50
        );
51
    }
52
53
    /**
54
     * @test
55
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
56
     * @throws \ReflectionException
57
     */
58
    public function nestedDtosMustBeValid(): void
59
    {
60
        $companyFqn    = $this->getCopiedFqn(
61
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_COMPANY
62
        );
63
        $someClientFqn = $this->getCopiedFqn(
64
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_NAME_SPACING_SOME_CLIENT
65
        );
66
67
        $companyDto           = $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($companyFqn);
68
        $invalidSomeClientDto = $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($someClientFqn);
69
        $invalidSomeClientDto->setString(str_repeat('a', Database::MAX_VARCHAR_LENGTH + 1));
70
        $companyDto->setSomeClientDto($invalidSomeClientDto);
71
        $this->expectException(ValidationException::class);
72
        $this->expectExceptionMessage('Found 1 errors validating');
73
        $this->getEntityFactory()->create(
74
            $companyFqn,
75
            $companyDto
76
        );
77
    }
78
79
    /**
80
     * @test
81
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
82
     * @throws \ReflectionException
83
     */
84
    public function nestedDtosCollectionsWillNotBeValidated(): void
85
    {
86
        $companyFqn         = $this->getCopiedFqn(
87
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_COMPANY
88
        );
89
        $companyDirectorFqn = $this->getCopiedFqn(
90
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_DIRECTOR
91
        );
92
        /**
93
         * @var DoctrineStaticMeta $companyDirectorDsm
94
         */
95
        $companyDirectorDsm = $companyDirectorFqn::getDoctrineStaticMeta();
96
97
        $companyDto        = $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($companyFqn);
98
        $invalidCollection = new ArrayCollection();
99
        $invalidDirector   = $companyDirectorDsm->getReflectionClass()->newInstanceWithoutConstructor();
100
        $invalidCollection->add($invalidDirector);
101
        $companyDto->setCompanyDirectors($invalidCollection);
102
        $company = $this->getEntityFactory()->create(
103
            $companyFqn,
104
            $companyDto
105
        );
106
        self::assertInstanceOf($companyFqn, $company);
107
    }
108
109
    /**
110
     * @test
111
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException
112
     * @throws \ReflectionException
113
     */
114
    public function canCreateValidEntityWithRequiredRelations(): void
115
    {
116
        $companyFqn = $this->getCopiedFqn(
117
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_COMPANY
118
        );
119
120
        $companyDto = $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($companyFqn);
121
122
        $emailFqn = $this->getCopiedFqn(
123
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_EMAIL
124
        );
125
        $email    = $this->getEntityFactory()->create($emailFqn);
126
        $companyDto->getAttributesEmails()->add($email);
127
128
        $personFqn = $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_PERSON);
129
        $personDto = $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($personFqn);
130
        $personDto->getAttributesEmails()->add($email);
131
132
        $companyDirectorFqn = $this->getCopiedFqn(
133
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_DIRECTOR
134
        );
135
        $companyDirectorDto = $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($companyDirectorFqn);
136
        $companyDirectorDto->setPersonDto($personDto);
137
        $companyDirectorDto->setCompanies(new ArrayCollection([$companyDto]));
138
        $companyDto->getCompanyDirectors()->add($companyDirectorDto);
139
140
        $addressFqn = $this->getCopiedFqn(
141
            self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_ATTRIBUTES_ADDRESS
142
        );
143
        $companyDto->getAttributesAddresses()->add(
144
            $this->getEntityDtoFactory()->createEmptyDtoFromEntityFqn($addressFqn)
145
        );
146
147
        $this->getDataFillerFactory()
148
             ->getInstanceFromEntityFqn($companyFqn)
149
             ->updateDtoWithFakeData($companyDto);
150
151
        $company = $this->getEntityFactory()->create(
152
            $companyFqn,
153
            $companyDto
154
        );
155
156
        self::assertInstanceOf($companyFqn, $company);
157
        self::assertInstanceOf($emailFqn, $company->getAttributesEmails()->first());
158
        self::assertInstanceOf($companyDirectorFqn, $company->getCompanyDirectors()->first());
159
        self::assertInstanceOf($personFqn, $company->getCompanyDirectors()->first()->getPerson());
160
        self::assertInstanceOf($addressFqn, $company->getAttributesAddresses()->first());
161
    }
162
}
163