forked from propelorm/Propel2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added PR 194 from Propel 1.6. Fixes propelorm#148
- Loading branch information
1 parent
80f03ab
commit 08be56a
Showing
5 changed files
with
141 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<config> | ||
<propel> | ||
<datasources default="reverse-bookstore"> | ||
<datasource id="reverse-bookstore"> | ||
<adapter>##DATABASE_VENDOR##</adapter> | ||
<connection> | ||
<classname>\Propel\Runtime\Connection\DebugPDO</classname> | ||
<dsn>##DATABASE_URL##</dsn> | ||
<user>##DATABASE_USER##</user> | ||
<password>##DATABASE_PASSWORD##</password> | ||
<options> | ||
<option id="ATTR_PERSISTENT">false</option> | ||
</options> | ||
<attributes> | ||
<option id="ATTR_EMULATE_PREPARES">true</option> | ||
</attributes> | ||
<settings> | ||
<setting id="charset">utf8</setting> | ||
</settings> | ||
</connection> | ||
</datasource> | ||
</datasources> | ||
</propel> | ||
</config> |
104 changes: 104 additions & 0 deletions
104
tests/Propel/Tests/Generator/Reverse/PgsqlSchemaParserTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Propel package. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT License | ||
*/ | ||
|
||
namespace Propel\Tests\Generator\Reverse; | ||
|
||
use Propel\Generator\Config\QuickGeneratorConfig; | ||
use Propel\Generator\Manager\ConfigManager; | ||
use Propel\Generator\Model\ColumnDefaultValue; | ||
use Propel\Generator\Model\Database; | ||
use Propel\Generator\Model\PropelTypes; | ||
use Propel\Generator\Platform\DefaultPlatform; | ||
use Propel\Generator\Reverse\PgsqlSchemaParser; | ||
use Propel\Runtime\Propel; | ||
use Propel\Tests\TestCase; | ||
|
||
use \DOMDocument; | ||
|
||
/** | ||
* Tests for Pgsql database schema parser. | ||
* | ||
* @author Alan Pinstein | ||
*/ | ||
class PgsqlSchemaParserTest extends TestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$xmlDom = new DOMDocument(); | ||
$xmlDom->load(__DIR__ . '/../../../../Fixtures/reverse/pgsql/runtime-conf.xml'); | ||
$xml = simplexml_load_string($xmlDom->saveXML()); | ||
$phpconf = TestableConfigManager::simpleXmlToArray($xml); | ||
|
||
Propel::setConfiguration($phpconf['propel']); | ||
|
||
$this->con = Propel::getConnection('reverse-bookstore'); | ||
$this->con->beginTransaction(); | ||
|
||
if ('pgsql' !== $this->con->getAttribute(\PDO::ATTR_DRIVER_NAME)) { | ||
$this->markTestSkipped('This test is designed for PostgreSQL'); | ||
} | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->con->rollback(); | ||
|
||
parent::tearDown(); | ||
Propel::init(__DIR__ . '/../../../../Fixtures/bookstore/build/conf/bookstore-conf.php'); | ||
} | ||
|
||
function parseDataProvider() | ||
{ | ||
return array( | ||
// columnDDL, expectedColumnPhpName, expectedColumnDefaultType, expectedColumnDefaultValue | ||
array("my_column varchar(20) default null", "MyColumn", ColumnDefaultValue::TYPE_VALUE, "NULL"), | ||
array("my_column varchar(20) default ''", "MyColumn", ColumnDefaultValue::TYPE_VALUE, ""), | ||
); | ||
} | ||
|
||
/** | ||
* @dataProvider parseDataProvider | ||
*/ | ||
public function testParse($columnDDL, $expectedColumnPhpName, $expectedColumnDefaultType, $expectedColumnDefaultValue) | ||
{ | ||
$this->markTestSkipped('Skipped as we now use one database for the whole test suite'); | ||
|
||
$this->con->query("create table foo ( {$columnDDL} );"); | ||
$parser = new PgsqlSchemaParser($this->con); | ||
$parser->setGeneratorConfig(new QuickGeneratorConfig()); | ||
|
||
$database = new Database(); | ||
$database->setPlatform(new DefaultPlatform()); | ||
|
||
// make sure our DDL insert produced exactly the SQL we inserted | ||
$this->assertEquals(1, $parser->parse($database), 'One table and one view defined should return one as we exclude views'); | ||
$tables = $database->getTables(); | ||
$this->assertEquals(1, count($tables)); | ||
$table = $tables[0]; | ||
$columns = $table->getColumns(); | ||
$this->assertEquals(1, count($columns)); | ||
|
||
// check out our rev-eng column info | ||
$defaultValue = $columns[0]->getDefaultValue(); | ||
$this->assertEquals($expectedColumnPhpName, $columns[0]->getPhpName()); | ||
$this->assertEquals($expectedColumnDefaultType, $defaultValue->getType()); | ||
$this->assertEquals($expectedColumnDefaultValue, $defaultValue->getValue()); | ||
} | ||
} | ||
|
||
class TestableConfigManager extends ConfigManager | ||
{ | ||
public static function simpleXmlToArray($xml) | ||
{ | ||
return parent::simpleXmlToArray($xml); | ||
} | ||
} |