Skip to content

Commit

Permalink
Merge pull request #586 from JeroenDeDauw/DropSchemaSqlCollector
Browse files Browse the repository at this point in the history
Change weird way of adding an entry to SplObjectStorage
  • Loading branch information
guilhermeblanco committed May 5, 2014
2 parents 4a7ff71 + 4ef88ef commit d328488
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php
Expand Up @@ -80,8 +80,7 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons
throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint);
}

$this->constraints->attach($fkConstraint);
$this->constraints[$fkConstraint] = $localTable;
$this->constraints->attach($fkConstraint, $localTable);
}

/**
Expand Down
@@ -0,0 +1,55 @@
<?php

namespace Doctrine\Tests\DBAL\Schema\Visitor;

use \Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;

class DropSchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
{
public function testGetQueriesUsesAcceptedForeignKeys()
{
$tableOne = $this->getMockWithoutArguments('Doctrine\DBAL\Schema\Table');
$tableTwo = $this->getMockWithoutArguments('Doctrine\DBAL\Schema\Table');

$keyConstraintOne = $this->getStubKeyConstraint('first');
$keyConstraintTwo = $this->getStubKeyConstraint('second');

$platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\AbstractPlatform')
->setMethods(array('getDropForeignKeySQL'))
->getMockForAbstractClass();

$collector = new DropSchemaSqlCollector($platform);

$platform->expects($this->exactly(2))
->method('getDropForeignKeySQL');

$platform->expects($this->at(0))
->method('getDropForeignKeySQL')
->with($keyConstraintOne, $tableOne);

$platform->expects($this->at(1))
->method('getDropForeignKeySQL')
->with($keyConstraintTwo, $tableTwo);

$collector->acceptForeignKey($tableOne, $keyConstraintOne);
$collector->acceptForeignKey($tableTwo, $keyConstraintTwo);

$collector->getQueries();
}

private function getMockWithoutArguments($className)
{
return $this->getMockBuilder($className)->disableOriginalConstructor()->getMock();
}

private function getStubKeyConstraint($name)
{
$constraint = $this->getMockWithoutArguments('Doctrine\DBAL\Schema\ForeignKeyConstraint');

$constraint->expects($this->any())
->method('getName')
->will($this->returnValue($name));

return $constraint;
}
}

0 comments on commit d328488

Please sign in to comment.