logger = $this->createMock(LoggerInterface::class); $this->backend = $this->createMock(CalDavBackend::class); $this->output = $this->createMock(IOutput::class); } public function testRunAllValid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ \OC::$server->getDatabaseConnection(), $this->backend, $this->logger ]) ->setMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) ->method('getInvalidObjects') ->willReturn([]); $this->output->expects($this->once()) ->method('startProgress') ->with(0); $this->output->expects($this->once()) ->method('finishProgress'); $step->run($this->output); } public function testRunInvalid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ \OC::$server->getDatabaseConnection(), $this->backend, $this->logger ]) ->setMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) ->method('getInvalidObjects') ->willReturn([ ['calendarid' => '42', 'uri' => 'myuri'], ]); $this->output->expects($this->once()) ->method('startProgress') ->with(1); $this->output->expects($this->once()) ->method('finishProgress'); $this->backend->expects($this->exactly(1)) ->method('getCalendarObject') ->with(42, 'myuri') ->willReturn([ 'calendardata' => $this->invalid ]); $this->output->expects($this->exactly(1)) ->method('advance'); $this->backend->expects($this->exactly(1)) ->method('getDenormalizedData') ->with($this->valid); $this->backend->expects($this->exactly(1)) ->method('updateCalendarObject') ->with(42, 'myuri', $this->valid); $step->run($this->output); } public function testRunValid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ \OC::$server->getDatabaseConnection(), $this->backend, $this->logger ]) ->setMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) ->method('getInvalidObjects') ->willReturn([ ['calendarid' => '42', 'uri' => 'myuri'], ]); $this->output->expects($this->once()) ->method('startProgress') ->with(1); $this->output->expects($this->once()) ->method('finishProgress'); $this->backend->expects($this->exactly(1)) ->method('getCalendarObject') ->with(42, 'myuri') ->willReturn([ 'calendardata' => $this->valid ]); $this->output->expects($this->never()) ->method('advance'); $this->backend->expects($this->never()) ->method('getDenormalizedData'); $this->backend->expects($this->never()) ->method('updateCalendarObject'); $step->run($this->output); } public function testRunStillInvalid(): void { /** @var CalDAVRemoveEmptyValue|\PHPUnit\Framework\MockObject\MockObject $step */ $step = $this->getMockBuilder(CalDAVRemoveEmptyValue::class) ->setConstructorArgs([ \OC::$server->getDatabaseConnection(), $this->backend, $this->logger ]) ->setMethods(['getInvalidObjects']) ->getMock(); $step->expects($this->once()) ->method('getInvalidObjects') ->willReturn([ ['calendarid' => '42', 'uri' => 'myuri'], ]); $this->output->expects($this->once()) ->method('startProgress') ->with(1); $this->output->expects($this->once()) ->method('finishProgress'); $this->backend->expects($this->exactly(1)) ->method('getCalendarObject') ->with(42, 'myuri') ->willReturn([ 'calendardata' => $this->invalid ]); $this->output->expects($this->exactly(1)) ->method('advance'); $this->backend->expects($this->exactly(1)) ->method('getDenormalizedData') ->with($this->valid) ->willThrowException(new InvalidDataException()); $this->backend->expects($this->never()) ->method('updateCalendarObject'); $step->run($this->output); } }