Skip to content

Commit

Permalink
Add closure values
Browse files Browse the repository at this point in the history
  • Loading branch information
phroggyy committed Feb 16, 2018
1 parent 2174599 commit 0e6a244
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/StickyContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/StickyContextProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions tests/StickyContextTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Decahedron\StickyLogging\StickyContext;

class StickyContextTest extends \PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
{
require __DIR__ .'/../vendor/autoload.php';
parent::setUpBeforeClass();
}

public function test_it_can_execute_closure_values()
{
StickyContext::add('arya', function () {
return 'Stark';
});

$this->assertEquals(['arya' => 'Stark'], StickyContext::all());
}
}

0 comments on commit 0e6a244

Please sign in to comment.