ソースを参照

Remove obvious errors in test suite

Andreas Braun 10 年 前
コミット
ac7e8615d9

+ 6 - 0
phpunit.xml.dist

@@ -9,6 +9,12 @@
          stopOnFailure="false"
          syntaxCheck="false"
 >
+    <php>
+        <!-- Disable deprecation warnings -->
+        <!-- php -r 'echo -1 & ~E_USER_DEPRECATED & ~E_DEPRECATED;' -->
+        <ini name="error_reporting" value="-24577"/>
+    </php>
+
     <testsuites>
         <testsuite name="Mongo driver adapter test suite">
             <directory>./tests/Alcaeus/MongoDbAdapter/</directory>

+ 2 - 2
tests/Alcaeus/MongoDbAdapter/MongoClientTest.php

@@ -67,8 +67,8 @@ class MongoClientTest extends TestCase
         $client = $this->getClient();
         $this->assertSame(['type' => \MongoClient::RP_PRIMARY], $client->getReadPreference());
 
-        $this->assertTrue($client->setReadPreference(\MongoClient::RP_SECONDARY, ['a' => 'b']));
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => ['a' => 'b']], $client->getReadPreference());
+        $this->assertTrue($client->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]));
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => [['a' => 'b']]], $client->getReadPreference());
     }
 
     public function testWriteConcern()

+ 28 - 11
tests/Alcaeus/MongoDbAdapter/MongoCollectionTest.php

@@ -489,16 +489,10 @@ class MongoCollectionTest extends TestCase
         $this->assertSame(['type' => \MongoClient::RP_PRIMARY], $collection->getReadPreference());
         $this->assertFalse($collection->getSlaveOkay());
 
-        $this->assertTrue($collection->setReadPreference(\MongoClient::RP_SECONDARY, ['a' => 'b']));
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => ['a' => 'b']], $collection->getReadPreference());
+        $this->assertTrue($collection->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]));
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => [['a' => 'b']]], $collection->getReadPreference());
         $this->assertTrue($collection->getSlaveOkay());
 
-        // Only way to check whether options are passed down is through debugInfo
-        $writeConcern = $collection->getCollection()->__debugInfo()['readPreference'];
-
-        $this->assertSame(ReadPreference::RP_SECONDARY, $writeConcern->getMode());
-        $this->assertSame(['a' => 'b'], $writeConcern->getTagSets());
-
         $this->assertTrue($collection->setSlaveOkay(true));
         $this->assertSame(['type' => \MongoClient::RP_SECONDARY_PREFERRED, 'tagsets' => ['a' => 'b']], $collection->getReadPreference());
 
@@ -506,13 +500,28 @@ class MongoCollectionTest extends TestCase
         $this->assertSame(['type' => \MongoClient::RP_PRIMARY], $collection->getReadPreference());
     }
 
+    public function testReadPreferenceIsSetInDriver()
+    {
+        $this->skipTestIf(extension_loaded('mongo'));
+
+        $collection = $this->getCollection();
+
+        $this->assertTrue($collection->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]));
+
+        // Only way to check whether options are passed down is through debugInfo
+        $readPreference = $collection->getCollection()->__debugInfo()['readPreference'];
+
+        $this->assertSame(ReadPreference::RP_SECONDARY, $readPreference->getMode());
+        $this->assertSame(['a' => 'b'], $readPreference->getTagSets());
+    }
+
     public function testReadPreferenceIsInherited()
     {
         $database = $this->getDatabase();
-        $database->setReadPreference(\MongoClient::RP_SECONDARY, ['a' => 'b']);
+        $database->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]);
 
         $collection = $database->selectCollection('test');
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => ['a' => 'b']], $collection->getReadPreference());
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => [['a' => 'b']]], $collection->getReadPreference());
     }
 
     public function testWriteConcern()
@@ -530,12 +539,20 @@ class MongoCollectionTest extends TestCase
 
         $collection->wtimeout = -1;
         $this->assertSame(['w' => 2, 'wtimeout' => 0], $collection->getWriteConcern());
+    }
+
+    public function testWriteConcernIsSetInDriver()
+    {
+        $this->skipTestIf(extension_loaded('mongo'));
+
+        $collection = $this->getCollection();
+        $this->assertTrue($collection->setWriteConcern(2, 100));
 
         // Only way to check whether options are passed down is through debugInfo
         $writeConcern = $collection->getCollection()->__debugInfo()['writeConcern'];
 
         $this->assertSame(2, $writeConcern->getW());
-        $this->assertSame(0, $writeConcern->getWtimeout());
+        $this->assertSame(100, $writeConcern->getWtimeout());
     }
 
     public function testWriteConcernIsInherited()

+ 4 - 2
tests/Alcaeus/MongoDbAdapter/MongoCursorTest.php

