3 final class LiskFixtureTestCase
extends PhabricatorTestCase
{
5 protected function getPhabricatorTestCaseConfiguration() {
7 self
::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES
=> true,
11 public function testTransactionalIsolation1of2() {
12 // NOTE: These tests are verifying that data is destroyed between tests.
13 // If the user from either test persists, the other test will fail.
16 count(id(new HarbormasterScratchTable())->loadAll()));
18 id(new HarbormasterScratchTable())
23 public function testTransactionalIsolation2of2() {
26 count(id(new HarbormasterScratchTable())->loadAll()));
28 id(new HarbormasterScratchTable())
33 public function testFixturesBasicallyWork() {
36 count(id(new HarbormasterScratchTable())->loadAll()));
38 id(new HarbormasterScratchTable())
39 ->setData('gwashington')
44 count(id(new HarbormasterScratchTable())->loadAll()));
47 public function testReadableTransactions() {
48 // TODO: When we have semi-durable fixtures, use those instead. This is
51 LiskDAO
::endIsolateAllLiskEffectsToTransactions();
54 $data = Filesystem
::readRandomCharacters(32);
56 $obj = new HarbormasterScratchTable();
57 $obj->openTransaction();
62 $loaded = id(new HarbormasterScratchTable())->loadOneWhere(
66 $obj->killTransaction();
70 pht('Reads inside transactions should have transaction visibility.'));
72 LiskDAO
::beginIsolateAllLiskEffectsToTransactions();
73 } catch (Exception
$ex) {
74 LiskDAO
::beginIsolateAllLiskEffectsToTransactions();
79 public function testGarbageLoadCalls() {
80 $obj = new HarbormasterObject();
84 $load = new HarbormasterObject();
86 $this->assertEqual(null, $load->load(0));
87 $this->assertEqual(null, $load->load(-1));
88 $this->assertEqual(null, $load->load(9999));
89 $this->assertEqual(null, $load->load(''));
90 $this->assertEqual(null, $load->load('cow'));
91 $this->assertEqual(null, $load->load($id.'cow'));
93 $this->assertTrue((bool)$load->load((int)$id));
94 $this->assertTrue((bool)$load->load((string)$id));
97 public function testCounters() {
98 $obj = new HarbormasterObject();
99 $conn_w = $obj->establishConnection('w');
101 // Test that the counter basically behaves as expected.
102 $this->assertEqual(1, LiskDAO
::loadNextCounterValue($conn_w, 'a'));
103 $this->assertEqual(2, LiskDAO
::loadNextCounterValue($conn_w, 'a'));
104 $this->assertEqual(3, LiskDAO
::loadNextCounterValue($conn_w, 'a'));
106 // This first insert is primarily a test that the previous LAST_INSERT_ID()
107 // value does not bleed into the creation of a new counter.
108 $this->assertEqual(1, LiskDAO
::loadNextCounterValue($conn_w, 'b'));
109 $this->assertEqual(2, LiskDAO
::loadNextCounterValue($conn_w, 'b'));
111 // Test alternate access/overwrite methods.
112 $this->assertEqual(3, LiskDAO
::loadCurrentCounterValue($conn_w, 'a'));
114 LiskDAO
::overwriteCounterValue($conn_w, 'a', 42);
115 $this->assertEqual(42, LiskDAO
::loadCurrentCounterValue($conn_w, 'a'));
116 $this->assertEqual(43, LiskDAO
::loadNextCounterValue($conn_w, 'a'));
118 // These inserts alternate database connections. Since unit tests are
119 // transactional by default, we need to break out of them or we'll deadlock
120 // since the transactions don't normally close until we exit the test.
121 LiskDAO
::endIsolateAllLiskEffectsToTransactions();
124 $conn_1 = $obj->establishConnection('w', $force_new = true);
125 $conn_2 = $obj->establishConnection('w', $force_new = true);
127 $this->assertEqual(1, LiskDAO
::loadNextCounterValue($conn_1, 'z'));
128 $this->assertEqual(2, LiskDAO
::loadNextCounterValue($conn_2, 'z'));
129 $this->assertEqual(3, LiskDAO
::loadNextCounterValue($conn_1, 'z'));
130 $this->assertEqual(4, LiskDAO
::loadNextCounterValue($conn_2, 'z'));
131 $this->assertEqual(5, LiskDAO
::loadNextCounterValue($conn_1, 'z'));
133 LiskDAO
::beginIsolateAllLiskEffectsToTransactions();
134 } catch (Exception
$ex) {
135 LiskDAO
::beginIsolateAllLiskEffectsToTransactions();
140 public function testNonmutableColumns() {
141 $object = id(new HarbormasterScratchTable())
143 ->setNonmutableData('val1')
148 $this->assertEqual('val1', $object->getData());
149 $this->assertEqual('val1', $object->getNonmutableData());
153 ->setNonmutableData('val2')
158 $this->assertEqual('val2', $object->getData());
160 // NOTE: This is the important test: the nonmutable column should not have
161 // been affected by the update.
162 $this->assertEqual('val1', $object->getNonmutableData());