AbstractManyToManyAssociationTestCase.php 1.2KB

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