Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
PR #3719
Browse files Browse the repository at this point in the history
Merge branch 'ashawley-master'
  • Loading branch information
Ralph Schindler committed Apr 16, 2013
2 parents e50f404 + e3ef3b9 commit bc7bc1a
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 1 deletion.
58 changes: 57 additions & 1 deletion library/Zend/Db/Metadata/Source/AbstractSource.php
Expand Up @@ -380,7 +380,7 @@ public function getConstraintKeys($constraint, $table, $schema = null)
$schema = $this->defaultSchema;
}

$this->loadConstraintData($table, $schema);
$this->loadConstraintReferences($table, $schema);

// organize references first
$references = array();
Expand All @@ -390,6 +390,8 @@ public function getConstraintKeys($constraint, $table, $schema = null)
}
}

$this->loadConstraintDataKeys($schema);

$keys = array();
foreach ($this->data['constraint_keys'][$schema] as $constraintKeyInfo) {
if ($constraintKeyInfo['table_name'] == $table && $constraintKeyInfo['constraint_name'] === $constraint) {
Expand Down Expand Up @@ -504,10 +506,18 @@ protected function prepareDataHierarchy($type)
}
}

/**
* Load schema data
*/
protected function loadSchemaData()
{
}

/**
* Load table name data
*
* @param string $schema
*/
protected function loadTableNameData($schema)
{
if (isset($this->data['table_names'][$schema])) {
Expand All @@ -517,6 +527,12 @@ protected function loadTableNameData($schema)
$this->prepareDataHierarchy('table_names', $schema);
}

/**
* Load column data
*
* @param string $table
* @param string $schema
*/
protected function loadColumnData($table, $schema)
{
if (isset($this->data['columns'][$schema][$table])) {
Expand All @@ -526,6 +542,12 @@ protected function loadColumnData($table, $schema)
$this->prepareDataHierarchy('columns', $schema, $table);
}

/**
* Load constraint data
*
* @param string $table
* @param string $schema
*/
protected function loadConstraintData($table, $schema)
{
if (isset($this->data['constraints'][$schema])) {
Expand All @@ -535,6 +557,40 @@ protected function loadConstraintData($table, $schema)
$this->prepareDataHierarchy('constraints', $schema);
}

/**
* Load constraint data keys
*
* @param string $schema
*/
protected function loadConstraintDataKeys($schema)
{
if (isset($this->data['constraint_keys'][$schema])) {
return;
}

$this->prepareDataHierarchy('constraint_keys', $schema);
}

/**
* Load constraint references
*
* @param string $table
* @param string $schema
*/
protected function loadConstraintReferences($table, $schema)
{
if (isset($this->data['constraint_references'][$schema])) {
return;
}

$this->prepareDataHierarchy('constraint_references', $schema);
}

/**
* Load trigger data
*
* @param string $schema
*/
protected function loadTriggerData($schema)
{
if (isset($this->data['triggers'][$schema])) {
Expand Down
98 changes: 98 additions & 0 deletions tests/ZendTest/Db/Metadata/Source/SqliteMetadataTest.php
@@ -0,0 +1,98 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\Db\Metadata\Source;

use Zend\Db\Adapter\Adapter;
use Zend\Db\Metadata\Source\SqliteMetadata;

/**
* @requires extension sqlite
*/
class SqliteMetadataTest extends \PHPUnit_Framework_TestCase
{

/**
* @var SqliteMetadata
*/
protected $metadata;

/**
* @var Adapter
*/
protected $adapter;

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->adapter = new Adapter(array(
'driver' => 'Pdo',
'dsn' => 'sqlite::memory:'
));
$this->metadata = new SqliteMetadata($this->adapter);

}

public function testGetSchemas()
{
$schemas = $this->metadata->getSchemas();
$this->assertContains('main', $schemas);
$this->assertCount(1, $schemas);
}

public function testGetTableNames()
{
$tables = $this->metadata->getTableNames('main');
$this->assertCount(0, $tables);
}

public function testGetColumnNames()
{
$columns = $this->metadata->getColumnNames(null, 'main');
$this->assertCount(0, $columns);
}

public function testGetConstraints()
{
$constraints = $this->metadata->getConstraints(null, 'main');
$this->assertCount(0, $constraints);
$this->assertContainsOnlyInstancesOf(
'Zend\Db\Metadata\Object\ConstraintObject',
$constraints
);
}

/**
* @group ZF2-3719
*/
public function testGetConstraintKeys()
{
$keys = $this->metadata->getConstraintKeys(
null, null, 'main'
);
$this->assertCount(0, $keys);
$this->assertContainsOnlyInstancesOf(
'Zend\Db\Metadata\Object\ConstraintKeyObject',
$keys
);
}

public function testGetTriggers()
{
$triggers = $this->metadata->getTriggers('main');
$this->assertCount(0, $triggers);
$this->assertContainsOnlyInstancesOf(
'Zend\Db\Metadata\Object\TriggerObject',
$triggers
);
}
}

0 comments on commit bc7bc1a

Please sign in to comment.