Permalink
Browse files

[!] Test Model\Currency fixed

  • Loading branch information...
1 parent 3e100a7 commit b1aec5173529897ac3992be76637ad559aee3389 @svowl svowl committed Jun 7, 2012
Showing with 16 additions and 21 deletions.
  1. +16 −19 .dev/tests/Classes/Model/Currency.php
  2. +0 −2 .dev/tests/PHPUnit/TestCase.php
@@ -80,7 +80,7 @@ public function testCreate()
$this->assertEquals($o, $c->getOrders()->get(0), 'check order');
try {
- $this->getTestCurrency();
+ $this->getTestCurrency(true);
$this->fail('check code unique failed');
} catch (\PDOException $e) {
@@ -106,15 +106,12 @@ public function testUpdate()
$c->setName('Test 2');
$c->setCode('ZZZ');
- \XLite\Core\Database::getEM()->persist($c);
- \XLite\Core\Database::getEM()->flush();
-
- \XLite\Core\Database::getEM()->clear();
+ $c->update();
- $c = \XLite\Core\Database::getRepo('XLite\Model\Currency')->find($c->getCurrencyId());
+ $c2 = \XLite\Core\Database::getRepo('XLite\Model\Currency')->find($c->getCurrencyId());
- $this->assertEquals('Test 2', $c->getName(), 'check new name');
- $this->assertEquals('ZZZ', $c->getCode(), 'check new code');
+ $this->assertEquals('Test 2', $c2->getName(), 'check new name');
+ $this->assertEquals('ZZZ', $c2->getCode(), 'check new code');
}
/**
@@ -236,11 +233,10 @@ public function testFormatValue()
protected function setUp()
{
- parent::setUp();
- $c = \XLite\Core\Database::getRepo("XLite\Model\Currency")->find(999);
- if ($c) {
- \XLite\Core\Database::getEM()->remove($c);
- \XLite\Core\Database::getEM()->flush();
+ try {
+ parent::setUp();
+ } catch (\Doctrine\Common\Annotations\AnnotationException $e) {
+ echo 'Exception';
}
$this->currency = $this->getTestCurrency();
}
@@ -259,14 +255,15 @@ protected function tearDown()
* @see ____func_see____
* @since 1.0.13
*/
- protected function getTestCurrency()
+ protected function getTestCurrency($forceCreate = false)
{
- $c = new \XLite\Model\Currency();
-
- $c->map($this->testData);
+ $c = \XLite\Core\Database::getRepo("XLite\Model\Currency")->find(999);
- \XLite\Core\Database::getEM()->persist($c);
- \XLite\Core\Database::getEM()->flush();
+ if ($forceCreate || !$c) {
+ $c = new \XLite\Model\Currency();
+ $c->map($this->testData);
+ $c->update();
+ }
return $c;
}
@@ -156,9 +156,7 @@ protected function setUp()
} catch (\Doctrine\ORM\ORMException $e) {
if ('The EntityManager is closed.' == $e->getMessage()) {
-
\XLite\Core\Database::getInstance()->startEntityManager();
- xlite(true);
} else {
throw $e;

0 comments on commit b1aec51

Please sign in to comment.