Commit 14241911 authored by Steve Müller's avatar Steve Müller

make schema visit namespaces

parent 3eebba76
......@@ -21,6 +21,7 @@ namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Visitor\CreateSchemaSqlCollector;
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
use Doctrine\DBAL\Schema\Visitor\NamespaceVisitor;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Platforms\AbstractPlatform;
......@@ -477,9 +478,16 @@ class Schema extends AbstractAsset
{
$visitor->acceptSchema($this);
if ($visitor instanceof NamespaceVisitor) {
foreach ($this->namespaces as $namespace) {
$visitor->acceptNamespace($namespace);
}
}
foreach ($this->_tables as $table) {
$table->visit($visitor);
}
foreach ($this->_sequences as $sequence) {
$sequence->visit($visitor);
}
......
......@@ -344,4 +344,114 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($schema->hasNamespace('baz'));
$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