Assume I have this test:
public function testStorage()
{
$collection = $this->getMockBuilder('MongoCollection')->disableOriginalConstructor()->getMock();
$collection->method('findOne')->will($this->returnValueMap([
[['_id' => 'aaa'], ['content'], 'ccc'],
]));
$this->assertEquals('ccc', $collection->findOne(['_id' => 'aaa'], ['content']));
}
When running unit test it says: Failed asserting that null matches expected 'ccc'. I couldn't figure out why. But if I switch to mock another function, let's say: find it should work.
public function testStorage()
{
$collection = $this->getMockBuilder('MongoCollection')->disableOriginalConstructor()->getMock();
$collection->method('find')->will($this->returnValueMap([
[['_id' => 'aaa'], ['content'], 'ccc'],
]));
$this->assertEquals('ccc', $collection->find(['_id' => 'aaa'], ['content']));
}
OK (1 test, 1 assertion)
I really appreciate your help! Thank you very much!