Skip to content

Commit 3fecdb8

Browse files
committed
Improved order for test class elements
1 parent 8be3b63 commit 3fecdb8

3 files changed

Lines changed: 52 additions & 76 deletions

File tree

src/FixerFactory.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,21 @@ public static function createFor(string $launchFile): Config
8585
];
8686

8787
$srcOrder = [
88-
'use_trait', 'case',
89-
'constant_public', 'constant_protected', 'constant_private',
88+
'use_trait', 'case', 'constant_public', 'constant_protected', 'constant_private',
9089
'property_public_static', 'property_protected_static', 'property_private_static',
9190
'method_public_static', 'method_protected_static', 'method_private_static',
9291
'property_public', 'property_protected', 'property_private',
93-
'construct', 'phpunit', 'magic', 'destruct',
94-
'method_public', 'method_protected', 'method_private'
92+
'construct', 'magic', 'method_public', 'destruct', 'method_protected', 'method_private'
9593
];
9694

9795
$testOrder = [
98-
'use_trait', 'case',
99-
'constant_public', 'constant_protected', 'constant_private',
96+
'use_trait', 'constant_public', 'constant_protected', 'constant_private',
10097
'property_public_static', 'property_protected_static', 'property_private_static',
10198
'property_public', 'property_protected', 'property_private',
10299
'construct', 'phpunit', 'magic', 'destruct',
103-
'method_public', 'method_protected', 'method_private',
104-
'method_public_static', 'method_protected_static', 'method_private_static'
100+
'method_public', 'method_public_static',
101+
'method_protected', 'method_protected_static',
102+
'method_private', 'method_private_static'
105103
];
106104

107105
self::$rules['Polymorphine/double_line_before_class_definition'] = true;

tests/Fixer/MultiOrderedClassElementsFixerTest.php

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,25 @@ class ExampleClass extends BaseExample implements ExampleInterface
2828
private $self;
2929
3030
/** someMethod phpDoc */
31-
public function someMethod()
32-
{
33-
//code...
34-
}
31+
public function someMethod() {}
3532
3633
public static function notConstructor(): SomeType
3734
{
38-
//code without 'self' return type
3935
}
4036
4137
final public static function staticConstructor(array $data): BaseExample
4238
{
43-
//return new self()
4439
}
4540
4641
/**
4742
* Static constructor with phpDoc
4843
*/
4944
public static function fromData(array $data): self
5045
{
51-
//return new self()
5246
}
5347
5448
public static function staticInterfaceConstructor(array $data): ExampleInterface
5549
{
56-
//return new self()
5750
}
5851
}
5952

@@ -67,33 +60,26 @@ class ExampleClass extends BaseExample implements ExampleInterface
6760
6861
public static function notConstructor(): SomeType
6962
{
70-
//code without 'self' return type
7163
}
7264
7365
final public static function staticConstructor(array $data): BaseExample
7466
{
75-
//return new self()
7667
}
7768
7869
/**
7970
* Static constructor with phpDoc
8071
*/
8172
public static function fromData(array $data): self
8273
{
83-
//return new self()
8474
}
8575
8676
public static function staticInterfaceConstructor(array $data): ExampleInterface
8777
{
88-
//return new self()
8978
}
9079
private $self;
9180
9281
/** someMethod phpDoc */
93-
public function someMethod()
94-
{
95-
//code...
96-
}
82+
public function someMethod() {}
9783
}
9884

9985
CODE;
@@ -108,36 +94,33 @@ public function testClassWithTestNameIsOrderedWithTestConfig()
10894
10995
class ExampleClassTest extends BaseExample implements ExampleInterface
11096
{
111-
public static function notConstructor(): SomeType
112-
{
113-
//code without 'self' return type
114-
}
97+
public static function notConstructor(): SomeType {}
11598
11699
private $self;
117100
118101
/** someMethod phpDoc */
119-
public function someMethod()
120-
{
121-
//code...
122-
}
102+
public function someMethod() {}
123103
124-
final public static function staticConstructor(array $data): BaseExample
125-
{
126-
//return new self()
127-
}
104+
private function getTestedClass(): ExampleClass {}
105+
106+
public static function tearDownAfterClass(): void {}
107+
108+
protected function tearDown(): void {}
109+
110+
private static function assertSomething(): void {}
111+
112+
protected static function staticConstructor(array $data): BaseExample {}
113+
114+
public static function setUpBeforeClass(): void {}
128115
129116
/**
130117
* Static constructor with phpDoc
131118
*/
132-
public static function fromData(array $data): self
133-
{
134-
//return new self()
135-
}
119+
public static function fromData(array $data): self {}
136120
137-
public static function staticInterfaceConstructor(array $data): ExampleInterface
138-
{
139-
//return new self()
140-
}
121+
public function test_Instantiation() {}
122+
123+
public static function staticInterfaceConstructor(array $data): ExampleInterface {}
141124
}
142125

