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 */ public function providerValidCodeParse() { return [ 'regularAddition' => [ ' [ '$a' => 'int', ], ], 'differingNumericTypesAdditionInWeakMode' => [ ' [ '$a' => 'float', ], ], 'modulo' => [ ' [ '$a' => 'int', '$b' => 'int', '$c' => 'int', '$d' => 'int', ], ], 'numericAddition' => [ ' [ ' [ ' [ ' [], 'error_levels' => ['PossiblyFalseOperand'], ], 'bitwiseoperations' => [ '> 2; $f = "a" & "b";', 'assertions' => [ '$a' => 'int', '$b' => 'int', '$c' => 'int', '$d' => 'int', '$e' => 'int', '$f' => 'string', ], ], 'booleanXor' => [ ' [ '$a' => 'int', '$b' => 'int', '$c' => 'bool', '$d' => 'bool', ], ], 'ternaryAssignment' => [ ' [ ' [ ' [ '$a' => 'float', '$b' => 'float', ], ], ]; } /** * @return array */ public function providerInvalidCodeParse() { return [ 'badAddition' => [ ' 'InvalidOperand', ], 'differingNumericTypesAdditionInStrictMode' => [ ' 'InvalidOperand', 'error_levels' => [], 'strict_mode' => true, ], 'concatenationWithNumberInStrictMode' => [ ' 'InvalidOperand', 'error_levels' => [], 'strict_mode' => true, ], 'addArrayToNumber' => [ ' 'InvalidOperand', 'error_levels' => [], 'strict_mode' => true, ], 'additionWithClassInWeakMode' => [ ' 'InvalidOperand', ], 'possiblyInvalidOperand' => [ ' 'PossiblyInvalidOperand', ], 'possiblyInvalidConcat' => [ ' 'PossiblyInvalidOperand', ], 'invalidGMPOperation' => [ ' 'InvalidOperand - src/somefile.php:3 - Cannot add GMP to non-numeric type', ], 'stringIncrement' => [ ' 'InvalidOperand', ], 'falseIncrement' => [ ' 'FalseOperand', ], 'trueIncrement' => [ ' 'InvalidOperand', ], 'possiblyDivByZero' => [ ' 'PossiblyNullOperand', ], ]; } }