forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneratorsTest.php
More file actions
119 lines (102 loc) · 3.45 KB
/
GeneratorsTest.php
File metadata and controls
119 lines (102 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Commands\Generators;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\StreamFilterTrait;
use PHPUnit\Framework\Attributes\Group;
/**
* @internal
*/
#[Group('Others')]
final class GeneratorsTest extends CIUnitTestCase
{
use StreamFilterTrait;
public function testGenerateFileCreated(): void
{
command('make:seeder categories');
$this->assertStringContainsString('File created: ', $this->getStreamFilterBuffer());
$file = APPPATH . 'Database/Seeds/Categories.php';
if (is_file($file)) {
unlink($file);
}
}
public function testGenerateFileExists(): void
{
command('make:filter items');
$this->assertStringContainsString('File created: ', $this->getStreamFilterBuffer());
$this->resetStreamFilterBuffer();
command('make:filter items');
$this->assertStringContainsString('File exists: ', $this->getStreamFilterBuffer());
$file = APPPATH . 'Filters/Items.php';
if (is_file($file)) {
unlink($file);
}
}
public function testGenerateFileOverwritten(): void
{
command('make:controller products');
$this->assertStringContainsString('File created: ', $this->getStreamFilterBuffer());
$this->resetStreamFilterBuffer();
command('make:controller products -force');
$this->assertStringContainsString('File overwritten: ', $this->getStreamFilterBuffer());
$file = APPPATH . 'Controllers/Products.php';
if (is_file($file)) {
unlink($file);
}
}
public function testGenerateFileFailsOnUnwritableDirectory(): void
{
if (is_windows()) {
$this->markTestSkipped('chmod does not work as expected on Windows');
}
chmod(APPPATH . 'Filters', 0444);
command('make:filter permissions');
$this->assertStringContainsString('Error while creating file: ', $this->getStreamFilterBuffer());
chmod(APPPATH . 'Filters', 0755);
}
public function testGenerateFailsOnUndefinedNamespace(): void
{
command('make:model cars -namespace CodeIgnite');
$this->assertStringContainsString('Namespace "CodeIgnite" is not defined.', $this->getStreamFilterBuffer());
}
public function testGenerateFileInSubfolders(): void
{
command('make:controller admin/user');
$file = APPPATH . 'Controllers/Admin/User.php';
$dir = dirname($file);
$this->assertFileExists($file);
$this->assertDirectoryExists($dir);
if (is_file($file)) {
unlink($file);
}
if (is_dir($dir)) {
rmdir($dir);
}
}
public function testSuffixingHasNoEffect(): void
{
command('make:foo bar --suffix');
$file1 = APPPATH . 'Commands/Bar.php';
$file2 = APPPATH . 'Commands/BarCommand.php';
$dir = dirname($file1);
$this->assertFileExists($file1);
$this->assertFileDoesNotExist($file2);
if (is_file($file1)) {
unlink($file1);
}
if (is_file($file2)) {
unlink($file2);
}
if (is_dir($dir)) {
rmdir($dir);
}
}
}