getMockBuilder(WebsiteAttributesSynchronizer::class) ->disableOriginalConstructor() ->setMethods([ 'isSynchronizationRequired', 'synchronize', ]) ->getMock(); $synchronizerMock->expects($this->once()) ->method('isSynchronizationRequired') ->will( $this->returnValue(true) ); $synchronizerMock->expects($this->once()) ->method('synchronize'); $cron = new SynchronizeWebsiteAttributes($synchronizerMock); $cron->execute(); } public function testExecuteWithNoSyncRequired() { $synchronizerMock = $this->getMockBuilder(WebsiteAttributesSynchronizer::class) ->disableOriginalConstructor() ->setMethods([ 'isSynchronizationRequired', 'synchronize', ]) ->getMock(); $synchronizerMock->expects($this->once()) ->method('isSynchronizationRequired') ->will( $this->returnValue(false) ); $synchronizerMock->expects($this->never()) ->method('synchronize'); $cron = new SynchronizeWebsiteAttributes($synchronizerMock); $cron->execute(); } }