Skip to content

Commit

Permalink
rename getProxyDirectory and allow to set it
Browse files Browse the repository at this point in the history
add a little acceptance/functional test
  • Loading branch information
pscheit committed Oct 29, 2013
1 parent e2dd068 commit e685887
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/Webforge/Doctrine/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\ORM\Tools\Setup;
use InvalidArgumentException;
use LogicException;
use Webforge\Common\System\Dir;

/**
* A Container for the full configuratino and business objects from the doctrine module
Expand Down Expand Up @@ -46,6 +47,11 @@ class Container {
*/
protected $connectionsConfiguration;

/**
* @var Webforge\Common\System\Dir
*/
protected $proxyDirectory;

/**
* @param array $connectionsConfiguration every array should have the con-name as key and name, password, dbname, host, charset as sub-keys
*/
Expand All @@ -59,7 +65,7 @@ function($dir) {
$entitiesPath
);

$this->configuration = Setup::createAnnotationMetadataConfiguration($entitiesPath, $isDevMode, $this->getProxyDir(), $this->getCache());
$this->configuration = Setup::createAnnotationMetadataConfiguration($entitiesPath, $isDevMode, $this->getProxyDirectory(), $this->getCache());
}

/**
Expand Down Expand Up @@ -147,7 +153,7 @@ protected function normalizeConnections(Array $dbsConfiguration) {
}

if (count($connections) === 1) {
$connections['default'] = current($connection);
$connections['default'] = current($connections);
}

if(!array_key_exists('default', $connections)) {
Expand All @@ -163,8 +169,17 @@ protected function normalizeConnections(Array $dbsConfiguration) {
* if NULL a system tmp dir will be used
* @return Dir|NULL
*/
public function getProxyDir() {
return NULL;
public function getProxyDirectory() {
return $this->proxyDirectory;
}

/**
* Set where to write doctrine proxies to
* @chainable
*/
public function setProxyDirectory(Dir $dir) {
$this->proxyDirectory = $dir;
return $this;
}

/**
Expand Down
28 changes: 28 additions & 0 deletions lib/Webforge/Doctrine/Test/SchemaTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Webforge\Doctrine\Test;

use Webforge\Doctrine\Util;

/**
* A testcase that requires that the schema for the entities is used
*/
class SchemaTestCase extends Base {

public static $schemaCreated = FALSE;

public function setUp() {
parent::setUp();

$this->dcc->initDoctrine(
$this->frameworkHelper->getBootContainer()->getProject()->getConfiguration()->get(array('db')),
$this->entitiesPaths = array($this->getTestDirectory('Entities/'))
);

if (!self::$schemaCreated) {
$this->dcc->getUtil()->updateSchema('tests', Util::FORCE, $eol = "\n");

self::$schemaCreated = TRUE;
}
}
}
63 changes: 63 additions & 0 deletions tests/Webforge/Doctrine/ContainerConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,40 @@ public static function invalidConfigurationArrays() {
)
);

$test(
array(
'default'=>$valid,
'tests'=>array(
'database'=>'acme-blog',
'user'=>'',
'password'=>'r0adrunn3r',
'driver'=>'pdo_sqlite'
)
)
);

$test(
array(
'tests'=>array(
'database'=>'acme-blog',
'user'=>'',
'password'=>'r0adrunn3r',
'driver'=>'pdo_sqlite'
)
)
);

$test(
array(
'tests'=>array(
'database'=>'',
'user'=>'roadrunner',
'password'=>'r0adrunn3r',
'driver'=>NULL
)
)
);

$test(
array(
'tests'=>$valid,
Expand Down Expand Up @@ -136,6 +170,26 @@ public function testDocumentationConfigurationExample() {
*/
}

public function testSingleDefaultKeyAcceptanceTest() {
$this->container->initDoctrine(
array(
'default'=>$config = array(
'database'=>'acme-blog',
'user'=>'acme',
'password'=>'r0adrunn3r',
'driver'=>'pdo_mysql',
)
),
$this->entitiesPaths
);

$config['charset'] = 'utf8';
$config['host'] = '127.0.0.1';
$config['port'] = NULL;
$em = $this->container->getEntityManager();
$this->assertEntityManagerHasConfig($em, $config, 'default');
}

protected function initDefault() {
$this->container->initDoctrine($this->dbConfigArray, $this->entitiesPaths);
}
Expand All @@ -160,6 +214,15 @@ public function testConfigurationCacheIsArrayByDefault() {
);
}

public function testContainerCanHaveTheProxyDirectoryInjected() {
$dir = new Dir(__DIR__.DIRECTORY_SEPARATOR);

$this->container->setProxyDirectory($dir);
$this->assertSame($dir, $this->container->getProxyDirectory());

// @TODO can we test that doctrine gets it?
}

protected function assertEntityManagerHasConfig(EntityManager $em, Array $config, $con = 'default') {
$connectionParams = array(
'database'=>'getDatabase',
Expand Down
31 changes: 31 additions & 0 deletions tests/Webforge/Doctrine/ContainerEntitiesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Webforge\Doctrine;

use Doctrine\Tests\Models\Company\CompanyCar;

class ContainerEntitiesTest extends \Webforge\Doctrine\Test\SchemaTestCase {

protected $container;

public function setUp() {
$this->chainClass = 'Webforge\\Doctrine\\Container';
parent::setUp();

$this->em = $this->dcc->getEntityManager('tests');
}

public function testEntityManagerFIndsTheEntyLoadedFromTestFiles() {
$this->assertNull($this->em->find('Doctrine\Tests\Models\Company\CompanyCar', 1));

$car = new CompanyCar('Ford');
$this->em->persist($car);
$this->em->flush();
$this->em->clear();

$this->assertInstanceOf(
'Doctrine\Tests\Models\Company\CompanyCar',
$this->em->find('Doctrine\Tests\Models\Company\CompanyCar', 1)
);
}
}
33 changes: 33 additions & 0 deletions tests/files/Entities/Doctrine/Tests/Models/Company/CompanyCar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Doctrine\Tests\Models\Company;

/**
* @Entity
* @Table(name="company_cars")
*/
class CompanyCar
{
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @Column(type="string", length=50)
*/
private $brand;

public function __construct($brand = null) {
$this->brand = $brand;
}

public function getId() {
return $this->id;
}

public function getBrand() {
return $this->title;
}
}

0 comments on commit e685887

Please sign in to comment.