Commit 5c6e8f8e authored by Jonathan.Wage's avatar Jonathan.Wage

New coverage for parser, yaml schema parsing, a few fixes.

parent ff892b17
...@@ -107,15 +107,19 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict ...@@ -107,15 +107,19 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict
*/ */
public function getPortableDeclaration(array $field) public function getPortableDeclaration(array $field)
{ {
$dbType = strtolower($field['type']); if ( ! isset($field['data_type'])) {
throw new Doctrine_DataDict_Exception('Native oracle definition must have a data_type key specified');
}
$dbType = strtolower($field['data_type']);
$type = array(); $type = array();
$length = $unsigned = $fixed = null; $length = $unsigned = $fixed = null;
if ( ! empty($field['length'])) { if ( ! empty($field['data_length'])) {
$length = $field['length']; $length = $field['data_length'];
} }
if ( ! isset($field['name'])) { if ( ! isset($field['column_name'])) {
$field['name'] = ''; $field['column_name'] = '';
} }
switch ($dbType) { switch ($dbType) {
...@@ -125,7 +129,7 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict ...@@ -125,7 +129,7 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict
$type[] = 'integer'; $type[] = 'integer';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} }
...@@ -139,7 +143,7 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict ...@@ -139,7 +143,7 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict
$type[] = 'string'; $type[] = 'string';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} }
...@@ -156,13 +160,13 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict ...@@ -156,13 +160,13 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict
$type[] = 'float'; $type[] = 'float';
break; break;
case 'number': case 'number':
if ( ! empty($field['scale'])) { if ( ! empty($field['data_scale'])) {
$type[] = 'decimal'; $type[] = 'decimal';
} else { } else {
$type[] = 'integer'; $type[] = 'integer';
if ($length == '1') { if ($length == '1') {
$type[] = 'boolean'; $type[] = 'boolean';
if (preg_match('/^(is|has)/', $field['name'])) { if (preg_match('/^(is|has)/', $field['column_name'])) {
$type = array_reverse($type); $type = array_reverse($type);
} }
} }
...@@ -192,4 +196,4 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict ...@@ -192,4 +196,4 @@ class Doctrine_DataDict_Oracle extends Doctrine_DataDict
'unsigned' => $unsigned, 'unsigned' => $unsigned,
'fixed' => $fixed); 'fixed' => $fixed);
} }
} }
\ No newline at end of file
...@@ -126,6 +126,8 @@ class Doctrine_Import_Oracle extends Doctrine_Import ...@@ -126,6 +126,8 @@ class Doctrine_Import_Oracle extends Doctrine_Import
$result = $this->conn->fetchAssoc($sql); $result = $this->conn->fetchAssoc($sql);
$descr = array();
foreach($result as $val) { foreach($result as $val) {
$val = array_change_key_case($val, CASE_LOWER); $val = array_change_key_case($val, CASE_LOWER);
$decl = $this->conn->dataDict->getPortableDeclaration($val); $decl = $this->conn->dataDict->getPortableDeclaration($val);
......
...@@ -102,7 +102,7 @@ class Doctrine_Import_Schema ...@@ -102,7 +102,7 @@ class Doctrine_Import_Schema
$array = array(); $array = array();
foreach ((array) $schema AS $s) { foreach ((array) $schema AS $s) {
if (is_file($s)) { if (is_file($s) || is_string($s)) {
$array = array_merge($array, $this->parseSchema($s, $format)); $array = array_merge($array, $this->parseSchema($s, $format));
} else if (is_dir($s)) { } else if (is_dir($s)) {
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s), $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($s),
...@@ -119,7 +119,7 @@ class Doctrine_Import_Schema ...@@ -119,7 +119,7 @@ class Doctrine_Import_Schema
$this->_buildRelationships($array); $this->_buildRelationships($array);
return array('schema' => $array, 'relations' => $this->_relations); return $array;
} }
/** /**
...@@ -144,10 +144,8 @@ class Doctrine_Import_Schema ...@@ -144,10 +144,8 @@ class Doctrine_Import_Schema
} }
} }
$schema = $this->buildSchema($schema, $format); $array = $this->buildSchema($schema, $format);
$array = $schema['schema'];
foreach ($array as $name => $properties) { foreach ($array as $name => $properties) {
if ( ! empty($models) && !in_array($properties['className'], $models)) { if ( ! empty($models) && !in_array($properties['className'], $models)) {
continue; continue;
......
...@@ -131,12 +131,19 @@ abstract class Doctrine_Parser ...@@ -131,12 +131,19 @@ abstract class Doctrine_Parser
return $contents; return $contents;
} }
public function doDump($data, $path) /**
* doDump
*
* @param string $data
* @param string $path
* @return void
*/
public function doDump($data, $path = null)
{ {
if ($path) { if ($path !== null) {
return file_put_contents($path, $data); return file_put_contents($path, $data);
} else { } else {
return $data; return $data;
} }
} }
} }
\ No newline at end of file
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Data_Export_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Data_Export_TestCase extends Doctrine_UnitTestCase
{
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Data_Import_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Data_Import_TestCase extends Doctrine_UnitTestCase
{
}
...@@ -34,7 +34,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -34,7 +34,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
public function testGetPortableDeclarationForUnknownNativeTypeThrowsException() public function testGetPortableDeclarationForUnknownNativeTypeThrowsException()
{ {
try { try {
$this->dataDict->getPortableDeclaration(array('type' => 'some_unknown_type')); $this->dataDict->getPortableDeclaration(array('data_type' => 'some_unknown_type'));
$this->fail(); $this->fail();
} catch(Doctrine_DataDict_Exception $e) { } catch(Doctrine_DataDict_Exception $e) {
$this->pass(); $this->pass();
...@@ -42,7 +42,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -42,7 +42,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeFloatType() public function testGetPortableDeclarationSupportsNativeFloatType()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'float')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'float'));
$this->assertEqual($type, array('type' => array('float'), $this->assertEqual($type, array('type' => array('float'),
'length' => null, 'length' => null,
...@@ -51,21 +51,21 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -51,21 +51,21 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeIntegerTypes() public function testGetPortableDeclarationSupportsNativeIntegerTypes()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'integer')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'integer'));
$this->assertEqual($type, array('type' => array('integer'), $this->assertEqual($type, array('type' => array('integer'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'pls_integer', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'pls_integer', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('integer', 'boolean'), $this->assertEqual($type, array('type' => array('integer', 'boolean'),
'length' => 1, 'length' => 1,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'binary_integer', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'binary_integer', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('integer', 'boolean'), $this->assertEqual($type, array('type' => array('integer', 'boolean'),
'length' => 1, 'length' => 1,
...@@ -74,35 +74,35 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -74,35 +74,35 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeStringTypes() public function testGetPortableDeclarationSupportsNativeStringTypes()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'varchar'));
$this->assertEqual($type, array('type' => array('string'), $this->assertEqual($type, array('type' => array('string'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'varchar2', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'varchar2', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('string', 'boolean'), $this->assertEqual($type, array('type' => array('string', 'boolean'),
'length' => 1, 'length' => 1,
'unsigned' => null, 'unsigned' => null,
'fixed' => false)); 'fixed' => false));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'nvarchar2', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'nvarchar2', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('string', 'boolean'), $this->assertEqual($type, array('type' => array('string', 'boolean'),
'length' => 1, 'length' => 1,
'unsigned' => null, 'unsigned' => null,
'fixed' => false)); 'fixed' => false));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'char', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'char', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('string', 'boolean'), $this->assertEqual($type, array('type' => array('string', 'boolean'),
'length' => 1, 'length' => 1,
'unsigned' => null, 'unsigned' => null,
'fixed' => true)); 'fixed' => true));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'nchar', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'nchar', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('string', 'boolean'), $this->assertEqual($type, array('type' => array('string', 'boolean'),
'length' => 1, 'length' => 1,
...@@ -111,7 +111,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -111,7 +111,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeNumberType() public function testGetPortableDeclarationSupportsNativeNumberType()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'number')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'number'));
$this->assertEqual($type, array('type' => array('integer'), $this->assertEqual($type, array('type' => array('integer'),
'length' => null, 'length' => null,
...@@ -119,7 +119,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -119,7 +119,7 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'number', 'length' => 1)); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'number', 'data_length' => 1));
$this->assertEqual($type, array('type' => array('integer', 'boolean'), $this->assertEqual($type, array('type' => array('integer', 'boolean'),
'length' => 1, 'length' => 1,
...@@ -129,14 +129,14 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -129,14 +129,14 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeTimestampType() public function testGetPortableDeclarationSupportsNativeTimestampType()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'date')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'date'));
$this->assertEqual($type, array('type' => array('timestamp'), $this->assertEqual($type, array('type' => array('timestamp'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'timestamp')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'timestamp'));
$this->assertEqual($type, array('type' => array('timestamp'), $this->assertEqual($type, array('type' => array('timestamp'),
'length' => null, 'length' => null,
...@@ -145,21 +145,21 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -145,21 +145,21 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeClobTypes() public function testGetPortableDeclarationSupportsNativeClobTypes()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'clob')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'clob'));
$this->assertEqual($type, array('type' => array('clob'), $this->assertEqual($type, array('type' => array('clob'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'long')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'long'));
$this->assertEqual($type, array('type' => array('string', 'clob'), $this->assertEqual($type, array('type' => array('string', 'clob'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'nclob')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'nclob'));
$this->assertEqual($type, array('type' => array('clob'), $this->assertEqual($type, array('type' => array('clob'),
'length' => null, 'length' => null,
...@@ -169,28 +169,28 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase { ...@@ -169,28 +169,28 @@ class Doctrine_DataDict_Oracle_TestCase extends Doctrine_UnitTestCase {
} }
public function testGetPortableDeclarationSupportsNativeBlobTypes() public function testGetPortableDeclarationSupportsNativeBlobTypes()
{ {
$type = $this->dataDict->getPortableDeclaration(array('type' => 'blob')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'blob'));
$this->assertEqual($type, array('type' => array('blob'), $this->assertEqual($type, array('type' => array('blob'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'long raw')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'long raw'));
$this->assertEqual($type, array('type' => array('blob'), $this->assertEqual($type, array('type' => array('blob'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'long raw')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'long raw'));
$this->assertEqual($type, array('type' => array('blob'), $this->assertEqual($type, array('type' => array('blob'),
'length' => null, 'length' => null,
'unsigned' => null, 'unsigned' => null,
'fixed' => null)); 'fixed' => null));
$type = $this->dataDict->getPortableDeclaration(array('type' => 'raw')); $type = $this->dataDict->getPortableDeclaration(array('data_type' => 'raw'));
$this->assertEqual($type, array('type' => array('blob'), $this->assertEqual($type, array('type' => array('blob'),
'length' => null, 'length' => null,
......
<?php <?php
class DoctrineTest_Reporter_Html extends DoctrineTest_Reporter{ class DoctrineTest_Reporter_Html extends DoctrineTest_Reporter {
public function paintHeader($name) { public $progress = false;
public function paintHeader($name) {
?> ?>
<html> <html>
<head> <head>
<title>Doctrine Unit Tests</title> <title>Doctrine Unit Tests</title>
<style> <style>
.fail { color: red; } pre { background-color: lightgray; } .fail
{
color: red;
}
#messages
{
border-left: 1px solid #333333;
border-right: 1px solid #333333;
background-color: #CCCCCC;
padding: 10px;
}
#summary
{
background-color: red;
padding: 8px;
color: white;
}
#wrapper
{
}
#wrapper h1
{
font-size: 20pt;
margin-bottom: 10px;
font-weight: bold;
}
</style> </style>
</head> </head>
<body> <body>
<div id="wrapper">
<h1><?php echo $name ?></h1> <h1><?php echo $name ?></h1>
<?php
<?php
} }
public function paintFooter() public function paintFooter()
{ {
$this->paintSummary();
print '<pre>'; $this->paintMessages();
$this->paintSummary();
print '</div>';
}
public function paintMessages()
{
print '<div id="messages">';
foreach ($this->_test->getMessages() as $message) { foreach ($this->_test->getMessages() as $message) {
print "<p>$message</p>"; print "<p>$message</p>";
} }
print '</pre>'; print '</div>';
$colour = ($this->_test->getFailCount() > 0 ? 'red' : 'green'); }
print '<div style=\'';
print "padding: 8px; margin-top: 1em; background-color: $colour; color: white;"; public function paintSummary()
print '\'>'; {
print $this->_test->getTestCaseCount() . ' test cases.'; $color = ($this->_test->getFailCount() > 0 ? 'red' : 'green');
print '<div id="summary" style="';
print "background-color: $color;";
print '">';
print $this->_test->getTestCaseCount() . ' test cases. ';
print '<strong>' . $this->_test->getPassCount() . '</strong> passes and '; print '<strong>' . $this->_test->getPassCount() . '</strong> passes and ';
print '<strong>' . $this->_test->getFailCount() . '</strong> fails.'; print '<strong>' . $this->_test->getFailCount() . '</strong> fails.';
print '</div>'; print '</div>';
} }
public function getProgressIndicator(){} public function getProgressIndicator() {}
} }
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
*/ */
class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase
{ {
public $buildSchema;
public $schema;
public function testYmlImport() public function testYmlImport()
{ {
$import = new Doctrine_Import_Schema(); $import = new Doctrine_Import_Schema();
...@@ -39,14 +42,65 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase ...@@ -39,14 +42,65 @@ class Doctrine_Import_Schema_TestCase extends Doctrine_UnitTestCase
if ( ! file_exists('classes/User.php')) { if ( ! file_exists('classes/User.php')) {
$this->fail(); $this->fail();
} else {
unlink('classes/User.php');
} }
if ( ! file_exists('classes/Group.php')) { if ( ! file_exists('classes/Profile.php')) {
$this->fail(); $this->fail();
}
}
public function testBuildSchema()
{
$schema = new Doctrine_Import_Schema();
$array = $schema->buildSchema('schema.yml', 'yml');
$model = $array['User'];
$this->assertTrue(array_key_exists('connection', $model));
$this->assertTrue(array_key_exists('className', $model));
$this->assertTrue(array_key_exists('tableName', $model));
$this->assertTrue(array_key_exists('columns', $model) && is_array($model['columns']));
$this->assertTrue(array_key_exists('relations', $model) && is_array($model['relations']));
$this->assertTrue(array_key_exists('indexes', $model) && is_array($model['indexes']));
$this->assertTrue(array_key_exists('attributes', $model) && is_array($model['attributes']));
$this->assertTrue(array_key_exists('templates', $model) && is_array($model['columns']));
$this->assertTrue(array_key_exists('actAs', $model) && is_array($model['actAs']));
$this->assertTrue(array_key_exists('options', $model) && is_array($model['options']));
$this->assertTrue(array_key_exists('package', $model));
}
public function testSchemaRelationshipCompletion()
{
$this->buildSchema = new Doctrine_Import_Schema();
$this->schema = $this->buildSchema->buildSchema('schema.yml', 'yml');
foreach ($this->schema as $name => $properties) {
$relations = $this->buildSchema->getRelations($properties);
foreach ($relations as $alias => $relation) {
if (!$this->_verifyMultiDirectionalRelationship($name, $alias, $relation)) {
$this->fail();
return false;
}
}
}
$this->pass();
}
protected function _verifyMultiDirectionalRelationship($class, $relationAlias, $relation)
{
$foreignClass = $relation['class'];
$foreignAlias = isset($relation['foreignAlias']) ? $relation['foreignAlias']:$class;
$foreignClassRelations = $this->buildSchema->getRelations($this->schema[$foreignClass]);
// Check to see if the foreign class has the opposite end defined for the class/foreignAlias
if (isset($foreignClassRelations[$foreignAlias])) {
return true;
} else { } else {
unlink('classes/Group.php'); return false;
} }
} }
} }
\ No newline at end of file
...@@ -32,15 +32,15 @@ ...@@ -32,15 +32,15 @@
*/ */
class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase
{ {
protected $serverExists = false; protected $serverExists = false;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
try { try {
$dsn = 'mysql://doctrine_tester:d0cTrynR0x!@localhost/doctrine_unit_test'; $dsn = 'mysql://doctrine_tester:d0cTrynR0x!@localhost/doctrine_unit_test';
$this->conn = $this->manager->openConnection($dsn,'unit_test',true); $this->conn = $this->manager->openConnection($dsn, 'unit_test', true);
$this->conn->connect(); $this->conn->connect();
$this->serverExists = true; $this->serverExists = true;
} catch (Exception $e){ } catch (Exception $e){
...@@ -48,16 +48,14 @@ class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase ...@@ -48,16 +48,14 @@ class Doctrine_Migration_Mysql_TestCase extends Doctrine_UnitTestCase
} }
} }
public function testMigration() public function testMigration()
{ {
if($this->serverExists){ if ($this->serverExists){
// Clean up any left over tables from broken test runs. // Clean up any left over tables from broken test runs.
try { try {
$this->conn->export->dropTable('migration_test'); $this->conn->export->dropTable('migration_test');
$this->conn->export->dropTable('migration_version'); $this->conn->export->dropTable('migration_version');
} catch(Exception $e) { } catch(Exception $e) { }
}
// New migration for the 'migration_classes' directory // New migration for the 'migration_classes' directory
$migration = new Doctrine_Migration('mysql_migration_classes'); $migration = new Doctrine_Migration('mysql_migration_classes');
......
...@@ -51,4 +51,4 @@ class Doctrine_Migration_TestCase extends Doctrine_UnitTestCase ...@@ -51,4 +51,4 @@ class Doctrine_Migration_TestCase extends Doctrine_UnitTestCase
// Make sure the current version is 0 // Make sure the current version is 0
$this->assertEqual($migration->getCurrentVersion(), 0); $this->assertEqual($migration->getCurrentVersion(), 0);
} }
} }
\ No newline at end of file
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Parser_TestCase
*
* @package Doctrine
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class Doctrine_Parser_TestCase extends Doctrine_UnitTestCase
{
public function testGetParserInstance()
{
$instance = Doctrine_Parser::getParser('Yml');
if ($instance instanceof Doctrine_Parser_Yml) {
$this->pass();
} else {
$this->fail();
}
}
public function testFacadeLoadAndDump()
{
Doctrine_Parser::dump(array('test' => 'good job', 'test2' => true, array('testing' => false)), 'yml', 'test.yml');
$array = Doctrine_Parser::load('test.yml', 'yml');
$this->assertEqual($array, array('test' => 'good job', 'test2' => true, array('testing' => false)));
}
public function testParserSupportsEmbeddingPhpSyntax()
{
$parser = Doctrine_Parser::getParser('Yml');
$yml = "---
test: good job
test2: true
testing: <?php echo 'false'.\"\n\"; ?>
w00t: not now
";
$data = $parser->doLoad($yml);
$array = $parser->loadData($data);
$this->assertEqual($array, array('test' => 'good job', 'test2' => true, 'testing' => false, 'w00t' => 'not now'));
}
public function testParserWritingToDisk()
{
$parser = Doctrine_Parser::getParser('Yml');
$parser->doDump('test', 'test.yml');
$this->assertEqual('test', file_get_contents('test.yml'));
}
public function testParserReturningLoadedData()
{
$parser = Doctrine_Parser::getParser('Yml');
$result = $parser->doDump('test');
$this->assertEqual('test', $result);
}
public function testLoadFromString()
{
$yml = "---
test: good job
test2: true
testing: <?php echo 'false'.\"\n\"; ?>
w00t: not now
";
$array = Doctrine_Parser::load($yml, 'yml');
$this->assertEqual($array, array('test' => 'good job', 'test2' => true, 'testing' => false, 'w00t' => 'not now'));
}
}
<?php
require_once('run.php');
\ No newline at end of file
...@@ -7,7 +7,7 @@ class MysqlChangeColumn extends Doctrine_Migration ...@@ -7,7 +7,7 @@ class MysqlChangeColumn extends Doctrine_Migration
} }
public function down() public function down()
{ {
$this->renameColumn('migration_test','field3','field2'); $this->renameColumn('migration_test','field3','field2');
} }
} }
\ No newline at end of file
...@@ -263,7 +263,19 @@ $migration->addTestCase(new Doctrine_Migration_Mysql_TestCase()); ...@@ -263,7 +263,19 @@ $migration->addTestCase(new Doctrine_Migration_Mysql_TestCase());
$test->addTestCase($migration); $test->addTestCase($migration);
$test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); $test->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase());
$test->addTestCase(new Doctrine_Import_Schema_TestCase());
$test->addTestCase(new Doctrine_Export_Schema_TestCase());
$test->run(); $parser = new GroupTest('Parser tests', 'parser');
$parser->addTestCase(new Doctrine_Parser_TestCase());
$test->addTestCase($parser);
$schemaFiles = new GroupTest('Schema files', 'schema_files');
$schemaFiles->addTestCase(new Doctrine_Import_Schema_TestCase());
$schemaFiles->addTestCase(new Doctrine_Export_Schema_TestCase());
$test->addTestCase($schemaFiles);
$data = new GroupTest('Data exporting/importing fixtures', 'data_fixtures');
$data->addTestCase(new Doctrine_Data_Import_TestCase());
$data->addTestCase(new Doctrine_Data_Export_TestCase());
$test->addTestCase($data);
$test->run();
\ No newline at end of file
--- ---
User: User:
tableName: user actAs: [Timestampable]
className: User columns:
columns: id:
id: type: integer(4)
notnull: true
primary: true primary: true
autoincrement: true autoincrement: true
type: integer username:
length: 4 type: string(255)
name: id password:
username: type: string(255)
type: string Profile:
length: 255 actAs: [Timestampable]
Group: columns:
tableName: group id:
className: Group type: integer(4)
columns:
id:
notnull: true
primary: true primary: true
autoincrement: true autoincrement: true
type: integer user_id:
length: 4 type: integer(4)
name: id contact_id:
name: type: integer(4)
type: string first_name:
length: 255 type: string(255)
\ No newline at end of file last_name:
type: string(255)
relations:
User:
foreignType: one
Contact:
foreignType: one
Contact:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
name:
type: string(255)
Phonenumber:
actAs: [Timestampable]
columns:
id:
type: integer(4)
primary: true
autoincrement: true
contact_id:
type: integer(4)
phone_number:
type: integer(4)
relations:
Contact:
foreignAlias: Phonenumbers
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment