Skip to content

Commit

Permalink
Add unit tests for value and composite expression (#86)
Browse files Browse the repository at this point in the history
Add unit tests for value and composite expression
  • Loading branch information
Tobias Oberrauch authored and mikeSimonson committed May 27, 2016
1 parent 4a9f909 commit 46a476a
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 0 deletions.
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 tests/Doctrine/Tests/Common/Collections/Expr/ValueTest.php
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);
}
}

0 comments on commit 46a476a

Please sign in to comment.