diff --git a/.gitignore b/.gitignore index f4686f8..85210f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.idea/ /vendor/ +/tests/phpunit.log /composer.lock diff --git a/makefile b/makefile index 897c411..b1e3726 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -.PHONY: demo demo-build demo-run +.PHONY: demo demo-build demo-run tests demo: composer install @@ -11,3 +11,6 @@ demo-build: demo-run: docker run --rm -p 8080:80 --name tracy-profiler-demo tracy-profiler-demo + +tests: + sudo docker run -v $$(pwd):/app --rm php:5.4-cli bash -c 'cd /app && php ./vendor/bin/phpunit' diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..771ed39 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + ./tests + + + + + + diff --git a/src/Profiler/Profiler.php b/src/Profiler/Profiler.php index c58e0e4..2c61a44 100644 --- a/src/Profiler/Profiler.php +++ b/src/Profiler/Profiler.php @@ -9,15 +9,22 @@ class Profiler extends AdvancedProfiler { private static $postProcessors; - public static function setPostProcessor(callable $postProcessor) + /** + * @inheritdoc + */ + public static function setPostProcessor(callable $postProcessor, $postProcessorId = "default") { - $postProcessorId = func_get_arg(1); self::$postProcessors[$postProcessorId] = $postProcessor; $postProcessors = self::$postProcessors; parent::setPostProcessor(function (Profile $profile) use ($postProcessors) { - foreach ($postProcessors as $postProcessor) { - $profile = call_user_func($postProcessor, $profile); + foreach ($postProcessors as $key => $postProcessor) { + if ($key !== "default") { + $profile = call_user_func($postProcessor, $profile); + } + } + if (isset($postProcessors["default"])) { + $profile = call_user_func($postProcessors["default"], $profile); } return $profile; }); diff --git a/tests/Profiler/ProfilerTest.php b/tests/Profiler/ProfilerTest.php index 87d47ac..569bf1e 100644 --- a/tests/Profiler/ProfilerTest.php +++ b/tests/Profiler/ProfilerTest.php @@ -1,6 +1,39 @@ assertEquals([3, 4, 2], $order); + } }