-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add factory method to create NQM from Doctrine EntityManager
- Loading branch information
Florian Eckerstorfer
committed
Feb 11, 2015
1 parent
034ba1d
commit 4529d6a
Showing
2 changed files
with
82 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of cocur/nqm. | ||
* | ||
* (c) Florian Eckerstorfer <florian@eckerstorfer.co> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cocur\NQM\Bridge\Doctrine; | ||
|
||
use Doctrine\ORM\EntityManager; | ||
use Cocur\NQM\QueryLoader\QueryLoaderInterface; | ||
use Cocur\NQM\NQM; | ||
|
||
/** | ||
* NQMFactory | ||
* | ||
* @package cocur/nqm | ||
* @subpackage bridge | ||
* @author Florian Eckerstorfer <florian@eckerstorfer.co> | ||
* @copyright 2013-2015 Florian Eckerstorfer | ||
* @license http://opensource.org/licenses/MIT The MIT License | ||
*/ | ||
class NQMFactory | ||
{ | ||
/** | ||
* @param EntityManager $em | ||
* @param QueryLoaderInterface $queryLoader | ||
* | ||
* @return NQM | ||
*/ | ||
public static function createFromEntityManager(EntityManager $em, QueryLoaderInterface $queryLoader) | ||
{ | ||
return new NQM($em->getConnection()->getWrappedConnection(), $queryLoader); | ||
} | ||
} |
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 | ||
|
||
/** | ||
* This file is part of cocur/nqm. | ||
* | ||
* (c) Florian Eckerstorfer <florian@eckerstorfer.co> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Cocur\NQM\Bridge\Doctrine; | ||
|
||
use Mockery as m; | ||
use Pseudo\Pdo; | ||
|
||
class NQMFactoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
* @covers Cocur\NQM\Bridge\Doctrine\NQMFactory::createFromEntityManager() | ||
*/ | ||
public function createFromEntityManager() | ||
{ | ||
$conn = m::mock('Doctrine\DBAL\Connection'); | ||
$conn->shouldReceive('getWrappedConnection')->andReturn($this->getMockPdo()); | ||
|
||
$em = m::mock('Doctrine\ORM\EntityManager'); | ||
$em->shouldReceive('getConnection')->andReturn($conn); | ||
|
||
$queryLoader = m::mock('Cocur\NQM\QueryLoader\QueryLoaderInterface'); | ||
|
||
$this->assertInstanceOf('Cocur\NQM\NQM', NQMFactory::createFromEntityManager($em, $queryLoader)); | ||
} | ||
|
||
/** | ||
* @return \PDO | ||
*/ | ||
protected function getMockPdo() | ||
{ | ||
return new Pdo(); | ||
} | ||
} |