Add TestLogger::setCollectContext and fluent interface
authorAntoine Musso <hashar@free.fr>
Tue, 31 Jan 2017 14:42:44 +0000 (15:42 +0100)
committerAntoine Musso <hashar@free.fr>
Wed, 1 Feb 2017 00:45:28 +0000 (01:45 +0100)
TestLogger has a setCollect() but lacked a similar method for the
$collectContext introduced with:
    7b85b6b09e - Optionally collect context in TestLogger

Document $collectContext on __construct()
Add setCollectContext()
Make both setCollect() and setCollectContext() to return $this for
fluent interface:

  $logger = new \TestLogger();
  $logger
      ->setCollect( true ),
      ->setCollectContext( true );

Change-Id: I806b07cfddbc7b428d41e3d619ef4d1db16f6747

tests/phpunit/includes/TestLogger.php

index 7086a92..84a6adf 100644 (file)
@@ -38,9 +38,11 @@ class TestLogger extends \Psr\Log\AbstractLogger {
        private $filter = null;
 
        /**
        private $filter = null;
 
        /**
-        * @param bool $collect Whether to collect logs
+        * @param bool $collect Whether to collect logs. @see setCollect()
         * @param callable $filter Filter logs before collecting/printing. Signature is
         *  string|null function ( string $message, string $level, array $context );
         * @param callable $filter Filter logs before collecting/printing. Signature is
         *  string|null function ( string $message, string $level, array $context );
+        * @param bool $collectContext Whether to keep the context passed to log.
+        *                             @since 1.29 @see setCollectContext()
         */
        public function __construct( $collect = false, $filter = null, $collectContext = false ) {
                $this->collect = $collect;
         */
        public function __construct( $collect = false, $filter = null, $collectContext = false ) {
                $this->collect = $collect;
@@ -51,9 +53,23 @@ class TestLogger extends \Psr\Log\AbstractLogger {
        /**
         * Set the "collect" flag
         * @param bool $collect
        /**
         * Set the "collect" flag
         * @param bool $collect
+        * @return TestLogger $this
         */
        public function setCollect( $collect ) {
                $this->collect = $collect;
         */
        public function setCollect( $collect ) {
                $this->collect = $collect;
+               return $this;
+       }
+
+       /**
+        * Set the collectContext flag
+        *
+        * @param bool $collectContext
+        * @since 1.29
+        * @return TestLogger $this
+        */
+       public function setCollectContext( $collectContext ) {
+               $this->collectContext = $collectContext;
+               return $this;
        }
 
        /**
        }
 
        /**