3 final class PhabricatorHandlePoolTestCase
extends PhabricatorTestCase
{
5 protected function getPhabricatorTestCaseConfiguration() {
7 self
::PHABRICATOR_TESTCONFIG_BUILD_STORAGE_FIXTURES
=> true,
11 public function testHandlePools() {
12 // A lot of the batch/just-in-time/cache behavior of handle pools is not
13 // observable by design, so these tests don't directly cover it.
15 $viewer = $this->generateNewTestUser();
16 $viewer_phid = $viewer->getPHID();
18 $phids = array($viewer_phid);
20 $handles = $viewer->loadHandles($phids);
22 // The handle load hasn't happened yet, but we can't directly observe that.
24 // Test Countable behaviors.
25 $this->assertEqual(1, count($handles));
27 // Test ArrayAccess behaviors.
30 array_keys(iterator_to_array($handles)));
31 $this->assertEqual(true, $handles[$viewer_phid]->isComplete());
32 $this->assertEqual($viewer_phid, $handles[$viewer_phid]->getPHID());
33 $this->assertTrue(isset($handles[$viewer_phid]));
34 $this->assertFalse(isset($handles['quack']));
36 // Test Iterator behaviors.
37 foreach ($handles as $key => $handle) {
38 $this->assertEqual($viewer_phid, $key);
39 $this->assertEqual($viewer_phid, $handle->getPHID());
42 // Do this twice to make sure the handle list is rewindable.
43 foreach ($handles as $key => $handle) {
44 $this->assertEqual($viewer_phid, $key);
45 $this->assertEqual($viewer_phid, $handle->getPHID());
48 $more_handles = $viewer->loadHandles($phids);
50 // This is testing that we got back a reference to the exact same object,
51 // which implies the caching behavior is working correctly.
53 $handles[$viewer_phid],
54 $more_handles[$viewer_phid],
55 pht('Handles should use viewer handle pool cache.'));