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 (#152)
by joseph
17:58
created

itCanCreateAnEntitySpecificFactoryAndCanCreateThatEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\C\Entity\Factory;
4
5
use EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityDependencyInjector;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityFactory;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityFactoryInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\EmailAddressFieldInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Interfaces\String\IsbnFieldInterface;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\DataTransferObjectInterface;
11
use EdmondsCommerce\DoctrineStaticMeta\Exception\ValidationException;
12
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
13
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator;
14
15
/**
16
 * @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Factory\EntityFactory
17
 * @large
18
 */
19
class EntityFactoryTest extends AbstractTest
20
{
21
    public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/EntityFactoryTest';
22
23
    private const TEST_ENTITY_FQN = self::TEST_ENTITIES_ROOT_NAMESPACE .
24
                                    TestCodeGenerator::TEST_ENTITY_ALL_ARCHETYPE_FIELDS;
25
26
    private const TEST_VALUES = [
27
        IsbnFieldInterface::PROP_ISBN                  => '978-3-16-148410-0',
28
        EmailAddressFieldInterface::PROP_EMAIL_ADDRESS => '[email protected]',
29
    ];
30
    protected static $buildOnce = true;
31
    private $entityFqn;
32
    /**
33
     * @var EntityFactoryInterface
34
     */
35
    private $factory;
36
37
    public function setup()
38
    {
39
        parent::setUp();
40
        if (false === self::$built) {
41
            $this->getTestCodeGenerator()
42
                 ->copyTo(self::WORK_DIR);
43
            self::$built = true;
44
        }
45
        $this->setupCopiedWorkDir();
46
        $this->entityFqn = $this->getCopiedFqn(self::TEST_ENTITY_FQN);
47
        $this->factory   = new EntityFactory(
48
            $this->getNamespaceHelper(),
49
            $this->container->get(EntityDependencyInjector::class),
50
            $this->getEntityDtoFactory()
51
        );
52
        $this->factory->setEntityManager($this->getEntityManager());
53
    }
54
55
56
    /**
57
     * @test
58
     */
59
    public function itCanCreateAnEmptyEntity(): void
60
    {
61
        $entity = $this->factory->create($this->entityFqn, $this->getValidDtoForTestEntity());
62
        self::assertInstanceOf($this->entityFqn, $entity);
63
    }
64
65
    private function getValidDtoForTestEntity(): DataTransferObjectInterface
66
    {
67
        return $this->getEntityDtoFactory()
68
                    ->createEmptyDtoFromEntityFqn($this->entityFqn)
69
                    ->setShortIndexedRequiredString('required')
70
                    ->setEmailAddress(self::TEST_VALUES[EmailAddressFieldInterface::PROP_EMAIL_ADDRESS])
71
                    ->setIsbn(self::TEST_VALUES[IsbnFieldInterface::PROP_ISBN]);
72
    }
73
74
    /**
75
     * @test
76
     */
77
    public function itThrowsAnExceptionIfThereIsAnInvalidProperty(): void
78
    {
79
        $dto = $this->getValidDtoForTestEntity();
80
        $dto->setEmailAddress('invalid');
0 ignored issues
show
Bug introduced by
The method setEmailAddress() does not exist on EdmondsCommerce\Doctrine...TransferObjectInterface. ( Ignorable by Annotation )

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

80
        $dto->/** @scrutinizer ignore-call */ 
81
              setEmailAddress('invalid');

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...
81
        $this->expectException(ValidationException::class);
82
        $this->factory->create(
83
            $this->entityFqn,
84
            $dto
85
        );
86
    }
87
88
    /**
89
     * @test
90
     */
91
    public function itCanCreateAnEntityWithValues(): void
92
    {
93
94
        $entity = $this->factory->create($this->entityFqn, $this->getValidDtoForTestEntity());
95
96
        self::assertSame($entity->getIsbn(), self::TEST_VALUES[IsbnFieldInterface::PROP_ISBN]);
97
98
        self::assertSame($entity->getEmailAddress(), self::TEST_VALUES[EmailAddressFieldInterface::PROP_EMAIL_ADDRESS]);
99
    }
100
101
    /**
102
     * @test
103
     */
104
    public function itCanCreateAnEntitySpecificFactoryAndCanCreateThatEntity(): void
105
    {
106
        $entityFactory    = $this->factory->createFactoryForEntity($this->entityFqn);
107
        $entityFactoryFqn = $this->getNamespaceHelper()->getFactoryFqnFromEntityFqn($this->entityFqn);
108
        self::assertInstanceOf($entityFactoryFqn, $entityFactory);
109
        self::assertInstanceOf(
110
            $this->entityFqn,
111
            $entityFactory->create(
112
                $this->getValidDtoForTestEntity()
113
            )
114
        );
115
    }
116
117
    /**
118
     * @test
119
     */
120
    public function itCanCreateAnEntityWithRequiredRelationsUsingNestedDtos(): void
121
    {
122
        $attributesAddressFqn =
123
            $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_ATTRIBUTES_ADDRESS);
124
125
        $companyDirectorFqn =
126
            $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_DIRECTOR);
127
128
        $personFqn =
129
            $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_PERSON);
130
131
        $emailFqn =
132
            $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_EMAIL);
133
134
        $companyFqn =
135
            $this->getCopiedFqn(self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_COMPANY);
136
137
        $personDto = $this->getEntityDtoFactory()
138
                          ->createEmptyDtoFromEntityFqn($personFqn);
139
        $personDto->getAttributesEmails()->add(
140
            $this->getEntityDtoFactory()
141
                 ->createEmptyDtoFromEntityFqn($emailFqn)
142
                 ->setEmailAddress('[email protected]')
143
        );
144
145
        $companyDto = $this->getEntityDtoFactory()
146
                           ->createEmptyDtoFromEntityFqn($companyFqn);
147
148
        $companyDto->getCompanyDirectors()
149
                   ->add(
150
                       $this->getEntityDtoFactory()
151
                            ->createEmptyDtoFromEntityFqn($companyDirectorFqn)
152
                            ->setPersonDto($personDto)
153
                   );
154
155
        $companyDto->getAttributesAddresses()
156
                   ->add(
157
                       $this->getEntityDtoFactory()
158
                            ->createEmptyDtoFromEntityFqn($attributesAddressFqn)
159
                   );
160
161
        $companyDto->getAttributesEmails()
162
                   ->add(
163
                       $this->getEntityDtoFactory()
164
                            ->createEmptyDtoFromEntityFqn($emailFqn)
165
                            ->setEmailAddress('[email protected]')
166
                   );
167
168
        $company = $this->factory->create($companyFqn, $companyDto);
169
        self::assertInstanceOf($companyFqn, $company);
170
        self::assertInstanceOf($companyDirectorFqn, $company->getCompanyDirectors()->first());
171
        self::assertSame($company, $company->getCompanyDirectors()->first()->getCompanies()->first());
172
    }
173
}
174