From 6f96c661ef58a4d2b398f90bdedf52066ca6e2e2 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Mon, 16 Jul 2018 20:52:58 -0400 Subject: [PATCH] Fix #881 - skip tests if necessary test classes are missing --- tests/BinaryOperationTest.php | 120 +++++++++++++++++++++------------- tests/ClassTest.php | 63 +++++++++++------- 2 files changed, 112 insertions(+), 71 deletions(-) diff --git a/tests/BinaryOperationTest.php b/tests/BinaryOperationTest.php index 22c542f75..e62b1fedb 100644 --- a/tests/BinaryOperationTest.php +++ b/tests/BinaryOperationTest.php @@ -6,6 +6,80 @@ class BinaryOperationTest extends TestCase use Traits\FileCheckerInvalidCodeParseTestTrait; use Traits\FileCheckerValidCodeParseTestTrait; + /** + * @return void + */ + public function testGMPOperations() + { + if (class_exists('GMP') === false) { + $this->markTestSkipped('Cannot run test, base class "GMP" does not exist!'); + + return; + } + + $this->addFile( + 'somefile.php', + ' 'GMP', + '$b' => 'GMP', + '$c' => 'GMP', + '$d' => 'GMP', + '$f' => 'GMP', + '$g' => 'GMP', + '$h' => 'GMP', + '$i' => 'GMP', + '$j' => 'GMP', + '$k' => 'GMP', + '$l' => 'GMP', + '$m' => 'GMP', + '$n' => 'GMP', + '$o' => 'GMP', + '$p' => 'GMP', + '$q' => 'GMP', + '$r' => 'GMP', + '$s' => 'GMP', + '$t' => 'GMP', + ]; + + $context = new \Psalm\Context(); + + $this->analyzeFile('somefile.php', $context); + + $actual_vars = []; + foreach ($assertions as $var => $_) { + if (isset($context->vars_in_scope[$var])) { + $actual_vars[$var] = (string)$context->vars_in_scope[$var]; + } + } + + $this->assertSame($assertions, $actual_vars); + } + /** * @return array */ @@ -61,52 +135,6 @@ class BinaryOperationTest extends TestCase '$f' => 'string', ], ], - 'gmpOperations' => [ - ' [ - '$a' => 'GMP', - '$b' => 'GMP', - '$c' => 'GMP', - '$d' => 'GMP', - '$f' => 'GMP', - '$g' => 'GMP', - '$h' => 'GMP', - '$i' => 'GMP', - '$j' => 'GMP', - '$k' => 'GMP', - '$l' => 'GMP', - '$m' => 'GMP', - '$n' => 'GMP', - '$o' => 'GMP', - '$p' => 'GMP', - '$q' => 'GMP', - '$r' => 'GMP', - '$s' => 'GMP', - '$t' => 'GMP', - ], - ], 'booleanXor' => [ 'markTestSkipped('Cannot run test, base class "mysqli" does not exist!'); + + return; + } + + $this->addFile( + 'somefile.php', + ' [ - ' [ '