Neos\Flow\Tests\Unit\Property\TypeConverter\PersistentObjectConverterTest::setupMockQuery PHP Method

setupMockQuery() public method

public setupMockQuery ( integer $numberOfResults, PHPUnit_Framework_MockObject_Matcher_Invocation $howOftenIsGetFirstCalled ) : stdClass
$numberOfResults integer
$howOftenIsGetFirstCalled PHPUnit_Framework_MockObject_Matcher_Invocation
return stdClass
    public function setupMockQuery($numberOfResults, $howOftenIsGetFirstCalled)
    {
        $mockClassSchema = $this->createMock(ClassSchema::class, [], ['Dummy']);
        $mockClassSchema->expects($this->once())->method('getIdentityProperties')->will($this->returnValue(['key1' => 'someType']));
        $this->mockReflectionService->expects($this->once())->method('getClassSchema')->with('SomeType')->will($this->returnValue($mockClassSchema));
        $mockConstraint = $this->getMockBuilder(Persistence\Generic\Qom\Comparison::class)->disableOriginalConstructor()->getMock();
        $mockObject = new \stdClass();
        $mockQuery = $this->createMock(Persistence\QueryInterface::class);
        $mockQueryResult = $this->createMock(Persistence\QueryResultInterface::class);
        $mockQueryResult->expects($this->once())->method('count')->will($this->returnValue($numberOfResults));
        $mockQueryResult->expects($howOftenIsGetFirstCalled)->method('getFirst')->will($this->returnValue($mockObject));
        $mockQuery->expects($this->once())->method('equals')->with('key1', 'value1')->will($this->returnValue($mockConstraint));
        $mockQuery->expects($this->once())->method('matching')->with($mockConstraint)->will($this->returnValue($mockQuery));
        $mockQuery->expects($this->once())->method('execute')->will($this->returnValue($mockQueryResult));
        $this->mockPersistenceManager->expects($this->once())->method('createQueryForType')->with('SomeType')->will($this->returnValue($mockQuery));
        return $mockObject;
    }