Skip to content

Commit

Permalink
fix(test): replace setMethods (deprecated) with onlyMethods and add a…
Browse files Browse the repository at this point in the history
… new DynamoDbClientMock class to declare the needed methods (otherwise onlyMethods would not work)
  • Loading branch information
Claudio La Barbera committed Apr 2, 2024
1 parent 43bcfc6 commit f55d66c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/DynamoDb/DynamoDbManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BaoPham\DynamoDb\DynamoDbClientInterface;
use BaoPham\DynamoDb\Tests\DynamoDbTestCase;
use BaoPham\DynamoDb\DynamoDb\DynamoDbManager;
use BaoPham\DynamoDb\Tests\Mocks\DynamoDbClientMock;

class DynamoDbManagerTest extends DynamoDbTestCase
{
Expand All @@ -25,9 +26,9 @@ public function setUp(): void
parent::setUp();

$this->mockedClient = $this
->getMockBuilder(DynamoDbClient::class)
->getMockBuilder(DynamoDbClientMock::class)
->disableOriginalConstructor()
->setMethods(['putItem', 'updateItem', 'deleteItem', 'scan', 'query', 'batchWriteItem'])
->onlyMethods(['putItem', 'updateItem', 'deleteItem', 'scan', 'query', 'batchWriteItem'])
->getMock();

$service = $this->getMockBuilder(DynamoDbClientInterface::class)->getMock();
Expand Down
33 changes: 33 additions & 0 deletions tests/Mocks/DynamoDbClientMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace BaoPham\DynamoDb\Tests\Mocks;

use Aws\DynamoDb\DynamoDbClient;
use Aws\Result;

class DynamoDbClientMock extends DynamoDbClient
{
public function putItem(array $args = []): Result {
return parent::putItem($args);
}

public function updateItem(array $args = []): Result {
return parent::updateItem($args);
}

public function deleteItem(array $args = []): Result {
return parent::deleteItem($args);
}

public function scan(array $args = []): Result {
return parent::scan($args);
}

public function query(array $args = []): Result {
return parent::query($args);
}

public function batchWriteItem(array $args = []): Result {
return parent::batchWriteItem($args);
}
}

0 comments on commit f55d66c

Please sign in to comment.