Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / AbstractManyToManyAssociationTestCase.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional;
4
5 use Doctrine\Common\Collections\Collection;
6
7 require_once __DIR__ . '/../../TestInit.php';
8
9 /**
10  * Base class for testing a many-to-many association mapping (without inheritance).
11  */
12 class AbstractManyToManyAssociationTestCase extends \Doctrine\Tests\OrmFunctionalTestCase
13 {
14     protected $_firstField;
15     protected $_secondField;
16     protected $_table;
17
18     public function assertForeignKeysContain($firstId, $secondId)
19     {
20         $this->assertEquals(1, $this->_countForeignKeys($firstId, $secondId));
21     }
22
23     public function assertForeignKeysNotContain($firstId, $secondId)
24     {
25         $this->assertEquals(0, $this->_countForeignKeys($firstId, $secondId));
26     }
27
28     protected function _countForeignKeys($firstId, $secondId)
29     {
30         return count($this->_em->getConnection()->executeQuery("
31             SELECT {$this->_firstField}
32               FROM {$this->_table}
33              WHERE {$this->_firstField} = ?
34                AND {$this->_secondField} = ?
35         ", array($firstId, $secondId))->fetchAll());
36     }
37
38     public function assertCollectionEquals(Collection $first, Collection $second)
39     {
40         return $first->forAll(function($k, $e) use($second) { return $second->contains($e); });
41     }
42 }