Skip to content

Commit e7beaf1

Browse files
authored
Fix test warnings (#335)
* Fix test warnings * Make PhpUnit more verbose when tests have warnings
1 parent 1cbbb90 commit e7beaf1

6 files changed

+61
-19
lines changed

Diff for: phpunit.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
colors="true"
77
executionOrder="defects"
88
cacheDirectory=".phpunit.cache"
9+
displayDetailsOnTestsThatTriggerWarnings="true"
910
>
1011
<testsuites>
1112
<testsuite name="main">

Diff for: src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public function refactor(Node $node): ?Node
5555

5656
$classMethods = $node->getMethods();
5757

58+
$hasChanged = false;
59+
5860
foreach ($node->stmts as $key => $stmt) {
5961
if (! $stmt instanceof ClassMethod) {
6062
continue;
@@ -68,12 +70,17 @@ public function refactor(Node $node): ?Node
6870

6971
if ($newNode instanceof ClassMethod) {
7072
$node->stmts[$key] = $newNode;
73+
$hasChanged = true;
7174
} elseif ($newNode === NodeVisitor::REMOVE_NODE) {
7275
unset($node->stmts[$key]);
76+
$hasChanged = true;
7377
}
7478
}
7579

76-
return $node;
80+
return $hasChanged
81+
? $node
82+
: null;
83+
7784
}
7885

7986
public function getRuleDefinition(): RuleDefinition

Diff for: src/Rector/Class_/AddExtendsAnnotationToModelFactoriesRector.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ public function refactor(Node $node): ?Node
8383
return null;
8484
}
8585

86+
$hasChanged = false;
87+
8688
foreach ($node->stmts as $stmt) {
8789
if (! $stmt instanceof Property) {
8890
continue;
@@ -92,32 +94,36 @@ public function refactor(Node $node): ?Node
9294
continue;
9395
}
9496

95-
$this->addExtendsPhpDocTag($node, $stmt);
97+
$hasChanged = $this->addExtendsPhpDocTag($node, $stmt);
98+
99+
break;
100+
}
96101

102+
if ($hasChanged) {
97103
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($node);
98104

99-
break;
105+
return $node;
100106
}
101107

102-
return $node;
108+
return null;
103109
}
104110

105-
public function addExtendsPhpDocTag(Node $node, Property $property): void
111+
private function addExtendsPhpDocTag(Node $node, Property $property): bool
106112
{
107113
if ($property->props === []) {
108-
return;
114+
return false;
109115
}
110116

111117
$modelName = $this->getModelName($property->props[0]->default);
112118

113119
if ($modelName === null) {
114-
return;
120+
return false;
115121
}
116122

117123
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
118124

119125
if ($phpDocInfo->hasByName(self::EXTENDS_TAG_NAME)) {
120-
return;
126+
return false;
121127
}
122128

123129
$phpDocTagNode = new PhpDocTagNode(self::EXTENDS_TAG_NAME, new ExtendsTagValueNode(
@@ -129,6 +135,8 @@ public function addExtendsPhpDocTag(Node $node, Property $property): void
129135
));
130136

131137
$phpDocInfo->addPhpDocTagNode($phpDocTagNode);
138+
139+
return true;
132140
}
133141

134142
private function getModelName(?Expr $expr): ?string

Diff for: src/Rector/Class_/ReplaceExpectsMethodsInTestsRector.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public function refactor(Node $node): ?Class_
8787
return null;
8888
}
8989

90+
$hasChanged = false;
91+
9092
foreach ($node->getMethods() as $classMethod) {
9193
$result = $this->expectedClassMethodAnalyzer->findExpectedJobCallsWithClassMethod($classMethod);
9294

@@ -96,6 +98,7 @@ public function refactor(Node $node): ?Class_
9698

9799
if ($result->isActionable()) {
98100
$this->fixUpClassMethod($classMethod, $result, 'Illuminate\Support\Facades\Bus');
101+
$hasChanged = true;
99102
}
100103

101104
$result = $this->expectedClassMethodAnalyzer->findExpectedEventCallsWithClassMethod($classMethod);
@@ -106,10 +109,14 @@ public function refactor(Node $node): ?Class_
106109

107110
if ($result->isActionable()) {
108111
$this->fixUpClassMethod($classMethod, $result, 'Illuminate\Support\Facades\Event');
112+
$hasChanged = true;
109113
}
110114
}
111115

