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 ( 7e47ac...2b80ff )
by joseph
15s queued 12s
created

php$1 ➔ nestedDtosCollectionsWillNotBeValidated()   A

Complexity

Conditions 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

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