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 (#153)
by joseph
20:25
created

EmbeddableCreatorTest::getCreator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Small\CodeGeneration\Creation\Src\Entity\Embeddable\Objects;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Embeddable\Objects\EmbeddableCreator;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FileFactory;
7
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FindReplaceFactory;
8
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File\Writer;
9
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
10
use EdmondsCommerce\DoctrineStaticMeta\Config;
11
use EdmondsCommerce\DoctrineStaticMeta\Tests\Small\ConfigTest;
12
use PHPUnit\Framework\TestCase;
13
14
class EmbeddableCreatorTest extends TestCase
15
{
16
    private const EXPECTED_FILE = <<<'PHP'
17
<?php declare(strict_types=1);
18
19
namespace Test\Project\Entity\Embeddable\Objects\Foo;
20
21
use Doctrine\ORM\Mapping\ClassMetadata;
22
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\AbstractEmbeddableObject;
23
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
24
use Test\Project\Entity\Embeddable\Interfaces\Foo\HasBarEmbeddableInterface;
25
use Test\Project\Entity\Embeddable\Interfaces\Objects\Foo\BarEmbeddableInterface;
26
27
class BarEmbeddable extends AbstractEmbeddableObject implements BarEmbeddableInterface
28
{
29
    /**
30
     * @var string
31
     */
32
    private $propertyOne;
33
    /**
34
     * @var string
35
     */
36
    private $propertyTwo;
37
38
    public function __construct(string $propertyOne, string $propertyTwo)
39
    {
40
        $this->validate($propertyOne, $propertyTwo);
41
        $this->propertyOne = $propertyOne;
42
        $this->propertyTwo = $propertyTwo;
43
    }
44
45
    private function validate(string $propertyOne, string $propertyTwo): void
46
    {
47
        $errors = [];
48
        if ('' === $propertyOne) {
49
            $errors[] = 'property one is empty';
50
        }
51
        if ('' === $propertyTwo) {
52
            $errors[] = 'property two is empty';
53
        }
54
        if ([] === $errors) {
55
            return;
56
        }
57
        throw new \InvalidArgumentException('Invalid arguments: ' . print_r($errors, true));
58
    }
59
60
    /**
61
     * @param ClassMetadata $metadata
62
     * @SuppressWarnings(PHPMD.StaticAccess)
63
     */
64
    public static function loadMetadata(ClassMetadata $metadata): void
65
    {
66
        $builder = self::setEmbeddableAndGetBuilder($metadata);
67
        MappingHelper::setSimpleFields(
68
            [
69
                BarEmbeddableInterface::EMBEDDED_PROP_PROPERTY_ONE => MappingHelper::TYPE_STRING,
70
                BarEmbeddableInterface::EMBEDDED_PROP_PROPERTY_TWO => MappingHelper::TYPE_STRING,
71
            ],
72
            $builder
73
        );
74
    }
75
76
    public function __toString(): string
77
    {
78
        return (string)print_r(
79
            [
80
                'barEmbeddable' => [
81
                    BarEmbeddableInterface::EMBEDDED_PROP_PROPERTY_ONE => $this->getPropertyOne(),
82
                    BarEmbeddableInterface::EMBEDDED_PROP_PROPERTY_TWO => $this->getPropertyTwo(),
83
                ],
84
            ],
85
            true
86
        );
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getPropertyOne(): string
93
    {
94
        return $this->propertyOne;
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function getPropertyTwo(): string
101
    {
102
        return $this->propertyTwo;
103
    }
104
105
    protected function getPrefix(): string
106
    {
107
        return HasBarEmbeddableInterface::PROP_BAR_EMBEDDABLE;
108
    }
109
}
110
PHP;
111
112
113
    /**
114
     * @test
115
     */
116
    public function itCanCreateTheFile(): void
117
    {
118
        $file     = $this->getCreator()
119
                         ->setCatName('Foo')
120
                         ->setName('Bar')
121
                         ->createTargetFileObject()
122
                         ->getTargetFile();
123
        $expected = self::EXPECTED_FILE;
124
        $actual   = $file->getContents();
125
        self::assertSame($expected, $actual);
126
    }
127
128
    private function getCreator(): EmbeddableCreator
129
    {
130
        $namespaceHelper = new NamespaceHelper();
131
        $config          = new Config(ConfigTest::SERVER);
132
133
        $creator = new EmbeddableCreator(
134
            new FileFactory($namespaceHelper, $config),
135
            $namespaceHelper,
136
            new Writer(),
137
            $config,
138
            new FindReplaceFactory()
139
        );
140
        $creator->setProjectRootNamespace('Test\Project');
141
142
        return $creator;
143
    }
144
}