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:
parent
09ad34c34b
commit
f896696fde
3 changed files with 8 additions and 22 deletions
1
src/infrastructure/env/PhabricatorEnv.php
vendored
1
src/infrastructure/env/PhabricatorEnv.php
vendored
|
@ -293,6 +293,7 @@ final class PhabricatorEnv {
|
|||
$source = self::$sourceStack->popSource();
|
||||
$stack_key = spl_object_hash($source);
|
||||
if ($stack_key !== $key) {
|
||||
self::$sourceStack->pushSource($source);
|
||||
throw new Exception(
|
||||
"Scoped environments were destroyed in a diffent order than they ".
|
||||
"were initialized.");
|
||||
|
|
|
@ -130,15 +130,11 @@ final class PhabricatorEnvTestCase extends PhabricatorTestCase {
|
|||
|
||||
public function testOverrideOrder() {
|
||||
$outer = PhabricatorEnv::beginScopedEnv();
|
||||
$middle = PhabricatorEnv::beginScopedEnv();
|
||||
$inner = PhabricatorEnv::beginScopedEnv();
|
||||
|
||||
$caught = null;
|
||||
try {
|
||||
if (phutil_is_hiphop_runtime()) {
|
||||
$middle->__destruct();
|
||||
}
|
||||
unset($middle);
|
||||
$outer->__destruct();
|
||||
} catch (Exception $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 ".
|
||||
"should throw.");
|
||||
|
||||
$caught = null;
|
||||
try {
|
||||
if (phutil_is_hiphop_runtime()) {
|
||||
$inner->__destruct();
|
||||
}
|
||||
unset($inner);
|
||||
} catch (Exception $ex) {
|
||||
$caught = $ex;
|
||||
}
|
||||
|
||||
$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()) {
|
||||
$outer->__destruct();
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ abstract class PhabricatorTestCase extends ArcanistPhutilTestCase {
|
|||
}
|
||||
|
||||
try {
|
||||
if (phutil_is_hiphop_runtime()) {
|
||||
$this->env->__destruct();
|
||||
}
|
||||
unset($this->env);
|
||||
} catch (Exception $ex) {
|
||||
throw new Exception(
|
||||
|
|
Loading…
Reference in a new issue