I'm doing some unit testing on a project that uses the AWS Laravel SDK.
I'm trying to use Mockery with the Aws
facade, and it works fine for the first test, then fails for all other tests:
public function testCreateS3Adaptor() {
\Aws::shouldReceive('createClient')->with('s3', $this->s3config)->andReturn(new S3Client());
// ... some tests
}
public function testPutFile() {
\Aws::shouldReceive('createClient')->with('s3', $this->s3config)->andReturn(new S3Client());
// ... some tests
}
public function testFetchFile() {
\Aws::shouldReceive('createClient')->with('s3', $this->s3config)->andReturn(new S3Client());
// ... some tests
}
public function testDeleteFile() {
\Aws::shouldReceive('createClient')->with('s3', $this->s3config)->andReturn(new S3Client());
// ... some tests
}
When running the tests:
.EEE
Time: 1.11 seconds, Memory: 31.25Mb
There were 3 errors:
1) S3AdaptorTest::testPutFile
BadMethodCallException: Unknown method: shouldRecieve.
/var/www/vhosts/laravel/storage-handler/vendor/aws/aws-sdk-php/src/Sdk.php:88
/var/www/vhosts/laravel/storage-handler/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/var/www/vhosts/laravel/storage-handler/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/var/www/vhosts/laravel/storage-handler/tests/S3AdaptorTest.php:39
/var/www/vhosts/laravel/storage-handler/tests/S3AdaptorTest.php:39
2) S3AdaptorTest::testFetchFile
BadMethodCallException: Unknown method: shouldRecieve.
/var/www/vhosts/laravel/storage-handler/vendor/aws/aws-sdk-php/src/Sdk.php:88
/var/www/vhosts/laravel/storage-handler/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/var/www/vhosts/laravel/storage-handler/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/var/www/vhosts/laravel/storage-handler/tests/S3AdaptorTest.php:53
/var/www/vhosts/laravel/storage-handler/tests/S3AdaptorTest.php:53
3) S3AdaptorTest::testDeleteFile
BadMethodCallException: Unknown method: shouldRecieve.
/var/www/vhosts/laravel/storage-handler/vendor/aws/aws-sdk-php/src/Sdk.php:88
/var/www/vhosts/laravel/storage-handler/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/var/www/vhosts/laravel/storage-handler/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:210
/var/www/vhosts/laravel/storage-handler/tests/S3AdaptorTest.php:63
/var/www/vhosts/laravel/storage-handler/tests/S3AdaptorTest.php:63
Now my best guess here is that (somehow) the __call
method in the AWS SDK (i.e. the thing that the Facade wraps) is overwriting the __call
method in the Facade.
This is the __call
method in the AWS SDK:
public function __call($name, array $args)
{
if (strpos($name, 'create') === 0) {
return $this->createClient(
substr($name, 6),
isset($args[0]) ? $args[0] : []
);
}
throw new \BadMethodCallException("Unknown method: {$name}.");
}
Is there any way to get around this without having to rewrite parts of mockery or the AWS Laravel library?
Aucun commentaire:
Enregistrer un commentaire