143126
CODE;
@@ -150,33 +133,30 @@ class ExampleClassTest extends BaseExample implements ExampleInterface
150133
151134
private $self;
152135
136+
public static function setUpBeforeClass(): void {}
137+
138+
public static function tearDownAfterClass(): void {}
139+
140+
protected function tearDown(): void {}
141+
153142
/** someMethod phpDoc */
154-
public function someMethod()
155-
{
156-
//code...
157-
}
158-
public static function notConstructor(): SomeType
159-
{
160-
//code without 'self' return type
161-
}
143+
public function someMethod() {}
162144
163-
final public static function staticConstructor(array $data): BaseExample
164-
{
165-
//return new self()
166-
}
145+
public function test_Instantiation() {}
146+
public static function notConstructor(): SomeType {}
167147
168148
/**
169149
* Static constructor with phpDoc
170150
*/
171-
public static function fromData(array $data): self
172-
{
173-
//return new self()
174-
}
151+
public static function fromData(array $data): self {}
175152
176-
public static function staticInterfaceConstructor(array $data): ExampleInterface
177-
{
178-
//return new self()
179-
}
153+
public static function staticInterfaceConstructor(array $data): ExampleInterface {}
154+
155+
protected static function staticConstructor(array $data): BaseExample {}
156+
157+
private function getTestedClass(): ExampleClass {}
158+
159+
private static function assertSomething(): void {}
180160
}
181161

182162
CODE;
@@ -187,23 +167,21 @@ public static function staticInterfaceConstructor(array $data): ExampleInterface
187167
protected function fixer(): FixerInterface
188168
{
189169
$srcOrder = [
190-
'use_trait', 'case',
191-
'constant_public', 'constant_protected', 'constant_private',
170+
'use_trait', 'case', 'constant_public', 'constant_protected', 'constant_private',
192171
'property_public_static', 'property_protected_static', 'property_private_static',
193172
'method_public_static', 'method_protected_static', 'method_private_static',
194173
'property_public', 'property_protected', 'property_private',
195-
'construct', 'phpunit', 'magic', 'destruct',
196-
'method_public', 'method_protected', 'method_private'
174+
'construct', 'magic', 'method_public', 'destruct', 'method_protected', 'method_private'
197175
];
198176

199177
$testOrder = [
200-
'use_trait', 'case',
201-
'constant_public', 'constant_protected', 'constant_private',
178+
'use_trait', 'constant_public', 'constant_protected', 'constant_private',
202179
'property_public_static', 'property_protected_static', 'property_private_static',
203180
'property_public', 'property_protected', 'property_private',
204181
'construct', 'phpunit', 'magic', 'destruct',
205-
'method_public', 'method_protected', 'method_private',
206-
'method_public_static', 'method_protected_static', 'method_private_static'
182+
'method_public', 'method_public_static',
183+
'method_protected', 'method_protected_static',
184+
'method_private', 'method_private_static'
207185
];
208186

209187
return new MultiOrderedClassElementsFixer($srcOrder, $testOrder);

tests/Fixtures/code-samples/Fixer/expected-ClassOrder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ public function setUpBeforeClass(): void
4949
{
5050
}
5151

52-
private function setUp()
53-
{
54-
}
55-
5652
public function doPublic(): void
5753
{
5854
}
@@ -64,4 +60,8 @@ protected function doProtected()
6460
private function doPrivate()
6561
{
6662
}
63+
64+
private function setUp()
65+
{
66+
}
6767
}

0 commit comments

Comments
 (0)