|
1 | 1 | <?php |
2 | 2 |
|
3 | | -namespace Tempest\Generation\Tests; |
| 3 | +namespace Tempest\Generation\Tests\Fixtures; |
4 | 4 |
|
5 | | -use PHPUnit\Framework\Attributes\Test; |
6 | | -use Tempest\Generation\ClassManipulator; |
7 | | -use Tempest\Generation\Tests\Fixtures\CreateMigrationsTable; |
8 | | -use Tempest\Generation\Tests\Fixtures\Database\MigrationModel; |
9 | | -use Tempest\Generation\Tests\Fixtures\TestAttribute; |
10 | | -use Tempest\Generation\Tests\Fixtures\WelcomeController; |
11 | | -use Tempest\Support\StringHelper; |
12 | | - |
13 | | -/** |
14 | | - * @internal |
15 | | - */ |
16 | | -final class ClassManipulatorTest extends TestCase |
| 5 | +final readonly class ClassFromFile |
17 | 6 | { |
18 | | - public function test_from_file(): void |
19 | | - { |
20 | | - $class = new ClassManipulator(__FILE__); |
21 | | - |
22 | | - $this->assertMatchesSnapshot($class->print()); |
23 | | - } |
24 | | - |
25 | | - #[Test] |
26 | | - public function updates_namespace(): void |
27 | | - { |
28 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
29 | | - $class->setNamespace('App'); |
30 | | - |
31 | | - $this->assertMatchesSnapshot($class->print()); |
32 | | - } |
33 | | - |
34 | | - #[Test] |
35 | | - public function updates_namespace_multiple_times(): void |
36 | | - { |
37 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
38 | | - $class->setNamespace('App'); |
39 | | - $class->setNamespace('Database'); |
40 | | - |
41 | | - $this->assertMatchesSnapshot($class->print()); |
42 | | - } |
43 | | - |
44 | | - #[Test] |
45 | | - public function removes_class_attributes(): void |
46 | | - { |
47 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
48 | | - $class->removeClassAttribute(TestAttribute::class); |
49 | | - |
50 | | - $this->assertMatchesSnapshot($class->print()); |
51 | | - } |
52 | | - |
53 | | - #[Test] |
54 | | - public function sets_class_final(): void |
55 | | - { |
56 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
57 | | - $class->setFinal(true); |
58 | | - |
59 | | - $this->assertMatchesSnapshot($class->print()); |
60 | | - } |
61 | | - |
62 | | - #[Test] |
63 | | - public function unsets_class_final(): void |
64 | | - { |
65 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
66 | | - $class->setFinal(false); |
67 | | - |
68 | | - $this->assertMatchesSnapshot($class->print()); |
69 | | - } |
70 | | - |
71 | | - #[Test] |
72 | | - public function sets_class_readonly(): void |
73 | | - { |
74 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
75 | | - $class->setReadOnly(true); |
76 | | - |
77 | | - $this->assertMatchesSnapshot($class->print()); |
78 | | - } |
79 | | - |
80 | | - #[Test] |
81 | | - public function unsets_class_readonly(): void |
82 | | - { |
83 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
84 | | - $class->setReadOnly(false); |
85 | | - |
86 | | - $this->assertMatchesSnapshot($class->print()); |
87 | | - } |
88 | | - |
89 | | - #[Test] |
90 | | - public function sets_strict_types(): void |
91 | | - { |
92 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
93 | | - $class->setStrictTypes(true); |
94 | | - |
95 | | - $this->assertMatchesSnapshot($class->print()); |
96 | | - } |
97 | | - |
98 | | - #[Test] |
99 | | - public function unsets_strict_types(): void |
100 | | - { |
101 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
102 | | - $class->setStrictTypes(false); |
103 | | - |
104 | | - $this->assertMatchesSnapshot($class->print()); |
105 | | - } |
106 | | - |
107 | | - #[Test] |
108 | | - public function does_not_simplify_implements_when_specified(): void |
109 | | - { |
110 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
111 | | - $class->simplifyImplements(false); |
112 | | - |
113 | | - $this->assertMatchesSnapshot($class->print()); |
114 | | - } |
115 | | - |
116 | | - #[Test] |
117 | | - public function set_aliases(): void |
118 | | - { |
119 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
120 | | - $class->setAlias(MigrationModel::class, 'Model'); |
121 | | - |
122 | | - $this->assertMatchesSnapshot($class->print()); |
123 | | - } |
124 | | - |
125 | | - #[Test] |
126 | | - public function simplifies_class_names_by_default(): void |
127 | | - { |
128 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
129 | | - |
130 | | - $this->assertMatchesSnapshot($class->print()); |
131 | | - } |
132 | | - |
133 | | - #[Test] |
134 | | - public function does_not_simplify_class_names_by_default(): void |
135 | | - { |
136 | | - $class = new ClassManipulator(CreateMigrationsTable::class); |
137 | | - $class->simplifyClassNamesInMethodBodies(false); |
138 | | - |
139 | | - $this->assertMatchesSnapshot($class->print()); |
140 | | - } |
141 | | - |
142 | | - #[Test] |
143 | | - public function transforms_functions(): void |
144 | | - { |
145 | | - $class = new ClassManipulator(WelcomeController::class); |
146 | | - $class->setNamespace('App\\Controllers'); |
147 | | - $class->setClassName('WelcomeController'); |
148 | | - |
149 | | - $this->assertMatchesSnapshot($class->print()); |
150 | | - } |
151 | | - |
152 | | - #[Test] |
153 | | - public function manipulates_classes(): void |
154 | | - { |
155 | | - $class = new ClassManipulator(WelcomeController::class); |
156 | | - $class->setNamespace('App\\Controllers'); |
157 | | - $class->setClassName('WelcomeController'); |
158 | | - $class->manipulate(fn (StringHelper $string) => $string->replace('welcome', 'home')); |
159 | | - |
160 | | - $this->assertMatchesSnapshot($class->print()); |
161 | | - } |
162 | 7 | } |
0 commit comments