112-
return $node;
116+
return $hasChanged
117+
? $node
118+
: null;
119+
113120
}
114121

115122
private function fixUpClassMethod(

Diff for: src/Rector/MethodCall/EloquentOrderByToLatestOrOldestRector.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ private function isOrderByMethodCall(MethodCall $methodCall): bool
112112

113113
private function isAllowedPattern(MethodCall $methodCall): bool
114114
{
115-
$columnArg = $methodCall->args[0] instanceof Arg ? $methodCall->args[0]->value : null;
115+
$columnArg = $methodCall->args !== [] && $methodCall->args[0] instanceof Arg
116+
? $methodCall->args[0]->value
117+
: null;
116118

117119
// If no patterns are specified, consider all column names as matching
118120
if ($this->allowedPatterns === []) {
@@ -142,19 +144,19 @@ private function isAllowedPattern(MethodCall $methodCall): bool
142144
return false;
143145
}
144146

145-
private function convertOrderByToLatest(MethodCall $methodCall): MethodCall
147+
private function convertOrderByToLatest(MethodCall $methodCall): ?MethodCall
146148
{
147149
if (! isset($methodCall->args[0]) && ! $methodCall->args[0] instanceof VariadicPlaceholder) {
148-
return $methodCall;
150+
return null;
149151
}
150152

151153
$columnVar = $methodCall->args[0] instanceof Arg ? $methodCall->args[0]->value : null;
152154
if (! $columnVar instanceof Expr) {
153-
return $methodCall;
155+
return null;
154156
}
155157

156158
if (isset($methodCall->args[1]) && (! $methodCall->args[1] instanceof Arg || ! $methodCall->args[1]->value instanceof String_)) {
157-
return $methodCall;
159+
return null;
158160
}
159161

160162
if (isset($methodCall->args[1]) && $methodCall->args[1] instanceof Arg && $methodCall->args[1]->value instanceof String_) {

Diff for: src/Rector/MethodCall/UseComponentPropertyWithinCommandsRector.php

+22-5
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,36 @@ public function refactor(Node $node): ?Node
7878
return null;
7979
}
8080

81+
$hasChanged = false;
82+
8183
foreach ($node->stmts as $key => $stmt) {
8284
if (! $stmt instanceof ClassMethod) {
8385
continue;
8486
}
8587

86-
$node->stmts[$key] = $this->refactorClassMethod($stmt);
88+
$changedClassMethod = $this->refactorClassMethod($stmt);
89+
90+
if ($changedClassMethod instanceof ClassMethod) {
91+
$node->stmts[$key] = $changedClassMethod;
92+
93+
$hasChanged = true;
94+
}
8795
}
8896

89-
return $node;
97+
return $hasChanged
98+
? $node
99+
: null;
100+
90101
}
91102

92-
private function refactorClassMethod(ClassMethod $classMethod): ClassMethod
103+
private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod
93104
{
94105
if ($classMethod->stmts === null) {
95-
return $classMethod;
106+
return null;
96107
}
97108

109+
$hasChanged = false;
110+
98111
foreach ($classMethod->stmts as $stmt) {
99112
if (! $stmt instanceof Expression) {
100113
continue;
@@ -123,8 +136,12 @@ private function refactorClassMethod(ClassMethod $classMethod): ClassMethod
123136

124137
$stmt->expr->var =
125138
new PropertyFetch(new Variable('this'), 'components');
139+
140+
$hasChanged = true;
126141
}
127142

128-
return $classMethod;
143+
return $hasChanged
144+
? $classMethod
145+
: null;
129146
}
130147
}

0 commit comments

Comments
 (0)