2009-07-02 13:37:59 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
2009-07-29 16:00:08 +04:00
|
|
|
use Doctrine\Common\Collections\Collection;
|
2009-07-02 13:37:59 +04:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for testing a many-to-many association mapping (without inheritance).
|
|
|
|
*/
|
|
|
|
class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected $_firstField;
|
|
|
|
protected $_secondField;
|
|
|
|
protected $_table;
|
|
|
|
|
|
|
|
public function assertForeignKeysContain($firstId, $secondId)
|
|
|
|
{
|
|
|
|
$this->assertEquals(1, $this->_countForeignKeys($firstId, $secondId));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assertForeignKeysNotContain($firstId, $secondId)
|
|
|
|
{
|
|
|
|
$this->assertEquals(0, $this->_countForeignKeys($firstId, $secondId));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function _countForeignKeys($firstId, $secondId)
|
|
|
|
{
|
|
|
|
return count($this->_em->getConnection()
|
|
|
|
->execute("SELECT {$this->_firstField}
|
|
|
|
FROM {$this->_table}
|
|
|
|
WHERE {$this->_firstField}=?
|
|
|
|
AND {$this->_secondField}=?",
|
2009-07-02 15:48:44 +04:00
|
|
|
array($firstId, $secondId))
|
|
|
|
->fetchAll());
|
2009-07-02 13:37:59 +04:00
|
|
|
}
|
|
|
|
|
2009-07-29 16:00:08 +04:00
|
|
|
public function assertCollectionEquals(Collection $first, Collection $second)
|
2009-07-02 13:37:59 +04:00
|
|
|
{
|
2009-07-03 21:36:41 +04:00
|
|
|
return $first->forAll(function($k, $e) use($second) { return $second->contains($e); });
|
2009-07-02 13:37:59 +04:00
|
|
|
}
|
|
|
|
}
|