public function testGetTypeName() { $int = new Variable('a', 1, CompiledExpression::INTEGER); parent::assertSame("integer", $int->getTypeName()); $double = new Variable('b', 1, CompiledExpression::DOUBLE); parent::assertSame("double", $double->getTypeName()); $number = new Variable('c', 1, CompiledExpression::NUMBER); parent::assertSame("number", $number->getTypeName()); $arr = new Variable('d', [1, 2], CompiledExpression::ARR); parent::assertSame("array", $arr->getTypeName()); $object = new Variable('e', 1, CompiledExpression::OBJECT); parent::assertSame("object", $object->getTypeName()); $resource = new Variable('f', 1, CompiledExpression::RESOURCE); parent::assertSame("resource", $resource->getTypeName()); $callable = new Variable('g', 1, CompiledExpression::CALLABLE_TYPE); parent::assertSame("callable", $callable->getTypeName()); $boolean = new Variable('h', 1, CompiledExpression::BOOLEAN); parent::assertSame("boolean", $boolean->getTypeName()); $null = new Variable('i', 1, CompiledExpression::NULL); parent::assertSame("null", $null->getTypeName()); $unknown = new Variable('j', 1, CompiledExpression::UNKNOWN); parent::assertSame("unknown", $unknown->getTypeName()); }
public function testEvalOpSuccess() { $baseExpression = new Node\Expr\Eval_($this->newScalarExpr("echo 'test';")); $compiledExpression = $this->compileExpression($baseExpression); parent::assertInstanceOfCompiledExpression($compiledExpression); parent::assertSame(CompiledExpression::NULL, $compiledExpression->getType()); parent::assertSame(null, $compiledExpression->getValue()); }
public function testExitOpSuccess() { $baseExpression = new Node\Expr\Exit_($this->newScalarExpr("test")); $compiledExpression = $this->compileExpression($baseExpression); parent::assertInstanceOfCompiledExpression($compiledExpression); parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); parent::assertSame("test", $compiledExpression->getValue()); }
public function testErrorSuppressSuccess() { $baseExpression = new Node\Expr\ErrorSuppress(new Node\Expr\Print_($this->newScalarExpr("test"))); $compiledExpression = $this->compileExpression($baseExpression); parent::assertInstanceOfCompiledExpression($compiledExpression); parent::assertSame(CompiledExpression::INTEGER, $compiledExpression->getType()); parent::assertSame(1, $compiledExpression->getValue()); }
/** * Tests echo $stmtTest = 2; creates the variable */ public function testEchoCreatesVar() { $context = $this->getContext(); $statement = new Node\Stmt\Echo_([new Node\Expr\Assign(new Node\Expr\Variable(new Node\Name("stmtTest")), $this->newScalarExpr(2))]); \PHPSA\nodeVisitorFactory($statement, $context); $variable = $context->getSymbol("stmtTest"); parent::assertTrue($variable instanceof Variable); }
/** * Tests if (1 == 1) { $stmtTest = 2; } creates the variable */ public function testIfStatementCreatesVar() { $context = $this->getContext(); $statement = new Node\Stmt\If_(new Node\Expr\BinaryOp\Equal($this->newScalarExpr(1), $this->newScalarExpr(1)), ["stmts" => [new Node\Expr\Assign(new Node\Expr\Variable(new Node\Name("stmtTest")), $this->newScalarExpr(2))]]); \PHPSA\nodeVisitorFactory($statement, $context); $variable = $context->getSymbol("stmtTest"); parent::assertTrue($variable instanceof Variable); }
public function testTernaryFalse() { // (2 == 3) ? "if" : "else" $baseExpression = new Node\Expr\Ternary(new Node\Expr\BinaryOp\Equal($this->newScalarExpr(2), $this->newScalarExpr(3)), $this->newScalarExpr("if"), $this->newScalarExpr("else")); $compiledExpression = $this->compileExpression($baseExpression); parent::assertInstanceOfCompiledExpression($compiledExpression); parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); parent::assertSame("else", $compiledExpression->getValue()); }
public function testEmptyVarNotExisting() { $context = $this->getContext(); $baseExpression = new Node\Expr\Empty_(new Node\Expr\Variable(new Node\Name("name"))); $compiledExpression = $this->compileExpression($baseExpression, $context); parent::assertInstanceOfCompiledExpression($compiledExpression); parent::assertSame(CompiledExpression::BOOLEAN, $compiledExpression->getType()); parent::assertFalse($compiledExpression->getValue()); }
public function testCoalesceVarNotExisting() { $context = $this->getContext(); $variable = new VariableNode(new Name("name")); $else = parent::newScalarExpr("else"); $baseExpression = new Node\Expr\BinaryOp\Coalesce($variable, $else); $compiledExpression = $this->compileExpression($baseExpression, $context); parent::assertInstanceOfCompiledExpression($compiledExpression); parent::assertSame(CompiledExpression::STRING, $compiledExpression->getType()); parent::assertSame("else", $compiledExpression->getValue()); }
/** * @param string $analyzerName * @return EventManager * @throws \Webiny\Component\EventManager\EventManagerException */ protected function getEventManager($analyzerName) { if (!class_exists($analyzerName, true)) { throw new \InvalidArgumentException("Analyzer with name: {$analyzerName} doesnot exist"); } /** @var \PHPSA\Analyzer\Pass\Metadata $metaData */ $metaData = $analyzerName::getMetadata(); if (!$metaData->allowsPhpVersion(PHP_VERSION)) { parent::markTestSkipped(sprintf('We cannot tests %s with %s because PHP required version is %s', $analyzerName, PHP_VERSION, $metaData->getRequiredPhpVersion())); } $analyzerConfiguration = $metaData->getConfiguration(); $analyzerConfiguration->attribute('enabled', true); $config = [$analyzerName::getMetadata()->getConfiguration()]; $em = EventManager::getInstance(); $configuration = new Configuration([], $config); \PHPSA\Analyzer\Factory::factory($em, $configuration); return $em; }
public function testFindYieldStatement() { $returnStatement = new \PhpParser\Node\Expr\Yield_(); parent::assertSame([$returnStatement], iterator_to_array($this->findYieldExpression([$returnStatement]))); }
/** * @dataProvider typesAsStringProvider */ public function testGetType($typeAsString, $expectedType) { parent::assertSame($expectedType, Types::getType($typeAsString)); }
public function testIsArrayWhenFalse() { $compiledExpression = new CompiledExpression(CompiledExpression::BOOLEAN); parent::assertFalse($compiledExpression->isArray()); }