Browse Source

Fix of absent formatAttributes method issue

Victor Pryazhnikov 4 năm trước cách đây
mục cha
commit
227343f20b
1 tập tin đã thay đổi với 16 bổ sung4 xóa
  1. 16 4
      tests/Monolog/Handler/DynamoDbHandlerTest.php

+ 16 - 4
tests/Monolog/Handler/DynamoDbHandlerTest.php

@@ -17,14 +17,27 @@ class DynamoDbHandlerTest extends TestCase
 {
     private $client;
 
+    private $isV3;
+
     public function setUp(): void
     {
         if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
             $this->markTestSkipped('aws/aws-sdk-php not installed');
         }
 
+        $this->isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
+
+        $implementedMethods = ['__call'];
+        $absentMethods = [];
+        if ($this->isV3) {
+            $absentMethods[] = 'formatAttributes';
+        } else {
+            $implementedMethods[] = 'formatAttributes';
+        }
+
         $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')
-            ->onlyMethods(['formatAttributes', '__call'])
+            ->onlyMethods($implementedMethods)
+            ->addMethods($absentMethods)
             ->disableOriginalConstructor()
             ->getMock();
     }
@@ -53,8 +66,7 @@ class DynamoDbHandlerTest extends TestCase
         $handler = new DynamoDbHandler($this->client, 'foo');
         $handler->setFormatter($formatter);
 
-        $isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
-        if ($isV3) {
+        if ($this->isV3) {
             $expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2));
         } else {
             $expFormatted = $formatted;
@@ -66,7 +78,7 @@ class DynamoDbHandlerTest extends TestCase
              ->with($record)
              ->will($this->returnValue($formatted));
         $this->client
-             ->expects($isV3 ? $this->never() : $this->once())
+             ->expects($this->isV3 ? $this->never() : $this->once())
              ->method('formatAttributes')
              ->with($this->isType('array'))
              ->will($this->returnValue($formatted));