Jump to content

Recommended Posts

I have a method that is trying to recognize legitimate names from data submitted by the user. I've got an array of obscene words, an array of bullshit words I've seen in past submissions, an array of just random strings that I've culled over time that I check against. I'm looking now at using AWS Comprehend DetectEntities as a last resort and it works - I hate to admit this - very well. The problem is that there is a phpunit group of tests that passed before the new code needed the actual AWS Comprehend call credentials to test.

I'm having issues mocking the ComprehendClient object.

$c = $this->getMockBuilder(ComprehendClient::class)
	->setConstructorArgs([
		'args' => [],
	])
	->addMethods(['detectEntities'])
	->getMock();
$c->expects(self::once())
	->method('detectEntities')
	->with([
		'LanguageCode' => 'en',
		'Text' => 'string'
	])
	->willReturn(true);

$this->assertTrue(ComprehendController::validateName('Bob'));

returns

 The service "ockobject_comprehendclient_a8" is not provided by the AWS SDK for PHP.

And

$cce = new class extends ComprehendClient {
	public function __construct(){
		parent::__construct([
			'credentials' => [],
			'region' => 'us-west-2',
			'version' => 'latest'
		]);
	}
	public function detectEntities($args = [])
	{
		return true;
	}
};
$c = $this->getMockBuilder($cce::class)
	->setConstructorArgs([
		'args' => [],
	])
	->setMockClassName(ComprehendClient::class)
	->addMethods(['detectEntities'])
	->getMock();
$c->expects(self::once())
	->method('detectEntities')
	->with([
		'LanguageCode' => 'en',
		'Text' => 'string'
	])
	->willReturn(true);

$this->assertTrue(ComprehendController::validateName('Bob'));

returns

The service "comprehendclient@anonymous\/home/my-dir/project/tests/unit/testcomprehend.php" is not provided by the AWS SDK for PHP.

Can anyone point me to a decent tutorial on how the hell to mock an aws object in phpunit? It's kinda driving me nuts...

Edited by maxxd
Link to comment
https://forums.phpfreaks.com/topic/326751-mocking-aws-sdk-objects/
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.