vendor/monolog/src/Monolog/Handler/TestHandler.php
changeset 0 7f95f8617b0b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vendor/monolog/src/Monolog/Handler/TestHandler.php	Sat Sep 24 15:40:41 2011 +0200
@@ -0,0 +1,120 @@
+<?php
+
+/*
+ * This file is part of the Monolog package.
+ *
+ * (c) Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Monolog\Handler;
+
+use Monolog\Logger;
+
+/**
+ * Used for testing purposes.
+ *
+ * It records all records and gives you access to them for verification.
+ *
+ * @author Jordi Boggiano <j.boggiano@seld.be>
+ */
+class TestHandler extends AbstractProcessingHandler
+{
+    protected $records = array();
+    protected $recordsByLevel = array();
+
+    public function getRecords()
+    {
+        return $this->records;
+    }
+
+    public function hasAlert($record)
+    {
+        return $this->hasRecord($record, Logger::ALERT);
+    }
+
+    public function hasCritical($record)
+    {
+        return $this->hasRecord($record, Logger::CRITICAL);
+    }
+
+    public function hasError($record)
+    {
+        return $this->hasRecord($record, Logger::ERROR);
+    }
+
+    public function hasWarning($record)
+    {
+        return $this->hasRecord($record, Logger::WARNING);
+    }
+
+    public function hasInfo($record)
+    {
+        return $this->hasRecord($record, Logger::INFO);
+    }
+
+    public function hasDebug($record)
+    {
+        return $this->hasRecord($record, Logger::DEBUG);
+    }
+
+    public function hasAlertRecords()
+    {
+        return isset($this->recordsByLevel[Logger::ALERT]);
+    }
+
+    public function hasCriticalRecords()
+    {
+        return isset($this->recordsByLevel[Logger::CRITICAL]);
+    }
+
+    public function hasErrorRecords()
+    {
+        return isset($this->recordsByLevel[Logger::ERROR]);
+    }
+
+    public function hasWarningRecords()
+    {
+        return isset($this->recordsByLevel[Logger::WARNING]);
+    }
+
+    public function hasInfoRecords()
+    {
+        return isset($this->recordsByLevel[Logger::INFO]);
+    }
+
+    public function hasDebugRecords()
+    {
+        return isset($this->recordsByLevel[Logger::DEBUG]);
+    }
+
+    protected function hasRecord($record, $level)
+    {
+        if (!isset($this->recordsByLevel[$level])) {
+            return false;
+        }
+
+        if (is_array($record)) {
+            $record = $record['message'];
+        }
+
+        foreach ($this->recordsByLevel[$level] as $rec) {
+            if ($rec['message'] === $record) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function write(array $record)
+    {
+        $this->recordsByLevel[$record['level']][] = $record;
+        $this->records[] = $record;
+    }
+}
\ No newline at end of file