Mongolid\ActiveRecordTest::testShouldGetFirstOrNewAndReturnExistingModel PHP Method

testShouldGetFirstOrNewAndReturnExistingModel() public method

    public function testShouldGetFirstOrNewAndReturnExistingModel()
    {
        // Arrage
        $entity = m::mock(ActiveRecord::class . '[getDataMapper]');
        $this->setProtected($entity, 'collection', 'mongolid');
        $id = 123;
        $dataMapper = m::mock();
        // Act
        Ioc::instance(get_class($entity), $entity);
        $entity->shouldReceive('getDataMapper')->andReturn($dataMapper);
        $dataMapper->shouldReceive('first')->once()->with($id)->andReturn($entity);
        // Assert
        $this->assertEquals($entity, $entity->firstOrNew($id));
    }