-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for value and composite expression (#86)
Add unit tests for value and composite expression
- Loading branch information
1 parent
4a9f909
commit 46a476a
Showing
2 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
tests/Doctrine/Tests/Common/Collections/Expr/CompositeExpressionTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Collections\Expr; | ||
|
||
use Doctrine\Common\Collections\Expr\CompositeExpression; | ||
use Doctrine\Common\Collections\Expr\ExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
|
||
/** | ||
* @author Tobias Oberrauch <[email protected]> | ||
* @covers \Doctrine\Common\Collections\Expr\CompositeExpression | ||
*/ | ||
class CompositeExpressionTest extends TestCase | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function invalidDataProvider() | ||
{ | ||
return array( | ||
array( | ||
'expression' => new Value('value'), | ||
), | ||
array( | ||
'expression' => 'wrong-type', | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider invalidDataProvider | ||
* | ||
* @param $expression | ||
* @return void | ||
*/ | ||
public function testExceptions($expression) | ||
{ | ||
$type = CompositeExpression::TYPE_AND; | ||
$expressions = array( | ||
$expression, | ||
); | ||
|
||
$this->setExpectedException('\RuntimeException'); | ||
new CompositeExpression($type, $expressions); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testGetType() | ||
{ | ||
$compositeExpression = $this->createCompositeExpression(); | ||
|
||
$expectedType = CompositeExpression::TYPE_AND; | ||
$actualType = $compositeExpression->getType(); | ||
|
||
$this->assertSame($expectedType, $actualType); | ||
} | ||
|
||
/** | ||
* @return CompositeExpression | ||
*/ | ||
protected function createCompositeExpression() | ||
{ | ||
$type = CompositeExpression::TYPE_AND; | ||
$expressions = array( | ||
$this->getMock('Doctrine\Common\Collections\Expr\Expression'), | ||
); | ||
|
||
$compositeExpression = new CompositeExpression($type, $expressions); | ||
|
||
return $compositeExpression; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testGetExpressionList() | ||
{ | ||
$compositeExpression = $this->createCompositeExpression(); | ||
|
||
$expectedExpressionList = array( | ||
$this->getMock('Doctrine\Common\Collections\Expr\Expression'), | ||
); | ||
$actualExpressionList = $compositeExpression->getExpressionList(); | ||
|
||
$this->assertEquals($expectedExpressionList, $actualExpressionList); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testVisitor() | ||
{ | ||
$compositeExpression = $this->createCompositeExpression(); | ||
|
||
$visitor = $this->getMockForAbstractClass('Doctrine\Common\Collections\Expr\ExpressionVisitor'); | ||
$visitor | ||
->expects($this->once()) | ||
->method('walkCompositeExpression'); | ||
|
||
/** @var ExpressionVisitor $visitor */ | ||
$compositeExpression->visit($visitor); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
tests/Doctrine/Tests/Common/Collections/Expr/ValueTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\Common\Collections\Expr; | ||
|
||
use Doctrine\Common\Collections\Expr\ExpressionVisitor; | ||
use Doctrine\Common\Collections\Expr\Value; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
|
||
/** | ||
* @author Tobias Oberrauch <[email protected]> | ||
* @covers \Doctrine\Common\Collections\Expr\Value | ||
*/ | ||
class ValueTest extends TestCase | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
public function testGetter() | ||
{ | ||
$value = 'foo'; | ||
$valueExpression = new Value($value); | ||
|
||
$actualValue = $valueExpression->getValue(); | ||
|
||
$this->assertEquals($value, $actualValue); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testVisitor() | ||
{ | ||
$visitor = $this->getMockForAbstractClass('Doctrine\Common\Collections\Expr\ExpressionVisitor'); | ||
$visitor | ||
->expects($this->once()) | ||
->method('walkValue'); | ||
|
||
/** @var ExpressionVisitor $visitor */ | ||
$value = 'foo'; | ||
$valueExpression = new Value($value); | ||
$valueExpression->visit($visitor); | ||
} | ||
} |