maxxd Posted February 9 Share Posted February 9 (edited) 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 February 9 by maxxd Quote Link to comment https://forums.phpfreaks.com/topic/326751-mocking-aws-sdk-objects/ Share on other sites More sharing options...
requinix Posted February 9 Share Posted February 9 This post implies using their UsesServiceTrait to handle the mocking (well, faking of results) as seen in places like S3's MultipartUploaderTest. Quote Link to comment https://forums.phpfreaks.com/topic/326751-mocking-aws-sdk-objects/#findComment-1649278 Share on other sites More sharing options...
maxxd Posted February 9 Author Share Posted February 9 Saw that earlier but it's possible I wasn't in the mindset to read it completely - I'll take another look. Thanks much! Quote Link to comment https://forums.phpfreaks.com/topic/326751-mocking-aws-sdk-objects/#findComment-1649285 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.