diff --git a/README.md b/README.md index a4384f3..493055f 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,4 @@ Roadmap 4. Implement mapping from form elements to object properties 5. Implement validators on form elements 6. Implement object association fields -x. ... \ No newline at end of file +7. ... \ No newline at end of file diff --git a/lib/FORM/FormManager.php b/lib/FORM/FormManager.php index 9df92e1..334c241 100644 --- a/lib/FORM/FormManager.php +++ b/lib/FORM/FormManager.php @@ -32,8 +32,9 @@ class FormManager /** * @param Configuration $config */ - public function __construct(\Doctrine\ORM\EntityManager $em, Configuration $config) + public function __construct(\Doctrine\ORM\EntityManager $em, Configuration $config = null) { + $this->_em = $em; $this->_config = $config; } @@ -44,7 +45,7 @@ public function __construct(\Doctrine\ORM\EntityManager $em, Configuration $conf */ public function getRepository($modelName) { - if (isset($this->_repositories[$modelName])) { + if (!isset($this->_repositories[$modelName])) { $this->_repositories[$modelName] = new FormRepository($this, $modelName); $this->_repositories[$modelName]->setEntityManager($this->getEntityManager()); } diff --git a/lib/FORM/FormRepository.php b/lib/FORM/FormRepository.php index 2710f83..fe5d3f4 100644 --- a/lib/FORM/FormRepository.php +++ b/lib/FORM/FormRepository.php @@ -53,9 +53,17 @@ public function getElement($propertyName){} * @param Doctrine\ORM\EntityManager $em * @return FormRepository */ - public function setEntityRepository($em) + public function setEntityManager($em) { $this->_em = $em; return $this; } + + /** + * @return Doctrine\ORM\EntityManager + */ + public function getEntityManager() + { + return $this->_em; + } } \ No newline at end of file diff --git a/nbproject/private/config.properties b/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.properties b/nbproject/private/private.properties new file mode 100644 index 0000000..e69de29 diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index b43b8d7..546224f 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -1,11 +1,5 @@ + - - file:/Users/mike/NetBeansProjects/FORM/README - file:/Users/mike/NetBeansProjects/FORM/lib/FORM/FormManager.php - file:/Users/mike/NetBeansProjects/FORM/lib/FORM/FormRepository.php - file:/Users/mike/NetBeansProjects/FORM/lib/FORM/Mapping/MetadataFactory.php - file:/Users/mike/NetBeansProjects/FORM/lib/FORM/Configuration.php - diff --git a/nbproject/project.properties b/nbproject/project.properties index a7aa623..d27f053 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,5 +1,8 @@ include.path=${php.global.include.path} php.version=PHP_53 +phpunit.bootstrap= +phpunit.configuration= +phpunit.suite= source.encoding=UTF-8 src.dir=. tags.asp=false diff --git a/tests/Test/FORM/AllTests.php b/tests/Test/FORM/AllTests.php new file mode 100644 index 0000000..63a782c --- /dev/null +++ b/tests/Test/FORM/AllTests.php @@ -0,0 +1,28 @@ +_em = $this->_getTestEntityManager(); + $this->_config = new \FORM\Configuration(); + $this->_fm = new \FORM\FormManager($this->_em, $this->_config); + } + + public function testConstructor() + { + $this->assertEquals($this->_em, $this->_fm->getEntityManager()); + $this->assertEquals($this->_config, $this->_fm->getConfiguration()); + } + + public function testGetRepository() + { + $repository = $this->_fm->getRepository('Test'); + $this->assertEquals('FORM\FormRepository', get_class($repository)); + $this->assertEquals($this->_em, $repository->getEntityManager()); + } +} \ No newline at end of file diff --git a/tests/Test/FORMTestCase.php b/tests/Test/FORMTestCase.php index 9c2be49..111c152 100644 --- a/tests/Test/FORMTestCase.php +++ b/tests/Test/FORMTestCase.php @@ -4,4 +4,63 @@ abstract class FORMTestCase extends \PHPUnit_Framework_TestCase { + /** The metadata cache that is shared between all ORM tests (except functional tests). */ + private static $_metadataCacheImpl = null; + /** The query cache that is shared between all ORM tests (except functional tests). */ + private static $_queryCacheImpl = null; + + /** + * Creates an EntityManager for testing purposes. + * + * NOTE: The created EntityManager will have its dependant DBAL parts completely + * mocked out using a DriverMock, ConnectionMock, etc. These mocks can then + * be configured in the tests to simulate the DBAL behavior that is desired + * for a particular test, + * + * @return Doctrine\ORM\EntityManager + */ + protected function _getTestEntityManager($conn = null, $conf = null, $eventManager = null, $withSharedMetadata = true) + { + $config = new \Doctrine\ORM\Configuration(); + if($withSharedMetadata) { + $config->setMetadataCacheImpl(self::getSharedMetadataCacheImpl()); + } else { + $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache); + } + + $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver()); + + $config->setQueryCacheImpl(self::getSharedQueryCacheImpl()); + $config->setProxyDir(__DIR__ . '/Proxies'); + $config->setProxyNamespace('Doctrine\Tests\Proxies'); + $eventManager = new \Doctrine\Common\EventManager(); + if ($conn === null) { + $conn = array( + 'driverClass' => 'Doctrine\Tests\Mocks\DriverMock', + 'wrapperClass' => 'Doctrine\Tests\Mocks\ConnectionMock', + 'user' => 'john', + 'password' => 'wayne' + ); + } + if (is_array($conn)) { + $conn = \Doctrine\DBAL\DriverManager::getConnection($conn, $config, $eventManager); + } + return \Doctrine\Tests\Mocks\EntityManagerMock::create($conn, $config, $eventManager); + } + + private static function getSharedMetadataCacheImpl() + { + if (self::$_metadataCacheImpl === null) { + self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache; + } + return self::$_metadataCacheImpl; + } + + private static function getSharedQueryCacheImpl() + { + if (self::$_queryCacheImpl === null) { + self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; + } + return self::$_queryCacheImpl; + } } \ No newline at end of file diff --git a/tests/Test/Functional/AllTests.php b/tests/Test/Functional/AllTests.php index dd3d1c8..4bdfdc3 100644 --- a/tests/Test/Functional/AllTests.php +++ b/tests/Test/Functional/AllTests.php @@ -3,7 +3,7 @@ namespace Test\Functional; if (!defined('PHPUnit_MAIN_METHOD')) { - define('PHPUnit_MAIN_METHOD', 'Common_AllTests::main'); + define('PHPUnit_MAIN_METHOD', 'Functional_AllTests::main'); } require_once __DIR__ . '/../Init.php'; diff --git a/tests/Test/Init.php b/tests/Test/Init.php index 23811c9..214466f 100644 --- a/tests/Test/Init.php +++ b/tests/Test/Init.php @@ -16,6 +16,9 @@ $classLoader = new \Doctrine\Common\ClassLoader('FORM', __DIR__ . "/../../lib"); $classLoader->register(); +$classLoader = new \Doctrine\Common\ClassLoader('Doctrine\Tests', __DIR__ . "/../../vendor/Doctrine2/tests"); +$classLoader->register(); + $classLoader = new \Doctrine\Common\ClassLoader('Doctrine', __DIR__ . "/../../vendor/Doctrine2/lib"); $classLoader->register();