-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More Test coverage and a minor "use" fix.
- Loading branch information
Showing
6 changed files
with
306 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the h4cc/AliceFixtureBundle package. | ||
* | ||
* (c) Julius Beckmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace h4cc\AliceFixturesBundle\Tests; | ||
|
||
use h4cc\AliceFixturesBundle\ORM\DoctrineORMSchemaTool; | ||
|
||
/** | ||
* Class DoctrineORMSchemaToolTest | ||
* | ||
* @author Julius Beckmann <[email protected]> | ||
* @covers h4cc\AliceFixturesBundle\ORM\DoctrineORMSchemaTool | ||
*/ | ||
class DoctrineORMSchemaToolTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
private $managerRegistryMock; | ||
|
||
public function setUp() | ||
{ | ||
$this->managerRegistryMock = $this->getMockBuilder('\Doctrine\Common\Persistence\ManagerRegistry') | ||
->setMethods(array('getManagers')) | ||
->getMockForAbstractClass(); | ||
|
||
$this->managerRegistryMock->expects($this->any()) | ||
->method('getManagers') | ||
->will($this->returnValue(array())); | ||
} | ||
|
||
public function testConstruct() | ||
{ | ||
$schemaTool = new DoctrineORMSchemaTool($this->managerRegistryMock); | ||
|
||
$this->assertInstanceOf('\h4cc\AliceFixturesBundle\ORM\SchemaToolInterface', $schemaTool); | ||
} | ||
|
||
public function testDropSchema() | ||
{ | ||
$schemaTool = new DoctrineORMSchemaTool($this->managerRegistryMock); | ||
|
||
// Not testing any further here for now, because mocking for DoctrineSchemaTool needs some effort. | ||
$schemaTool->dropSchema(); | ||
} | ||
|
||
public function testCreateSchema() | ||
{ | ||
$schemaTool = new DoctrineORMSchemaTool($this->managerRegistryMock); | ||
|
||
// Not testing any further here for now, because mocking for DoctrineSchemaTool needs some effort. | ||
$schemaTool->createSchema(); | ||
} | ||
} | ||
|
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,180 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the h4cc/AliceFixtureBundle package. | ||
* | ||
* (c) Julius Beckmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace h4cc\AliceFixturesBundle\Tests; | ||
|
||
use h4cc\AliceFixturesBundle\ORM\Doctrine; | ||
|
||
/** | ||
* Class DoctrineTest | ||
* | ||
* @author Julius Beckmann <[email protected]> | ||
* @covers h4cc\AliceFixturesBundle\ORM\Doctrine | ||
*/ | ||
class DoctrineTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
private $managerMock; | ||
|
||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
private $managerRegistryMock; | ||
|
||
private $objects = array(); | ||
private $testObject; | ||
|
||
public function setUp() | ||
{ | ||
$this->managerMock = $this->getMockBuilder('\Doctrine\Common\Persistence\ObjectManager') | ||
->setMethods(array('persist', 'find', 'remove', 'merge', 'detach', 'flush')) | ||
->getMockForAbstractClass(); | ||
|
||
$this->managerRegistryMock = $this->getMockBuilder('\Doctrine\Common\Persistence\ManagerRegistry') | ||
->setMethods(array('getManagerForClass')) | ||
->getMockForAbstractClass(); | ||
|
||
$this->managerRegistryMock->expects($this->any()) | ||
->method('getManagerForClass') | ||
->will($this->returnValue($this->managerMock)); | ||
|
||
$this->objects = range('a', 'c'); | ||
$this->objects[] = $this->testObject = new \stdClass(); | ||
} | ||
|
||
public function testConstruct() | ||
{ | ||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$this->assertInstanceOf('\h4cc\AliceFixturesBundle\ORM\ORMInterface', $doctrine); | ||
} | ||
|
||
public function testPersist() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('persist'); | ||
$this->managerMock->expects($this->once())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$doctrine->persist($this->objects); | ||
} | ||
|
||
public function testPersistWithoutFlush() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('persist'); | ||
$this->managerMock->expects($this->never())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, false); | ||
|
||
$doctrine->persist($this->objects); | ||
} | ||
|
||
public function testMerge() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('merge') | ||
->will($this->returnValueMap(array( | ||
array('a', 'a_merged'), | ||
array('b', 'b_merged'), | ||
array('c', 'c_merged'), | ||
array($this->testObject, 'testObject_merged'), | ||
))); | ||
$this->managerMock->expects($this->never())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$mergedObjects = $doctrine->merge($this->objects); | ||
|
||
$this->assertEquals(array('a_merged', 'b_merged', 'c_merged', 'testObject_merged'), $mergedObjects); | ||
} | ||
|
||
public function testDetach() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('detach'); | ||
$this->managerMock->expects($this->never())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$doctrine->detach($this->objects); | ||
} | ||
|
||
public function testRemove() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('merge'); | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('remove'); | ||
$this->managerMock->expects($this->once())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$doctrine->remove($this->objects); | ||
} | ||
|
||
public function testRemoveWithoutFlush() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('merge'); | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('remove'); | ||
$this->managerMock->expects($this->never())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, false); | ||
|
||
$doctrine->remove($this->objects); | ||
} | ||
|
||
public function testFind() | ||
{ | ||
$this->managerMock->expects($this->exactly(count($this->objects)))->method('find') | ||
->will($this->returnValueMap(array( | ||
array('Some/Class', 0, 'a'), | ||
array('Some/Class', 1, 'b'), | ||
array('Some/Class', 2, 'c'), | ||
array('Some/Class', 3, $this->testObject), | ||
))); | ||
$this->managerMock->expects($this->never())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
foreach($this->objects as $index => $expectedEntity) { | ||
$entity = $doctrine->find('Some/Class', $index); | ||
$this->assertEquals($expectedEntity, $entity); | ||
} | ||
} | ||
|
||
/** | ||
* @expectedException \UnexpectedValueException | ||
* @expectedExceptionMessage Entity with Id 42 and Class Some/Class not found | ||
*/ | ||
public function testFindNotFoundException() | ||
{ | ||
$this->managerMock->expects($this->once())->method('find') | ||
->will($this->returnValueMap(array( | ||
array('Some/Class', 42, null), | ||
))); | ||
$this->managerMock->expects($this->never())->method('flush'); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$doctrine->find('Some/Class', 42); | ||
} | ||
|
||
/** | ||
* @expectedException \RuntimeException | ||
* @expectedExceptionMessage No ObjectManager for class Some/Class | ||
*/ | ||
public function testNoObjectManager() | ||
{ | ||
$this->managerRegistryMock = $this->getMockBuilder('\Doctrine\Common\Persistence\ManagerRegistry') | ||
->setMethods(array('getManagerForClass')) | ||
->getMockForAbstractClass(); | ||
$this->managerRegistryMock->expects($this->once())->method('getManagerForClass')->with('Some/Class')->willReturn(null); | ||
|
||
$doctrine = new Doctrine($this->managerRegistryMock, true); | ||
|
||
$doctrine->find('Some/Class', 42); | ||
} | ||
} | ||
|
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,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the h4cc/AliceFixtureBundle package. | ||
* | ||
* (c) Julius Beckmann <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace h4cc\AliceFixturesBundle\Tests; | ||
|
||
use h4cc\AliceFixturesBundle\ORM\MongoDBODMSchemaTool; | ||
|
||
/** | ||
* Class MongoDBODMSchemaToolTest | ||
* | ||
* @author Julius Beckmann <[email protected]> | ||
* @covers h4cc\AliceFixturesBundle\ORM\MongoDBODMSchemaTool | ||
*/ | ||
class MongoDBODMSchemaToolTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** @var \PHPUnit_Framework_MockObject_MockObject */ | ||
private $managerRegistryMock; | ||
|
||
public function setUp() | ||
{ | ||
$this->managerRegistryMock = $this->getMockBuilder('\Doctrine\Common\Persistence\ManagerRegistry') | ||
->setMethods(array('getManagers')) | ||
->getMockForAbstractClass(); | ||
|
||
$this->managerRegistryMock->expects($this->any()) | ||
->method('getManagers') | ||
->will($this->returnValue(array())); | ||
} | ||
|
||
public function testConstruct() | ||
{ | ||
$schemaTool = new MongoDBODMSchemaTool($this->managerRegistryMock); | ||
|
||
$this->assertInstanceOf('\h4cc\AliceFixturesBundle\ORM\SchemaToolInterface', $schemaTool); | ||
} | ||
|
||
public function testDropSchema() | ||
{ | ||
$schemaTool = new MongoDBODMSchemaTool($this->managerRegistryMock); | ||
|
||
// Not testing any further here for now, because mocking for DoctrineSchemaTool needs some effort. | ||
$schemaTool->dropSchema(); | ||
} | ||
|
||
public function testCreateSchema() | ||
{ | ||
$schemaTool = new MongoDBODMSchemaTool($this->managerRegistryMock); | ||
|
||
// Not testing any further here for now, because mocking for DoctrineSchemaTool needs some effort. | ||
$schemaTool->createSchema(); | ||
} | ||
} | ||
|