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
16:19
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' . ucfirst($type) . 'FieldInterface';
72
        $contents     = $this->getCreator()
73
                             ->setMappingHelperCommonType($type)
74
                             ->setDefaultValue($default)
75
                             ->createTargetFileObject($newObjectFqn)
76
                             ->getTargetFile()
77
                             ->getContents();
78
        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

78
        self::assertRegExp('%public const DEFAULT_.+? = ' . $match . '%', /** @scrutinizer ignore-type */ $contents);
Loading history...
79
    }
80
81
    /**
82
     * @test
83
     */
84
    public function itCanCreateABooleanFieldInterface(): void
85
    {
86
        $contents = $this->itCanCreateAFieldInterface(MappingHelper::TYPE_BOOLEAN);
87
        self::assertContains('function isTestBoolean(): ?bool', $contents);
88
    }
89
90
    /**
91
     * @test
92
     *
93
     * @param string $type
94
     *
95
     * @return string
96
     */
97
    public function itCanCreateAFieldInterface(string $type = MappingHelper::PHP_TYPE_ARRAY): string
98
    {
99
        $newObjectFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entity\\Fields\\Traits\\Test' . ucfirst($type) . 'FieldInterface';
100
        $contents     = $this->getCreator()
101
                             ->setMappingHelperCommonType($type)
102
                             ->createTargetFileObject($newObjectFqn)
103
                             ->getTargetFile()
104
                             ->getContents();
105
        self::assertNotEmpty($contents);
106
107
        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...
108
    }
109
110
    /**
111
     * @test
112
     */
113
    public function itCreatesStringFieldsWithExtraValidation(): void
114
    {
115
        $contents = $this->itCanCreateAFieldInterface(MappingHelper::PHP_TYPE_STRING);
0 ignored issues
show
Unused Code introduced by
The assignment to $contents is dead and can be removed.
Loading history...
116
    }
117
}
118