3 namespace Doctrine\Tests\DBAL\Schema;
5 require_once __DIR__ . '/../../TestInit.php';
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Schema\Column;
10 use Doctrine\DBAL\Schema\Index;
12 class IndexTest extends \PHPUnit_Framework_TestCase
14 public function createIndex($unique=false, $primary=false)
16 return new Index("foo", array("bar", "baz"), $unique, $primary);
19 public function testCreateIndex()
21 $idx = $this->createIndex();
22 $this->assertEquals("foo", $idx->getName());
23 $columns = $idx->getColumns();
24 $this->assertEquals(2, count($columns));
25 $this->assertEquals(array("bar", "baz"), $columns);
26 $this->assertFalse($idx->isUnique());
27 $this->assertFalse($idx->isPrimary());
30 public function testCreatePrimary()
32 $idx = $this->createIndex(false, true);
33 $this->assertTrue($idx->isUnique());
34 $this->assertTrue($idx->isPrimary());
37 public function testCreateUnique()
39 $idx = $this->createIndex(true, false);
40 $this->assertTrue($idx->isUnique());
41 $this->assertFalse($idx->isPrimary());
47 public function testFullfilledByUnique()
49 $idx1 = $this->createIndex(true, false);
50 $idx2 = $this->createIndex(true, false);
51 $idx3 = $this->createIndex();
53 $this->assertTrue($idx1->isFullfilledBy($idx2));
54 $this->assertFalse($idx1->isFullfilledBy($idx3));
60 public function testFullfilledByPrimary()
62 $idx1 = $this->createIndex(true, true);
63 $idx2 = $this->createIndex(true, true);
64 $idx3 = $this->createIndex(true, false);
66 $this->assertTrue($idx1->isFullfilledBy($idx2));
67 $this->assertFalse($idx1->isFullfilledBy($idx3));
73 public function testFullfilledByIndex()
75 $idx1 = $this->createIndex();
76 $idx2 = $this->createIndex();
77 $pri = $this->createIndex(true, true);
78 $uniq = $this->createIndex(true);
80 $this->assertTrue($idx1->isFullfilledBy($idx2));
81 $this->assertTrue($idx1->isFullfilledBy($pri));
82 $this->assertTrue($idx1->isFullfilledBy($uniq));
88 public function testFlags()
90 $idx1 = $this->createIndex();
91 $this->assertFalse($idx1->hasFlag('clustered'));
93 $idx1->addFlag('clustered');
94 $this->assertTrue($idx1->hasFlag('clustered'));
95 $this->assertTrue($idx1->hasFlag('CLUSTERED'));
97 $idx1->removeFlag('clustered');
98 $this->assertFalse($idx1->hasFlag('clustered'));
104 public function testIndexQuotes()
106 $index = new Index("foo", array("`bar`", "`baz`"));
108 $this->assertTrue($index->spansColumns(array("bar", "baz")));
109 $this->assertTrue($index->hasColumnAtPosition("bar", 0));
110 $this->assertTrue($index->hasColumnAtPosition("baz", 1));
112 $this->assertFalse($index->hasColumnAtPosition("bar", 1));
113 $this->assertFalse($index->hasColumnAtPosition("baz", 0));