3 namespace Doctrine\Tests\ORM\Functional;
5 use Doctrine\Common\Collections\Collection;
7 require_once __DIR__ . '/../../TestInit.php';
10 * Base class for testing a many-to-many association mapping (without inheritance).
12 class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctionalTestCase
14 protected $_firstField;
15 protected $_secondField;
18 public function assertForeignKeysContain($firstId, $secondId)
20 $this->assertEquals(1, $this->_countForeignKeys($firstId, $secondId));
23 public function assertForeignKeysNotContain($firstId, $secondId)
25 $this->assertEquals(0, $this->_countForeignKeys($firstId, $secondId));
28 protected function _countForeignKeys($firstId, $secondId)
30 return count($this->_em->getConnection()->executeQuery("
31 SELECT {$this->_firstField}
33 WHERE {$this->_firstField} = ?
34 AND {$this->_secondField} = ?
35 ", array($firstId, $secondId))->fetchAll());
38 public function assertCollectionEquals(Collection $first, Collection $second)
40 return $first->forAll(function($k, $e) use($second) { return $second->contains($e); });