Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Add more tests for expression analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Levin committed Sep 13, 2014
1 parent 185a565 commit 6111454
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Tests/Integration/Analysis/BasicExpressionAnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ function () { $var; },
['var' => $this->typeSystem->getTypeFromValue(fopen('php://memory', 'r'))]);
}

public function testInvalidVariable()
{
$this->assertAnalysisFails(function ($foo) { $bar; });
}

public function testCasts()
{
$values = [
Expand Down Expand Up @@ -441,4 +446,35 @@ function () use ($value) { $value; },
);
}
}

public function testConstantTypeAnalysis()
{
$this->assertReturnsNativeType(
function () { SORT_ASC; },
INativeType::TYPE_INT
);

$this->assertReturnsNativeType(
function () { M_PI; },
INativeType::TYPE_DOUBLE
);
}

public function testClassConstantTypeAnalysis()
{
$this->assertReturnsNativeType(
function () { \ArrayObject::ARRAY_AS_PROPS; },
INativeType::TYPE_INT
);

$this->assertReturnsNativeType(
function () { \DateTime::ATOM; },
INativeType::TYPE_STRING
);
}

public function testInvalidClassConstantTypeAnalysis()
{
$this->assertAnalysisFails(function ($foo) { $foo::ARRAY_AS_PROPS; });
}
}
13 changes: 13 additions & 0 deletions Tests/Integration/Analysis/TypeAnalysisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,19 @@ function (ITypeAnalysis $analysis, O\BinaryOperationExpression $expression) use
}
}

public function testThrow()
{
$this->doAnalysisTest(
function () { throw new \LogicException(); },
function (ITypeAnalysis $analysis, O\ThrowExpression $expression) {
$this->assertTypeMatchesValue(
$analysis,
$expression->getException(),
$this->typeSystem->getObjectType('LogicException'));
}
);
}

/**
* @expectedException \Pinq\Analysis\TypeException
*/
Expand Down

0 comments on commit 6111454

Please sign in to comment.