Skip to content

Commit

Permalink
Merge pull request #4 from pedro151/v1.3.x
Browse files Browse the repository at this point in the history
V1.3.x
  • Loading branch information
pedro151 committed Jun 11, 2016
2 parents eff0673 + 0b2e1f9 commit 0eaf5e9
Show file tree
Hide file tree
Showing 10 changed files with 228 additions and 13 deletions.
Binary file modified bin/orm-generator.phar
Binary file not shown.
4 changes: 3 additions & 1 deletion build/Classes/AdapterConfig/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ abstract class AbstractAdapter
// caminho onde os arquivos devem ser criados
'path' => 'models' ,
// flag para gerar pasta com o nome do driver do banco de dados
'folder-database' => 0 ,
'folder-database' => 0,
// string com o nome da pastar personalizada
'folder-name' => '',

############################## Comandos adicionais
//flag para mostrar o status da execução ao termino do processo
Expand Down
6 changes: 3 additions & 3 deletions build/Classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Config
/**
* @var string
*/
public static $version = "1.3.0";
public static $version = "1.3.1";

/**
* String that separates the parent section name
Expand Down Expand Up @@ -65,7 +65,7 @@ class Config
private $adapterDriver;

private $frameworkList = array (
'zf1', 'phalcon'
'none', 'zf1', 'phalcon'
);

public function __construct ( $argv, $basePath )
Expand Down Expand Up @@ -142,7 +142,7 @@ private function parseConfig ( $basePath, $argv )

if ( !in_array ( $configCurrent[ 'framework' ], $this->frameworkList ) ) {
$frameworks = implode("\n\t", $this->frameworkList);
throw new \Exception( "list of frameworks: \n".$frameworks."\n" );
throw new \Exception( "list of frameworks: \n\t\033[1;33m".$frameworks."\n\033[0m" );
}

return $argv + array_filter ( $configCurrent );
Expand Down
4 changes: 2 additions & 2 deletions build/Classes/MakerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ public function parseLocation ( $basePath )

# pasta com nome do driver do banco
$driverBase = '';
if ( $this->config->{"folder-database"} )
if ( (bool) @$this->config->{"folder-database"} )
{
$classDriver = explode ( '\\' , get_class ( $this->driver ) );
$driverBase = end ( $classDriver );
}
$folderName = '';
if ( $this->config->{"folder-name"} )
if ( (bool) @$this->config->{"folder-name"} )
{
$folderName = $this->getClassName ( trim ( $this->config->{"folder-name"} ) );
}
Expand Down
16 changes: 15 additions & 1 deletion build/Classes/templates/zf1/dbtable.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ class <?=$objTables->getNamespace()?>_DbTable_<?=\Classes\Maker\AbstractMaker::g
<?php endforeach; ?>
);
<?php endif ?>
<?php if($this->config->{'folder-name'}):?>
/**
* Initialize database adapter.
*
* @return void
* @see Zend_Db_Table_Abstract::_setupDatabaseAdapter
* @throws Zend_Db_Table_Exception
* @throws Zend_Exception
*/
protected function _setupDatabaseAdapter()
{
$this->_db = Zend_Registry::get( '<?=($this->config->{'folder-name'})?>');
parent::_setupDatabaseAdapter();
}
<?php endif ?>
<?php if( $objTables->hasSequences() ) : ?>

/**
Expand All @@ -65,7 +80,6 @@ class <?=$objTables->getNamespace()?>_DbTable_<?=\Classes\Maker\AbstractMaker::g
*
* @var mixed
*/

