[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class LiskFixtureTestCase extends PhabricatorTestCase { 4 5 public 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 '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 bascially behaves as expected. 102 $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_w, 'a')); 103 $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'a')); 104 $this->assertEqual(3, LiskDAO::loadNextCounterID($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::loadNextCounterID($conn_w, 'b')); 109 $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_w, 'b')); 110 111 // These inserts alternate database connections. Since unit tests are 112 // transactional by default, we need to break out of them or we'll deadlock 113 // since the transactions don't normally close until we exit the test. 114 LiskDAO::endIsolateAllLiskEffectsToTransactions(); 115 try { 116 117 $conn_1 = $obj->establishConnection('w', $force_new = true); 118 $conn_2 = $obj->establishConnection('w', $force_new = true); 119 120 $this->assertEqual(1, LiskDAO::loadNextCounterID($conn_1, 'z')); 121 $this->assertEqual(2, LiskDAO::loadNextCounterID($conn_2, 'z')); 122 $this->assertEqual(3, LiskDAO::loadNextCounterID($conn_1, 'z')); 123 $this->assertEqual(4, LiskDAO::loadNextCounterID($conn_2, 'z')); 124 $this->assertEqual(5, LiskDAO::loadNextCounterID($conn_1, 'z')); 125 126 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 127 } catch (Exception $ex) { 128 LiskDAO::beginIsolateAllLiskEffectsToTransactions(); 129 throw $ex; 130 } 131 } 132 133 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |