1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-03 11:21:01 +01:00

Don't pop invalid test environment

Summary: If `unset($env)` throws then we pop some other environment instead which is impossible to pop later.

Test Plan:
  $ arc unit src/infrastructure/env/__tests__ src/applications/calendar/storage/__tests__

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4488
This commit is contained in:
vrana 2013-01-17 11:50:49 -08:00
parent 09ad34c34b
commit f896696fde
3 changed files with 8 additions and 22 deletions

View file

@ -293,6 +293,7 @@ final class PhabricatorEnv {
$source = self::$sourceStack->popSource(); $source = self::$sourceStack->popSource();
$stack_key = spl_object_hash($source); $stack_key = spl_object_hash($source);
if ($stack_key !== $key) { if ($stack_key !== $key) {
self::$sourceStack->pushSource($source);
throw new Exception( throw new Exception(
"Scoped environments were destroyed in a diffent order than they ". "Scoped environments were destroyed in a diffent order than they ".
"were initialized."); "were initialized.");

View file

@ -130,15 +130,11 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase {
public function testOverrideOrder() { public function testOverrideOrder() {
$outer = PhabricatorEnv::beginScopedEnv(); $outer = PhabricatorEnv::beginScopedEnv();
$middle = PhabricatorEnv::beginScopedEnv();
$inner = PhabricatorEnv::beginScopedEnv(); $inner = PhabricatorEnv::beginScopedEnv();
$caught = null; $caught = null;
try { try {
if (phutil_is_hiphop_runtime()) { $outer->__destruct();
$middle->__destruct();
}
unset($middle);
} catch (Exception $ex) { } catch (Exception $ex) {
$caught = $ex; $caught = $ex;
} }
@ -149,25 +145,11 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase {
"Destroying a scoped environment which is not on the top of the stack ". "Destroying a scoped environment which is not on the top of the stack ".
"should throw."); "should throw.");
$caught = null; if (phutil_is_hiphop_runtime()) {
try { $inner->__destruct();
if (phutil_is_hiphop_runtime()) {
$inner->__destruct();
}
unset($inner);
} catch (Exception $ex) {
$caught = $ex;
} }
unset($inner);
$this->assertEqual(
true,
$caught instanceof Exception,
"Destroying a scoped environment which is not on the top of the stack ".
"should throw.");
// Although we popped the other two out-of-order, we still expect to end
// up in the right state after handling the exceptions, so this should
// execute without issues.
if (phutil_is_hiphop_runtime()) { if (phutil_is_hiphop_runtime()) {
$outer->__destruct(); $outer->__destruct();
} }

View file

@ -91,6 +91,9 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
} }
try { try {
if (phutil_is_hiphop_runtime()) {
$this->env->__destruct();
}
unset($this->env); unset($this->env);
} catch (Exception $ex) { } catch (Exception $ex) {
throw new Exception( throw new Exception(