Author: ornicar2
Date: 2010-02-10 20:44:03 +0100 (Wed, 10 Feb 2010)
New Revision: 27844
Added:
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/unit/dmProjectTest.php
Modified:
plugins/diemPlugin/trunk/dmCorePlugin/lib/project/dmProject.php
Log:
[Diem]
- refactored some dmProject classes methods to avoid code duplication
- added unit tests for dmProject class
Modified: plugins/diemPlugin/trunk/dmCorePlugin/lib/project/dmProject.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/project/dmProject.php
2010-02-10 19:43:11 UTC (rev 27843)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/project/dmProject.php
2010-02-10 19:44:03 UTC (rev 27844)
@@ -40,11 +40,9 @@
{
if (null === self::$models)
{
- self::$models = array();
- foreach(glob(dmOs::join(sfConfig::get('sf_lib_dir'),
'model/doctrine/base/Base*.class.php')) as $baseModel)
- {
- self::$models[] = preg_replace('|^Base(\w+).class.php$|', '$1',
basename($baseModel));
- }
+ $baseFiles = glob(dmOs::join(sfConfig::get('sf_lib_dir'),
'model/doctrine/base/Base*.class.php'));
+
+ self::$models = self::getModelsFromBaseFiles($baseFiles);
}
return self::$models;
@@ -54,15 +52,11 @@
{
if (null === self::$allModels)
{
- $baseModels = sfFinder::type('file')
+ $baseFiles = sfFinder::type('file')
->name('/^Base\w+.class.php$/i')
->in(dmOs::join(sfConfig::get('sf_lib_dir'), 'model/doctrine'));
- self::$allModels = array();
- foreach($baseModels as $baseModel)
- {
- self::$allModels[] = preg_replace('|^Base(\w+).class.php$|', '$1',
basename($baseModel));
- }
+ self::$allModels = self::getModelsFromBaseFiles($baseFiles);
}
return self::$allModels;
@@ -72,21 +66,28 @@
{
if (null === self::$dmModels)
{
- $baseModels = sfFinder::type('file')
+ $baseFiles = sfFinder::type('file')
->name('/Base\w+.class.php/i')
->maxDepth(0)
->in(dmOs::join(sfConfig::get("sf_lib_dir"),
"model/doctrine/dmCorePlugin/base"));
- self::$dmModels = array();
- foreach($baseModels as $baseModel)
- {
- self::$dmModels[] = preg_replace('|^Base(\w+).class.php$|', '$1',
basename($baseModel));
- }
+ self::$dmModels = self::getModelsFromBaseFiles($baseFiles);
}
return self::$dmModels;
}
+ protected static function getModelsFromBaseFiles(array $files)
+ {
+ $models = array();
+ foreach($files as $file)
+ {
+ $models[] = preg_replace('|^Base(\w+).class.php$|', '$1',
basename($file));
+ }
+
+ return $models;
+ }
+
public static function checkFilesystemPermissions()
{
$requiredWritableDirs = array(
Added:
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/unit/dmProjectTest.php
===================================================================
---
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/unit/dmProjectTest.php
(rev 0)
+++
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/unit/dmProjectTest.php
2010-02-10 19:44:03 UTC (rev 27844)
@@ -0,0 +1,33 @@
+<?php
+
+require_once(realpath(dirname(__FILE__).'/../../..').'/unit/helper/dmModuleUnitTestHelper.php');
+$helper = new dmModuleUnitTestHelper();
+$helper->boot();
+
+$t = new lime_test(10);
+
+$models = dmProject::getModels();
+$dmModels = dmProject::getDmModels();
+$allModels = dmProject::getAllModels();
+
+$t->is_deeply($models, $expected = array(
+ 'DmTestCateg', 'DmTestComment', 'DmTestDomainCateg', 'DmTestDomain',
'DmTestFruit', 'DmTestPost', 'DmTestPostTag', 'DmTestTag', 'DmTestUser'
+), 'dmProject::getModels() -> '.implode(', ', $expected));
+
+$t->is_deeply(array_intersect($models, $allModels), $models,
'dmProject::getAllModels() contain all project models');
+
+$t->is_deeply(array_intersect($dmModels, $allModels), $dmModels,
'dmProject::getAllModels() contain all Diem models');
+
+$t->is_deeply(array_intersect($models, $dmModels), array(),
'dmProject::getDmModels() contain no project models');
+
+$t->is_deeply(array_intersect($dmModels, $models), array(),
'dmProject::getModels() contain no Diem models');
+
+$t->is(count($dmModels), $expected = 17, 'Diem has '.$expected.' models');
+
+$t->is(dmProject::getKey(), 'project', 'project key is "project"');
+
+$t->ok(dmProject::appExists('front'), 'project has a front app');
+
+$t->ok(dmProject::appExists('admin'), 'project has a admin app');
+
+$t->ok(!dmProject::appExists('bluk'), 'project has no bluk app');
\ No newline at end of file
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.