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

CreateDbalFieldAndInterfaceActionTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 45
dl 0
loc 97
rs 10
c 1
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 10 1
A itCanCreateANewFieldAndInterfaceForEachType() 0 18 2
A provideTypes() 0 17 1
A getProviderData() 0 16 3
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Medium\CodeGeneration\Action;
4
5
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Action\CreateDbalFieldAndInterfaceAction;
6
use EdmondsCommerce\DoctrineStaticMeta\MappingHelper;
7
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
8
9
/**
10
 * @medium
11
 */
12
class CreateDbalFieldAndInterfaceActionTest extends AbstractTest
13
{
14
15
    public const WORK_DIR = AbstractTest::VAR_PATH . '/' . AbstractTest::TEST_TYPE_MEDIUM
16
                            . '/CreateDbalFieldAndInterfaceActionTest';
17
18
    private const BASE_FIELD_TRAIT_NS = self::TEST_PROJECT_ROOT_NAMESPACE . '\\Entity\\Fields\\Traits';
19
    private const BASE_TRAIT_PATH     = self::WORK_DIR . '/src/Entity/Fields/Traits';
20
    private const BASE_INTERFACE_PATH = self::WORK_DIR . '/src/Entity/Fields/Interfaces';
21
22
    public function provideTypes(): array
23
    {
24
        $toMerge   = [];
25
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_STRING, 'foo', true);
26
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_STRING, 'foo', false);
27
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_BOOLEAN, null, null);
28
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_BOOLEAN, true, null);
29
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_INTEGER, 10, true);
30
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_INTEGER, 100, false);
31
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_INTEGER, null, true);
32
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_FLOAT, 10, null);
33
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_ARRAY, null, null);
34
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_OBJECT, null, null);
35
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_DATETIME, null, null);
36
        $toMerge[] = $this->getProviderData(MappingHelper::TYPE_TEXT, 'blah', null);
37
38
        return array_merge(...$toMerge);
39
    }
40
41
    /**
42
     * @param string    $mappingHelperCommonType
43
     * @param mixed     $defaultValue
44
     * @param bool|null $unique
45
     *
46
     * @return array
47
     */
48
    private function getProviderData(string $mappingHelperCommonType, $defaultValue, ?bool $unique): array
49
    {
50
        $uniqueName  = $unique ? 'Unique' : '';
51
        $defaultName = (null === $defaultValue) ? (string)$defaultValue : 'null';
52
        $typeName    = ucfirst(str_replace('\\', '', $mappingHelperCommonType));
53
        $name        = $uniqueName . ucfirst($defaultName) . $typeName;
54
55
        return [
56
            $name =>
57
                [
58
                    self::BASE_FIELD_TRAIT_NS . '\\' . ucfirst($mappingHelperCommonType) . '\\' . $name . 'FieldTrait',
59
                    $mappingHelperCommonType,
60
                    $defaultValue,
61
                    $unique,
62
                    self::BASE_TRAIT_PATH . '/' . $typeName . '/' . $name . 'FieldTrait.php',
63
                    self::BASE_INTERFACE_PATH . '/' . $typeName . '/' . $name . 'FieldInterface.php',
64
                ],
65
        ];
66
    }
67
68
    /**
69
     * @test
70
     * @dataProvider provideTypes
71
     *
72
     * @param string    $fqn
73
     * @param string    $type
74
     * @param mixed     $defaultValue
75
     * @param bool|null $unique
76
     * @param string    $fieldPath
77
     * @param string    $interfacePath
78
     */
79
    public function itCanCreateANewFieldAndInterfaceForEachType(
80
        string $fqn,
81
        string $type,
82
        $defaultValue,
83
        ?bool $unique,
84
        string $fieldPath,
85
        string $interfacePath
86
    ): void {
87
        $action = $this->getAction();
88
        $action->setFieldTraitFqn($fqn);
89
        $action->setMappingHelperCommonType($type);
90
        $action->setDefaultValue($defaultValue);
91
        if (null !== $unique) {
92
            $action->setIsUnique($unique);
93
        }
94
        $action->run();
95
        self::assertFileExists($fieldPath);
96
        self::assertFileExists($interfacePath);
97
    }
98
99
    private function getAction(): CreateDbalFieldAndInterfaceAction
100
    {
101
        /**
102
         * @var CreateDbalFieldAndInterfaceAction $action
103
         */
104
        $action = $this->container->get(CreateDbalFieldAndInterfaceAction::class)
105
                                  ->setProjectRootDirectory(self::WORK_DIR)
106
                                  ->setProjectRootNamespace(self::TEST_PROJECT_ROOT_NAMESPACE);
107
108
        return $action;
109
    }
110
}
111