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 (#214)
by joseph
21:10
created

FieldInterfaceCreatorTest::itRequiresTheSuffix()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Small\CodeGeneration\Creation\Src\Entity\Fields\Interfaces;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\CodeHelper;
6
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Src\Entity\Fields\Interfaces\FieldInterfaceCreator;
7
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FileFactory;
8
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FindReplaceFactory;
9
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File\Writer;
10
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper;
11
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\TypeHelper;
12
use EdmondsCommerce\DoctrineStaticMeta\Config;
13
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
14
use EdmondsCommerce\DoctrineStaticMeta\Tests\Small\ConfigTest;
15
use InvalidArgumentException;
16
use PHPUnit\Framework\TestCase;
17
18
/**
19
 * @small
20
 */
21
class FieldInterfaceCreatorTest extends TestCase
22
{
23
    /**
24
     * @test
25
     */
26
    public function itRequiresTheSuffix(): void
27
    {
28
        $newObjectFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entity\\Fields\\TestArray';
29
        $this->expectException(InvalidArgumentException::class);
30
        $this->expectExceptionMessage('$newObjectFqn must end in FieldInterface');
31
        $this->getCreator()->createTargetFileObject($newObjectFqn);
32
    }
33
34
    private function getCreator(): FieldInterfaceCreator
35
    {
36
        $namespaceHelper = new NamespaceHelper();
37
        $config          = new Config(ConfigTest::SERVER);
38
39
        return new FieldInterfaceCreator(
40
            new FileFactory($namespaceHelper, $config),
41
            $namespaceHelper,
42
            new Writer(),
43
            $config,
44
            new FindReplaceFactory(),
45
            new CodeHelper($namespaceHelper),
46
            new TypeHelper()
47
        );
48
    }
49
50
    public function provideTypesToDefaultsAndExpectedText(): array
51
    {
52
        return [
53
            MappingHelper::TYPE_STRING         => [MappingHelper::TYPE_STRING, 'foo', "'foo'"],
54
            MappingHelper::TYPE_BOOLEAN        => [MappingHelper::TYPE_BOOLEAN, true, 'true'],
55
            MappingHelper::TYPE_FLOAT          => [MappingHelper::TYPE_FLOAT, 2.2, '2.2'],
56
            MappingHelper::TYPE_FLOAT . '_int' => [MappingHelper::TYPE_FLOAT, 3, '3.0'],
57
            MappingHelper::TYPE_INTEGER        => [MappingHelper::TYPE_INTEGER, 4, '4'],
58
        ];
59
    }
60
61
    /**
62
     * @test
63
     * @dataProvider provideTypesToDefaultsAndExpectedText
64
     *
65
     * @param string $type
66
     * @param mixed  $default
67
     * @param string $match
68
     */
69
    public function itCanSetDefaultValues(string $type, $default, string $match): void
70
    {
71
        $newObjectFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entity\\Fields\\Traits\\Test'
72
                        . ucfirst($type) . 'FieldInterface';
73
        $contents     = $this->getCreator()
74
                             ->setMappingHelperCommonType($type)
75
                             ->setDefaultValue($default)
76
                             ->createTargetFileObject($newObjectFqn)
77
                             ->getTargetFile()
78
                             ->getContents();
79
        self::assertRegExp('%public const DEFAULT_.+? = ' . $match . '%', $contents);
0 ignored issues
show
Bug introduced by
It seems like $contents can also be of type null; however, parameter $string of PHPUnit\Framework\Assert::assertRegExp() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

79
        self::assertRegExp('%public const DEFAULT_.+? = ' . $match . '%', /** @scrutinizer ignore-type */ $contents);
Loading history...
80
    }
81
82
    /**
83
     * @test
84
     */
85
    public function itCanCreateABooleanFieldInterface(): void
86
    {
87
        $contents = $this->itCanCreateAFieldInterface(MappingHelper::TYPE_BOOLEAN);
88
        self::assertContains('function isTestBoolean(): ?bool', $contents);
89
    }
90
91
    /**
92
     * @test
93
     *
94
     * @param string $type
95
     *
96
     * @return string
97
     */
98
    public function itCanCreateAFieldInterface(string $type = MappingHelper::PHP_TYPE_ARRAY): string
99
    {
100
        $newObjectFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entity\\Fields\\Traits\\Test'
101
                        . ucfirst($type) . 'FieldInterface';
102
        $contents     = $this->getCreator()
103
                             ->setMappingHelperCommonType($type)
104
                             ->createTargetFileObject($newObjectFqn)
105
                             ->getTargetFile()
106
                             ->getContents();
107
        self::assertNotEmpty($contents);
108
109
        return $contents;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $contents could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
110
    }
111
112
    /**
113
     * @test
114
     */
115
    public function itCreatesStringFieldsWithExtraValidation(): void
116
    {
117
        $this->itCanCreateAFieldInterface(MappingHelper::PHP_TYPE_STRING);
118
    }
119
}
120