/** * @covers ::finish */ public function testFinishShouldMailResults() { $historyId = 1; $settings = array('user' => 1, 'history' => $historyId, 'email' => true, 'rows' => 1); $mockImportHistoryService = $this->getMock('Craft\\Import_HistoryService'); $mockImportHistoryService->expects($this->any())->method('end')->with($historyId, ImportModel::StatusFinished); $this->setComponent(craft(), 'import_history', $mockImportHistoryService); $mockEmailService = $this->getMock('Craft\\EmailService'); $mockEmailService->expects($this->exactly(1))->method('sendEmail')->with($this->isInstanceOf('Craft\\EmailModel')); $this->setComponent(craft(), 'email', $mockEmailService); $mockTwigEnvironment = $this->getMockBuilder('Craft\\TwigEnvironment')->disableOriginalConstructor()->getMock(); $mockTemplatesService = $this->getMock('Craft\\TemplatesService'); $mockTemplatesService->expects($this->exactly(1))->method('render')->willReturn('renderedtemplate'); $mockTemplatesService->expects($this->exactly(1))->method('getTwig')->willReturn($mockTwigEnvironment); $this->setComponent(craft(), 'templates', $mockTemplatesService); $mockUser = $this->getMockUser(); $this->setMockUsersService($mockUser); $service = new ImportService(); $service->log = array(1 => 'Error message'); $service->finish($settings, false); }