<?php if ( 1 == count($objTables->getSequences() ) ) : ?>
<?php if(strpos($this->config->driver, 'pgsql')): ?>
<?php $seqs = $objTables->getSequences();reset($seqs);$seq = current($seqs);?>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "orm-generator maps the entire database and then creates the DAO (Data Access Object) and ORM (Object-relational mapping) of the entire database to facilitate the development. uses various types of databases like Postgres and Mysql and various types of ORM framework.",
"keywords": ["orm", "datamapper", "database", "model", "mapper", "entity", "dao", "generator", "orm-generator", "mysql", "postgres", "phalcon", "zend"],
"license": "MIT",
"version": "v1.3.0",
"version": "v1.3.1",
"authors": [
{
"name": "pedro151",
Expand Down
2 changes: 1 addition & 1 deletion configs/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

; name framework used, which has the contents of the database configurations
; and framework template
framework = "phalcon"
framework = "zf1"
; configuration environment you want to generate
environment = dev
; database driver name (Ex.: pgsql)
Expand Down
4 changes: 2 additions & 2 deletions phpunit_mysql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/report" charset="ISO-8859-1"
highlight="false" lowUpperBound="35" highLowerBound="70"/>
<!--<log type="coverage-html" target="./log/report" charset="ISO-8859-1"-->
<!--highlight="false" lowUpperBound="35" highLowerBound="70"/>-->
</logging>
</phpunit>
4 changes: 2 additions & 2 deletions phpunit_pgsql.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./log/report" charset="ISO-8859-1"
highlight="false" lowUpperBound="35" highLowerBound="70"/>
<!--<log type="coverage-html" target="./log/report" charset="ISO-8859-1"-->
<!--highlight="false" lowUpperBound="35" highLowerBound="70"/>-->
</logging>
</phpunit>
199 changes: 199 additions & 0 deletions tests/TestMysql/TestClasses/MakerFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?php
/**
* Created by PhpStorm.
* User: pedro
* Date: 22/02/16
* Time: 15:29
*/

namespace TestMysql\TestClasses;


use Classes\Config;
use Classes\MakerFile;

class MakerFileTest extends \PHPUnit_Framework_TestCase
{
const FILE_EntityAbstract = "EntityAbstract.php";
const FILE_TableAbstract = "TableAbstract.php";
public $basePath;

protected function setUp ()
{
$this->basePath = dirname ( $GLOBALS[ 'base_path' ] );
}

private function rrmdir ( $dir )
{
if ( is_dir ( $dir ) )
{
$objects = scandir ( $dir );
foreach ( $objects as $object )
{
if ( $object != "." && $object != ".." )
{
if ( is_dir ( $dir . "/" . $object ) )
{
$this->rrmdir ( $dir . "/" . $object );
} else
{
unlink ( $dir . "/" . $object );
}
}
}
rmdir ( $dir );
}
}

public function testFactory ()
{
$names = array (
'DbTable' ,
'Entity' ,
''
);

$maker = new MakerFile(
new Config(
array (
'schema' => array (
'public' ,
'quiz'
)
) ,
$this->basePath
)
);
foreach ( $maker->factoryMakerFile () as $key => $obj )
{
$this->assertTrue ( $obj->getPastName () == $names[ $key ] );
}
}

public function testLocationDatabaseTrue ()
{
$maker = new MakerFile(
new Config(
array (
'folder-database' => true ,
'driver' => 'mysql' ,
'schema' => array (
'public' ,
'quiz' ,
)
) ,
$this->basePath
)
);

$arrBase = array (
$this->basePath ,
'models' ,
'Mysql'
);

foreach ( $maker->location as $index => $item )
{
$arrBaseFinal = $arrBase;
$arrBaseFinal[] = ucfirst ( $index );
$location = implode ( DIRECTORY_SEPARATOR , filter_var_array ( $arrBaseFinal ) );
$this->assertTrue ( $item == $location );
unset( $arrBaseFinal );
}
}

public function testLocationDatabaseFalse ()
{
$maker = new MakerFile(
new Config(
array (
'folder-database' => false ,
'driver' => 'mysql' ,
'schema' => array (
'public' ,
'quiz' ,
)
) ,
$this->basePath
)
);

$arrBase = array (
$this->basePath ,
'models'
);

foreach ( $maker->location as $index => $item )
{
$arrBaseFinal = $arrBase;
$arrBaseFinal[] = MakerFile::getClassName( $index );
$location = implode ( DIRECTORY_SEPARATOR , array_filter ( $arrBaseFinal ) );
$this->assertTrue ( $item == $location );
unset( $arrBaseFinal );
}
}

public function testLocationSchemaOff ()
{
$maker = new MakerFile(
new Config(
array (
'folder-database' => false ,
'database' => $GLOBALS[ 'dbname' ],
'driver' => 'mysql' ,
'schema' => array ()
) ,
$this->basePath
)
);


$db = MakerFile::getClassName( $maker->getConfig()->getDatabase());

$arrBase = array (
$this->basePath ,
'models',
$db
);

foreach ( $maker->location as $index => $item )
{
$location = implode ( DIRECTORY_SEPARATOR , array_filter ( $arrBase ) );
$this->assertTrue ( $item == $location );
}

}


public function testLocationDatabaseCustom ()
{
$maker = new MakerFile(
new Config(
array (
'folder-name' => 'db' ,
'driver' => 'mysql' ,
'schema' => array (
'public' ,
'quiz' ,
)
) ,
$this->basePath
)
);

$arrBase = array (
$this->basePath ,
'models' ,
'Db'
);

foreach ( $maker->location as $index => $item )
{
$arrBaseFinal = $arrBase;
$arrBaseFinal[] = ucfirst ( $index );
$location = implode ( DIRECTORY_SEPARATOR , filter_var_array ( $arrBaseFinal ) );
$this->assertTrue ( $item == $location );
unset( $arrBaseFinal );
}
}
}

0 comments on commit 0eaf5e9

Please sign in to comment.