Skip to content
This repository

[2.0] Log Writer support for MongoClient driver class #3220

Closed
wants to merge 1 commit into from

2 participants

Jeremy Mikola Matthew Weier O'Phinney
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Dec 13, 2012
Jeremy Mikola jmikola [2.0] Log Writer support for MongoClient driver class
See: #3145
1d9c2e8
This page is out of date. Refresh to see the latest.
7 library/Zend/Log/Writer/MongoDB.php
@@ -13,6 +13,7 @@
13 13
14 14 use DateTime;
15 15 use Mongo;
  16 +use MongoClient;
16 17 use MongoDate;
17 18 use Traversable;
18 19 use Zend\Log\Exception\InvalidArgumentException;
@@ -46,7 +47,7 @@ class MongoDB extends AbstractWriter
46 47 /**
47 48 * Constructor
48 49 *
49   - * @param Mongo|array|Traversable $mongo
  50 + * @param Mongo|MongoClient|array|Traversable $mongo
50 51 * @param string|MongoDB $database
51 52 * @param string $collection
52 53 * @param array $saveOptions
@@ -75,9 +76,9 @@ public function __construct($mongo, $database, $collection, array $saveOptions =
75 76 $mongo = isset($mongo['mongo']) ? $mongo['mongo'] : null;
76 77 }
77 78
78   - if (!($mongo instanceof Mongo)) {
  79 + if (!($mongo instanceof MongoClient || $mongo instanceof Mongo)) {
79 80 throw new Exception\InvalidArgumentException(
80   - 'Parameter of type %s is invalid; must be Mongo',
  81 + 'Parameter of type %s is invalid; must be MongoClient or Mongo',
81 82 (is_object($mongo) ? get_class($mongo) : gettype($mongo))
82 83 );
83 84 }
4 tests/ZendTest/Log/Writer/MongoDBTest.php
@@ -32,7 +32,9 @@ public function setUp()
32 32 $this->database = 'zf2_test';
33 33 $this->collection = 'logs';
34 34
35   - $this->mongo = $this->getMockBuilder('Mongo')
  35 + $mongoClass = (version_compare(phpversion('mongo'), '1.3.0', '<')) ? 'Mongo' : 'MongoClient';
  36 +
  37 + $this->mongo = $this->getMockBuilder($mongoClass)
36 38 ->disableOriginalConstructor()
37 39 ->setMethods(array('selectCollection'))
38 40 ->getMock();

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.