summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SpyLogger.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SpyLogger.php')
-rw-r--r--www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SpyLogger.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SpyLogger.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SpyLogger.php
new file mode 100644
index 00000000..bd18da13
--- /dev/null
+++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Utils/SpyLogger.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace SMW\Tests\Utils;
+
+use Psr\Log\AbstractLogger;
+
+/**
+ * @group semantic-mediawiki
+ *
+ * @license GNU GPL v2+
+ * @since 2.5
+ *
+ * @author mwjames
+ */
+class SpyLogger extends AbstractLogger {
+
+ /**
+ * @var array
+ */
+ private $logs = [];
+
+ /**
+ * @since 2.5
+ *
+ * {@inheritDoc}
+ */
+ public function log( $level, $message, array $context = [] ) {
+
+ if ( is_array( $message ) ) {
+ $message = json_encode( $message );
+ }
+
+ $this->logs[] = [ $level, $message, $context ];
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @return array
+ */
+ public function getLogs() {
+ return $this->logs;
+ }
+
+ /**
+ * @since 2.5
+ *
+ * @return string
+ */
+ public function getMessagesAsString() {
+ $message = '';
+
+ foreach ( $this->logs as $log ) {
+ $message .= ' ' . $log[1];
+ }
+
+ return $message;
+ }
+
+}