Commit fce77af2 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #664 from deeky666/DBAL-669

[DBAL-669] Make schema visit namespaces
parents b6cd3238 14241911
...@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema; ...@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector; use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector;
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector; use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
use Doctrine\DBAL\Schema\Visitor\NamespaceVisitor;
use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
...@@ -477,9 +478,16 @@ class Schema extends AbstractAsset ...@@ -477,9 +478,16 @@ class Schema extends AbstractAsset
{ {
$visitor->acceptSchema($this); $visitor->acceptSchema($this);
if ($visitor instanceof NamespaceVisitor) {
foreach ($this->namespaces as $namespace) {
$visitor->acceptNamespace($namespace);
}
}
foreach ($this->_tables as $table) { foreach ($this->_tables as $table) {
$table->visit($visitor); $table->visit($visitor);
} }
foreach ($this->_sequences as $sequence) { foreach ($this->_sequences as $sequence) {
$sequence->visit($visitor); $sequence->visit($visitor);
} }
......
...@@ -344,4 +344,114 @@ class SchemaTest extends \PHPUnit_Framework_TestCase ...@@ -344,4 +344,114 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($schema->hasNamespace('baz')); $this->assertTrue($schema->hasNamespace('baz'));
$this->assertFalse($schema->hasNamespace('moo')); $this->assertFalse($schema->hasNamespace('moo'));
} }
/**
* @group DBAL-669
*/
public function testVisitsVisitor()
{
$schema = new Schema();
$visitor = $this->getMock('Doctrine\DBAL\Schema\Visitor\Visitor');
$schema->createNamespace('foo');
$schema->createNamespace('bar');
$schema->createTable('baz');
$schema->createTable('bla.bloo');
$schema->createSequence('moo');
$schema->createSequence('war');
$visitor->expects($this->once())
->method('acceptSchema')
->with($schema);
$visitor->expects($this->never())
->method('acceptNamespace');
$visitor->expects($this->at(1))
->method('acceptTable')
->with($schema->getTable('baz'));
$visitor->expects($this->at(2))
->method('acceptTable')
->with($schema->getTable('bla.bloo'));
$visitor->expects($this->exactly(2))
->method('acceptTable');
$visitor->expects($this->at(3))
->method('acceptSequence')
->with($schema->getSequence('moo'));
$visitor->expects($this->at(4))
->method('acceptSequence')
->with($schema->getSequence('war'));
$visitor->expects($this->exactly(2))
->method('acceptSequence');
$this->assertNull($schema->visit($visitor));
}
/**
* @group DBAL-669
*/
public function testVisitsNamespaceVisitor()
{
$schema = new Schema();
$visitor = $this->getMock('Doctrine\DBAL\Schema\Visitor\AbstractVisitor');
$schema->createNamespace('foo');
$schema->createNamespace('bar');
$schema->createTable('baz');
$schema->createTable('bla.bloo');
$schema->createSequence('moo');
$schema->createSequence('war');
$visitor->expects($this->once())
->method('acceptSchema')
->with($schema);
$visitor->expects($this->at(1))
->method('acceptNamespace')
->with('foo');
$visitor->expects($this->at(2))
->method('acceptNamespace')
->with('bar');
$visitor->expects($this->at(3))
->method('acceptNamespace')
->with('bla');
$visitor->expects($this->exactly(3))
->method('acceptNamespace');
$visitor->expects($this->at(4))
->method('acceptTable')
->with($schema->getTable('baz'));
$visitor->expects($this->at(5))
->method('acceptTable')
->with($schema->getTable('bla.bloo'));
$visitor->expects($this->exactly(2))
->method('acceptTable');
$visitor->expects($this->at(6))
->method('acceptSequence')
->with($schema->getSequence('moo'));
$visitor->expects($this->at(7))
->method('acceptSequence')
->with($schema->getSequence('war'));
$visitor->expects($this->exactly(2))
->method('acceptSequence');
$this->assertNull($schema->visit($visitor));
}
} }
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