Unit Testing Aerospike Functions

Hi.

I’m just wondering the best way to be able to mock Aerospike functions for testing within my services. As an example, I can easily create a mockAerospike() service which I can inject into my service, but when running the mock methods and telling it to return something it’s running into issues.

This is an example of using the mock Aerospike functionality:

// Declare the mock:
$this->mockAerospike = $this->getMockBuilder('Aerospike')
            ->disableOriginalConstructor()
            ->setMethods(['isConnected', 'get', 'put', 'exists'])
            ->getMock();

// Use it in a function:
$this->mockAerospike->expects($this->once())
            ->method('get')
            ->with($key, $record, null, $options)
            ->willReturn(Aerospike::OK);

This is all firing fine, but how do I effectively return some data from this get function in order to be able to run the tests in my application?

I know I’m in danger of muddying the waters here, but I guess it’s the functionality of the get() function which causes the issue. I suppose a better way of explaining it would be that the get() function should either return an error code (if the request was not successful) or return the data array as requested. This way you can basically check that if the response is not an array - something must have gone wrong so check the error code and act accordingly.

If you agree with this, let me know and I can think about it as a feature request @rbotzer - I understand this will massively break the BC of the Aerospike client