contextMock = $this->getMockBuilder(Context::class) ->disableOriginalConstructor() ->getMock(); $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class) ->getMockForAbstractClass(); $this->dateTimeMock = $this->getMockBuilder(DateTime::class) ->disableOriginalConstructor() ->getMock(); $this->entityManagerMock = $this->getMockBuilder(EntityManager::class) ->disableOriginalConstructor() ->getMock(); $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class) ->disableOriginalConstructor() ->getMock(); $this->pageMock = $this->getMockBuilder(Page::class) ->disableOriginalConstructor() ->getMock(); $this->resourcesMock = $this->getMockBuilder(ResourceConnection::class) ->disableOriginalConstructor() ->getMock(); $this->contextMock->expects($this->once()) ->method('getResources') ->willReturn($this->resourcesMock); $this->model = (new ObjectManager($this))->getObject(PageResourceModel::class, [ 'context' => $this->contextMock, 'storeManager' => $this->storeManagerMock, 'dateTime' => $this->dateTimeMock, 'entityManager' => $this->entityManagerMock, 'metadataPool' => $this->metadataPoolMock, ]); } public function testSave() { $this->entityManagerMock->expects($this->once()) ->method('save') ->with($this->pageMock, []) ->willReturn(true); $this->assertInstanceOf(PageResourceModel::class, $this->model->save($this->pageMock)); } public function testBeforeSave() { $this->pageMock->expects($this->any()) ->method('getData') ->willReturnMap([ ['identifier', null, 'test'], ['custom_theme_from', null, null], ['custom_theme_to', null, '10/02/2016'], ]); $this->dateTimeMock->expects($this->once()) ->method('formatDate') ->with('10/02/2016') ->willReturn('10 Feb 2016'); $this->pageMock->expects($this->any()) ->method('setData') ->withConsecutive( ['custom_theme_from', null], ['custom_theme_to', '10 Feb 2016'] ); $this->model->beforeSave($this->pageMock); } }