@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 166 lines 5.2 kB view raw
1<?php 2 3final class LiskFixtureTestCase extends PhabricatorTestCase { 4 5 protected function getPhabricatorTestCaseConfiguration() { 6 return array( 7 self::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES => true, 8 ); 9 } 10 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. 14 $this->assertEqual( 15 0, 16 count(id(new HarbormasterScratchTable())->loadAll())); 17 18 id(new HarbormasterScratchTable()) 19 ->setData('alincoln') 20 ->save(); 21 } 22 23 public function testTransactionalIsolation2of2() { 24 $this->assertEqual( 25 0, 26 count(id(new HarbormasterScratchTable())->loadAll())); 27 28 id(new HarbormasterScratchTable()) 29 ->setData('ugrant') 30 ->save(); 31 } 32 33 public function testFixturesBasicallyWork() { 34 $this->assertEqual( 35 0, 36 count(id(new HarbormasterScratchTable())->loadAll())); 37 38 id(new HarbormasterScratchTable()) 39 ->setData('gwashington') 40 ->save(); 41 42 $this->assertEqual( 43 1, 44 count(id(new HarbormasterScratchTable())->loadAll())); 45 } 46 47 public function testReadableTransactions() { 48 // TODO: When we have semi-durable fixtures, use those instead. This is 49 // extremely hacky. 50 51 LiskDAO::endIsolateAllLiskEffectsToTransactions(); 52 try { 53 54 $data = Filesystem::readRandomCharacters(32); 55 56 $obj = new HarbormasterScratchTable(); 57 $obj->openTransaction(); 58 59 $obj->setData($data); 60 $obj->save(); 61 62 $loaded = id(new HarbormasterScratchTable())->loadOneWhere( 63 'data = %s', 64 $data); 65 66 $obj->killTransaction(); 67 68 $this->assertTrue( 69 ($loaded !== null), 70 pht('Reads inside transactions should have transaction visibility.')); 71 72 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 73 } catch (Exception $ex) { 74 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 75 throw $ex; 76 } 77 } 78 79 public function testGarbageLoadCalls() { 80 $obj = new HarbormasterObject(); 81 $obj->save(); 82 $id = $obj->getID(); 83 84 $load = new HarbormasterObject(); 85 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')); 92 93 $this->assertTrue((bool)$load->load((int)$id)); 94 $this->assertTrue((bool)$load->load((string)$id)); 95 } 96 97 public function testCounters() { 98 $obj = new HarbormasterObject(); 99 $conn_w = $obj->establishConnection('w'); 100 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')); 105 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')); 110 111 // Test alternate access/overwrite methods. 112 $this->assertEqual(3, LiskDAO::loadCurrentCounterValue($conn_w, 'a')); 113 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')); 117 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(); 122 try { 123 124 $conn_1 = $obj->establishConnection('w', $force_new = true); 125 $conn_2 = $obj->establishConnection('w', $force_new = true); 126 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')); 132 133 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 134 } catch (Exception $ex) { 135 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 136 throw $ex; 137 } 138 } 139 140 public function testNonmutableColumns() { 141 $object = id(new HarbormasterScratchTable()) 142 ->setData('val1') 143 ->setNonmutableData('val1') 144 ->save(); 145 146 $object->reload(); 147 148 $this->assertEqual('val1', $object->getData()); 149 $this->assertEqual('val1', $object->getNonmutableData()); 150 151 $object 152 ->setData('val2') 153 ->setNonmutableData('val2') 154 ->save(); 155 156 $object->reload(); 157 158 $this->assertEqual('val2', $object->getData()); 159 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()); 163 } 164 165 166}