From 0e6a2449e77659d175ed8815cedf1949b073501f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Sjo=CC=88berg?= Date: Fri, 16 Feb 2018 00:20:28 +0000 Subject: [PATCH] Add closure values --- src/StickyContext.php | 4 +++- tests/StickyContextProcessorTest.php | 2 +- tests/StickyContextTest.php | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/StickyContextTest.php diff --git a/src/StickyContext.php b/src/StickyContext.php index 26795f4..f0f4401 100644 --- a/src/StickyContext.php +++ b/src/StickyContext.php @@ -46,7 +46,9 @@ public static function add($key, $data) */ public static function all() { - return static::$data; + return array_map(function ($value) { + return is_callable($value) ? $value() : $value; + }, static::$data); } /** diff --git a/tests/StickyContextProcessorTest.php b/tests/StickyContextProcessorTest.php index 43f9cc4..9768032 100644 --- a/tests/StickyContextProcessorTest.php +++ b/tests/StickyContextProcessorTest.php @@ -9,7 +9,7 @@ class StickyContextProcessorTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass() { require __DIR__ .'/../vendor/autoload.php'; - parent::setUpBeforeClass(); // TODO: Change the autogenerated stub + parent::setUpBeforeClass(); } public function test_it_does_not_add_sticky_data_if_none_is_available() diff --git a/tests/StickyContextTest.php b/tests/StickyContextTest.php new file mode 100644 index 0000000..e22b39f --- /dev/null +++ b/tests/StickyContextTest.php @@ -0,0 +1,21 @@ +assertEquals(['arya' => 'Stark'], StickyContext::all()); + } +}