IndexTest.php 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Doctrine\Tests\DBAL\Schema;
  3. require_once __DIR__ . '/../../TestInit.php';
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\DBAL\Schema\Table;
  6. use Doctrine\DBAL\Schema\Column;
  7. use Doctrine\DBAL\Schema\Index;
  8. class IndexTest extends \PHPUnit_Framework_TestCase
  9. {
  10. public function createIndex($unique=false, $primary=false)
  11. {
  12. return new Index("foo", array("bar", "baz"), $unique, $primary);
  13. }
  14. public function testCreateIndex()
  15. {
  16. $idx = $this->createIndex();
  17. $this->assertEquals("foo", $idx->getName());
  18. $columns = $idx->getColumns();
  19. $this->assertEquals(2, count($columns));
  20. $this->assertEquals(array("bar", "baz"), $columns);
  21. $this->assertFalse($idx->isUnique());
  22. $this->assertFalse($idx->isPrimary());
  23. }
  24. public function testCreatePrimary()
  25. {
  26. $idx = $this->createIndex(false, true);
  27. $this->assertTrue($idx->isUnique());
  28. $this->assertTrue($idx->isPrimary());
  29. }
  30. public function testCreateUnique()
  31. {
  32. $idx = $this->createIndex(true, false);
  33. $this->assertTrue($idx->isUnique());
  34. $this->assertFalse($idx->isPrimary());
  35. }
  36. /**
  37. * @group DBAL-50
  38. */
  39. public function testFullfilledByUnique()
  40. {
  41. $idx1 = $this->createIndex(true, false);
  42. $idx2 = $this->createIndex(true, false);
  43. $idx3 = $this->createIndex();
  44. $this->assertTrue($idx1->isFullfilledBy($idx2));
  45. $this->assertFalse($idx1->isFullfilledBy($idx3));
  46. }
  47. /**
  48. * @group DBAL-50
  49. */
  50. public function testFullfilledByPrimary()
  51. {
  52. $idx1 = $this->createIndex(true, true);
  53. $idx2 = $this->createIndex(true, true);
  54. $idx3 = $this->createIndex(true, false);
  55. $this->assertTrue($idx1->isFullfilledBy($idx2));
  56. $this->assertFalse($idx1->isFullfilledBy($idx3));
  57. }
  58. /**
  59. * @group DBAL-50
  60. */
  61. public function testFullfilledByIndex()
  62. {
  63. $idx1 = $this->createIndex();
  64. $idx2 = $this->createIndex();
  65. $pri = $this->createIndex(true, true);
  66. $uniq = $this->createIndex(true);
  67. $this->assertTrue($idx1->isFullfilledBy($idx2));
  68. $this->assertTrue($idx1->isFullfilledBy($pri));
  69. $this->assertTrue($idx1->isFullfilledBy($uniq));
  70. }
  71. }