diff --git a/composer.json b/composer.json index aa0e889..2fb9c81 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "src/helpers/Craft.php", "src/helpers/Http.php", "src/helpers/Model.php", + "src/helpers/Queue.php", "src/helpers/Test.php" ] }, diff --git a/src/helpers/Queue.php b/src/helpers/Queue.php new file mode 100644 index 0000000..60de9d6 --- /dev/null +++ b/src/helpers/Queue.php @@ -0,0 +1,20 @@ +queue->run(); + + return $result; + } +} diff --git a/src/test/CleanupRequestState.php b/src/test/CleanupRequestState.php new file mode 100644 index 0000000..ebfb783 --- /dev/null +++ b/src/test/CleanupRequestState.php @@ -0,0 +1,33 @@ +hasProperty('afterRequestCallbacks')) { + $reflect = $reflect->getParentClass(); + } + + if ($reflect) { + $property = $reflect->getProperty('afterRequestCallbacks'); + $property->setValue($app, []); + } + } + } +} diff --git a/src/test/TestCase.php b/src/test/TestCase.php index e06c8b7..5eea605 100644 --- a/src/test/TestCase.php +++ b/src/test/TestCase.php @@ -14,6 +14,7 @@ class TestCase extends \PHPUnit\Framework\TestCase { use ActingAs, Benchmark, + CleanupRequestState, CookieState, DatabaseAssertions, Dd, diff --git a/tests/RequestStateTest.php b/tests/RequestStateTest.php new file mode 100644 index 0000000..e74654c --- /dev/null +++ b/tests/RequestStateTest.php @@ -0,0 +1,17 @@ +onAfterRequest(fn () => throw new Exception('An after request callback was not cleared.')); + + expect(true)->toBeTrue(); +}); + +test('expects request state to be empty', function () { + $app = Craft::$app; + $reflect = new ReflectionClass($app); + while ($reflect && ! $reflect->hasProperty('afterRequestCallbacks')) { + $reflect = $reflect->getParentClass(); + } + + expect($reflect->getProperty('afterRequestCallbacks')->getValue($app))->toBeEmpty(); +})->depends('sets request state');