Browse Source

DX: ControlCaseStructuresAnalyzerTest - cleanup (#6874)

Dariusz Rumiński 1 year ago
parent
commit
0b56d6bb9d
2 changed files with 7 additions and 14 deletions
  1. 1 1
      phpstan.dist.neon
  2. 6 13
      tests/Tokenizer/Analyzer/ControlCaseStructuresAnalyzerTest.php

+ 1 - 1
phpstan.dist.neon

@@ -26,6 +26,6 @@ parameters:
         -
             message: '#Call to static method .+ with .+ will always evaluate to true.$#'
             path: tests
-            count: 19
+            count: 18
     tipsOfTheDay: false
     tmpDir: dev-tools/phpstan/cache

+ 6 - 13
tests/Tokenizer/Analyzer/ControlCaseStructuresAnalyzerTest.php

@@ -402,22 +402,12 @@ $expressionResult = match ($condition) {
         $this->expectException(\InvalidArgumentException::class);
         $this->expectExceptionMessage(sprintf('Unexpected type "%d".', T_IF));
 
-        foreach (ControlCaseStructuresAnalyzer::findControlStructures($tokens, [T_IF]) as $analysis) {
-            echo 1; // we need to use `foreach` here to prevent PHP removing the call as optimization
-        }
+        // we use `iterator_to_array` to ensure generator is consumed and it has possibility to raise exception
+        iterator_to_array(ControlCaseStructuresAnalyzer::findControlStructures($tokens, [T_IF]));
     }
 
     private static function assertAnalysis(AbstractControlCaseStructuresAnalysis $expectedAnalysis, AbstractControlCaseStructuresAnalysis $analysis): void
     {
-        $serializeExpected = serialize($expectedAnalysis);
-        $serializeActual = serialize($analysis);
-
-        if ($serializeExpected === $serializeActual) {
-            self::assertTrue(true);
-
-            return;
-        }
-
         self::assertSame($expectedAnalysis->getIndex(), $analysis->getIndex(), 'index');
         self::assertSame($expectedAnalysis->getOpenIndex(), $analysis->getOpenIndex(), 'open index');
         self::assertSame($expectedAnalysis->getCloseIndex(), $analysis->getCloseIndex(), 'close index');
@@ -447,6 +437,9 @@ $expressionResult = match ($condition) {
             }
         }
 
-        self::assertSame($serializeExpected, $serializeActual);
+        self::assertSame(
+            serialize($expectedAnalysis),
+            serialize($analysis)
+        );
     }
 }