Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update Doctrine ORM mapper tests

  • Loading branch information...
commit 6b48c5f3f6db2fa81b6094c4e67f0befee60d6dc 1 parent 03a91aa
@adamlundrigan adamlundrigan authored
View
22 tests/CdliTwoStageSignupTest/Framework/DoctrineORMMapperTestCase.php
@@ -10,7 +10,6 @@ class DoctrineORMMapperTestCase extends TestCase
public function setUp()
{
parent::setUp();
- $this->db = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
$this->dbSchemaDown();
$this->dbSchemaUp();
}
@@ -27,13 +26,32 @@ protected function dbSchemaUp()
protected function importSchema($file)
{
+ $conn = $this->getDBALConnection();
$sqlfile = explode(';',file_get_contents($file));
foreach ( $sqlfile as $sqlStmt ) {
$sqlStmt = trim($sqlStmt);
if ( !empty($sqlStmt) ) {
- $this->db->query($sqlStmt)->execute();
+ $conn->executeQuery($sqlStmt);
}
}
}
+ protected $em;
+ protected function getEntityManager()
+ {
+ if (is_null($this->em)) {
+ $this->em = $this->getServiceLocator()->get('zfcuser_doctrine_em');
+ }
+ return $this->em;
+ }
+
+ protected $conn;
+ protected function getDBALConnection()
+ {
+ if (is_null($this->conn)) {
+ $this->conn = $this->getEntityManager()->getConnection();
+ }
+ return $this->conn;
+ }
+
}
View
24 tests/CdliTwoStageSignupTest/Mapper/DoctrineORMMapperTest.php
@@ -38,20 +38,21 @@ public function testPersist()
// Find the inserted record and verify it was created properly
$result = $this->_queryFindByRequestKey($this->model->getRequestKey());
- $this->assertInternalType('array', $result);
- $this->assertEquals($this->model->getRequestKey(), $result['request_key']);
- $this->assertEquals($this->model->getEmailAddress(), $result['email_address']);
- $this->assertEquals($this->model->getRequestTime()->format('Y-m-d H:i:s'), $result['request_time']);
+ $this->assertInstanceOf('CdliTwoStageSignup\Entity\EmailVerification', $result);
+ $this->assertEquals($this->model->getRequestKey(), $result->getRequestKey());
+ $this->assertEquals($this->model->getEmailAddress(), $result->getEmailAddress());
+ $this->assertEquals($this->model->getRequestTime(), $result->getRequestTime());
}
public function testRemove()
{
$this->importSchema(__DIR__ . '/_files/singlerecord.sql');
- $model = $this->mapper->remove($this->model);
+ $model = $this->_queryFindByRequestKey('DCE2D890895CF02');
+ $model = $this->mapper->remove($model);
// Verify that it was removed
$result = $this->_queryFindByRequestKey($this->model->getRequestKey());
- $this->assertFalse($result);
+ $this->assertNull($result);
}
public function testFindByEmail()
@@ -80,9 +81,9 @@ public function testCleanExpiredVerificationRequests()
$this->mapper->cleanExpiredVerificationRequests();
- $set = $this->db->query('SELECT * FROM '.$this->db->platform->quoteIdentifier('user_signup_email_verification'))->execute();
- $this->assertEquals(1, $set->count());
- $actualEntity = $set->current();
+ $set = $this->getDBALConnection()->executeQuery('SELECT * FROM user_signup_email_verification')->fetchAll();
+ $this->assertEquals(1, count($set));
+ $actualEntity = array_pop($set);
$this->assertEquals($m->getRequestKey(), $actualEntity['request_key']);
$this->assertEquals($m->getEmailAddress(), $actualEntity['email_address']);
$this->assertEquals($m->getRequestTime()->format('Y-m-d H:i:s'), $actualEntity['request_time']);
@@ -90,9 +91,8 @@ public function testCleanExpiredVerificationRequests()
protected function _queryFindByRequestKey($key)
{
- $stmt = $this->db->query('SELECT * FROM '.$this->db->platform->quoteIdentifier('user_signup_email_verification').' WHERE request_key = ' . $this->db->driver->formatParameterName('id'));
- $results = $stmt->execute(array('id'=>$key));
- return $results->current();
+ $repo = $this->em->getRepository('CdliTwoStageSignup\Entity\EmailVerification');
+ return $repo->findOneBy(array('request_key' => $key));
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.