Issues (57)

tests/Feature/GenerateFilesTest.php (3 issues)

1
<?php
2
3
namespace Shamaseen\Repository\Tests\Feature;
4
5
use Illuminate\Support\Facades\Config;
6
use PHPUnit\Framework\Attributes\DataProvider;
0 ignored issues
show
The type PHPUnit\Framework\Attributes\DataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Shamaseen\Repository\Commands\Generator;
8
use Shamaseen\Repository\PathResolver;
9
use Shamaseen\Repository\Tests\TestCase;
10
11
class GenerateFilesTest extends TestCase
12
{
13
    private array $filesToGenerate = ['Controller', 'Repository', 'Model', 'Request', 'Resource', 'Collection', 'Policy', 'Test'];
14
15
    /**
16
     * @param string $dataName
17
     */
18
    public function __construct(?string $name = null, array $data = [], $dataName = '')
19
    {
20
        parent::__construct($name, $data, $dataName);
0 ignored issues
show
The call to PHPUnit\Framework\TestCase::__construct() has too many arguments starting with $data. ( Ignorable by Annotation )

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

20
        parent::/** @scrutinizer ignore-call */ 
21
                __construct($name, $data, $dataName);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
It seems like $name can also be of type null; however, parameter $name of PHPUnit\Framework\TestCase::__construct() 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

20
        parent::__construct(/** @scrutinizer ignore-type */ $name, $data, $dataName);
Loading history...
21
    }
22
23
    public function testGenerate()
24
    {
25
        $this->artisan("generate:repository $this->userPath/$this->modelName -f");
26
27
        foreach ($this->filesToGenerate as $type) {
28
            $absolutePath = $this->generator->absolutePath(
29
                $this->pathResolver->outputPath($type)
30
            );
31
32
            $this->assertFileExists($absolutePath);
33
        }
34
    }
35
36
    public function testGenerateMCROnly()
37
    {
38
        $this->artisan("generate:repository $this->userPath/$this->modelName -f -mrc");
39
40
        $filesToGenerate = ['Controller', 'Repository', 'Model'];
41
        foreach ($filesToGenerate as $type) {
42
            $absolutePath = $this->generator->absolutePath(
43
                $this->pathResolver->outputPath($type)
44
            );
45
46
            $this->assertFileExists($absolutePath);
47
        }
48
    }
49
50
    public static function defaultStubsConfigProvider(): array
51
    {
52
        return [
53
            // run 1
54
            [
55
                [
56
                    Generator::RESOURCE_OPTION
57
                ],
58
                [
59
                    'Resource',
60
                ]
61
            ],
62
            // run 2
63
            [
64
                [
65
                    Generator::MODEL_OPTION,
66
                    Generator::CONTROLLER_OPTION,
67
                ],
68
                [
69
                    'Model',
70
                    'Controller',
71
                ],
72
            ],
73
            // running Request option should only generate Request
74
            [
75
                [
76
                    Generator::REQUEST_OPTION,
77
                ],
78
                [
79
                    'Request',
80
                ]
81
            ],
82
            // running Collection option should only generate Collection
83
            [
84
                [
85
                    Generator::COLLECTION_OPTION,
86
                ],
87
                [
88
                    'Collection',
89
                ]
90
            ],
91
        ];
92
    }
93
94
    #[DataProvider('defaultStubsConfigProvider')]
95
    public function testDefaultStubsConfig(array $config, array $generatedNames)
96
    {
97
        Config::set('repository.default_generated_files', $config);
98
        $this->artisan("generate:repository $this->userPath/$this->modelName -f");
99
100
        foreach ($generatedNames as $generatedName) {
101
            $this->assertFileExists($this->generator->absolutePath(
102
                $this->pathResolver->outputPath($generatedName)
103
            ));
104
        }
105
106
        $allGeneratedStubs = array_keys(PathResolver::$configTypePathMap);
107
        $filesNotGenerated = array_diff($allGeneratedStubs, $generatedNames);
108
109
        foreach ($filesNotGenerated as $fileNotGenerated) {
110
            $this->assertFileDoesNotExist($this->generator->absolutePath(
111
                $this->pathResolver->outputPath($fileNotGenerated)
112
            ));
113
        }
114
    }
115
}
116