@@ -122,6 +122,8 @@ class MongoCursorTest extends TestCase
      */
     public function testCursorAppliesOptions($checkOptionCallback, \Closure $applyOptionCallback = null)
     {
+        $this->skipTestIf(extension_loaded('mongo'));
+
         $query = ['foo' => 'bar'];
         $projection = ['_id' => false, 'foo' => true];
 
@@ -320,10 +322,10 @@ class MongoCursorTest extends TestCase
     public function testReadPreferenceIsInherited()
     {
         $collection = $this->getCollection();
-        $collection->setReadPreference(\MongoClient::RP_SECONDARY, ['a' => 'b']);
+        $collection->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]);
 
         $cursor = $collection->find(['foo' => 'bar']);
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => ['a' => 'b']], $cursor->getReadPreference());
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => [['a' => 'b']]], $cursor->getReadPreference());
     }
 
     /**

+ 35 - 11
tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

@@ -121,30 +121,40 @@ class MongoDBTest extends TestCase
         $this->assertSame(['type' => \MongoClient::RP_PRIMARY], $database->getReadPreference());
         $this->assertFalse($database->getSlaveOkay());
 
-        $this->assertTrue($database->setReadPreference(\MongoClient::RP_SECONDARY, ['a' => 'b']));
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => ['a' => 'b']], $database->getReadPreference());
+        $this->assertTrue($database->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]));
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => [['a' => 'b']]], $database->getReadPreference());
         $this->assertTrue($database->getSlaveOkay());
 
-        // Only way to check whether options are passed down is through debugInfo
-        $writeConcern = $database->getDb()->__debugInfo()['readPreference'];
-
-        $this->assertSame(ReadPreference::RP_SECONDARY, $writeConcern->getMode());
-        $this->assertSame(['a' => 'b'], $writeConcern->getTagSets());
-
         $this->assertTrue($database->setSlaveOkay(true));
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY_PREFERRED, 'tagsets' => ['a' => 'b']], $database->getReadPreference());
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY_PREFERRED, 'tagsets' => [['a' => 'b']]], $database->getReadPreference());
 
         $this->assertTrue($database->setSlaveOkay(false));
         $this->assertSame(['type' => \MongoClient::RP_PRIMARY], $database->getReadPreference());
     }
 
+    public function testReadPreferenceIsSetInDriver()
+    {
+        $this->skipTestIf(extension_loaded('mongo'));
+
+        $database = $this->getDatabase();
+
+        $this->assertTrue($database->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]));
+
+        // Only way to check whether options are passed down is through debugInfo
+        $readPreference = $database->getDb()->__debugInfo()['readPreference'];
+
+        $this->assertSame(ReadPreference::RP_SECONDARY, $readPreference->getMode());
+        $this->assertSame(['a' => 'b'], $readPreference->getTagSets());
+
+    }
+
     public function testReadPreferenceIsInherited()
     {
         $client = $this->getClient();
-        $client->setReadPreference(\MongoClient::RP_SECONDARY, ['a' => 'b']);
+        $client->setReadPreference(\MongoClient::RP_SECONDARY, [['a' => 'b']]);
 
         $database = $client->selectDB('test');
-        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => ['a' => 'b']], $database->getReadPreference());
+        $this->assertSame(['type' => \MongoClient::RP_SECONDARY, 'tagsets' => [['a' => 'b']]], $database->getReadPreference());
     }
 
     public function testWriteConcern()
@@ -170,6 +180,20 @@ class MongoDBTest extends TestCase
         $this->assertSame(0, $writeConcern->getWtimeout());
     }
 
+    public function testWriteConcernIsSetInDriver()
+    {
+        $this->skipTestIf(extension_loaded('mongo'));
+
+        $database = $this->getDatabase();
+        $this->assertTrue($database->setWriteConcern(2, 100));
+
+        // Only way to check whether options are passed down is through debugInfo
+        $writeConcern = $database->getDb()->__debugInfo()['writeConcern'];
+
+        $this->assertSame(2, $writeConcern->getW());
+        $this->assertSame(100, $writeConcern->getWtimeout());
+    }
+
     public function testWriteConcernIsInherited()
     {
         $client = $this->getClient();

+ 3 - 1
tests/Alcaeus/MongoDbAdapter/MongoIdTest.php

@@ -43,8 +43,10 @@ class MongoIdTest extends TestCase
         new \MongoId('invalid');
     }
 
-    public function testCreateWithObjetId()
+    public function testCreateWithObjectId()
     {
+        $this->skipTestIf(extension_loaded('mongo'));
+
         $original = '54203e08d51d4a1f868b456e';
         $objectId = new \MongoDB\BSON\ObjectID($original);
 

+ 10 - 2
tests/Alcaeus/MongoDbAdapter/TestCase.php

@@ -147,11 +147,19 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
     }
 
     /**
-     * @param $condition
+     * @param bool $condition
      */
     protected function skipTestUnless($condition)
     {
-        if (!$condition) {
+        $this->skipTestIf(! $condition);
+    }
+
+    /**
+     * @param bool $condition
+     */
+    protected function skipTestIf($condition)
+    {
+        if ($condition) {
             $this->markTestSkipped('Test only applies when running against mongo-php-adapter');
         }
     }