taskLogMock = $this->createMock(TaskLogInterface::class); $serviceLocatorMock = $this->getServiceLocatorMock([ TaskLogInterface::SERVICE_ID => $this->taskLogMock, FileSystemService::SERVICE_ID => $this->createMock(FileSystemService::class), ]); $this->subject = new TaskLogUtility(); $this->subject->setServiceLocator($serviceLocatorMock); } public function testHelp() { $output = $this->subject->__invoke(['--help']); $this->assertInstanceOf(common_report_Report::class, $output); $this->assertEquals( "Examples 1. Stats Description: Return stats about the tasks logs statuses Example: sudo -u www-data php index.php 'oat\\taoTaskQueue\scripts\\tools\TaskLogUtility' --stats 2. List Task Logs Description: List All the tasks that are not archived will be retrived, default limit is 20 Example: sudo -u www-data php index.php 'oat\\taoTaskQueue\scripts\\tools\TaskLogUtility' --available --limit[optional]=20 --offset[optional]=10 3. Get Task Log Description: Get an specific task log by id Example: sudo -u www-data php index.php 'oat\\taoTaskQueue\scripts\\tools\TaskLogUtility' --get-task=[taskdId] 4. Archive a Task Log Description: Archive a task log Example: sudo -u www-data php index.php 'oat\\taoTaskQueue\scripts\\tools\TaskLogUtility' --archive=[taskdId] --force[optional] 5. Cancel a Task Log Description: Cancel a task log Example: sudo -u www-data php index.php 'oat\\taoTaskQueue\scripts\\tools\TaskLogUtility' --cancel=[taskdId] --force[optional]", $output->getMessage() ); } public function testGetStats() { $stats = new TasksLogsStats(1, 2, 3); $this->taskLogMock ->expects($this->once()) ->method('getStats') ->with(TaskLogInterface::SUPER_USER) ->willReturn($stats); $output = $this->subject->__invoke(['--stats']); $this->assertInstanceOf(common_report_Report::class, $output); $this->assertStringContainsString('"numberOfTasksCompleted": 1', $output->getMessage()); $this->assertStringContainsString('"numberOfTasksFailed": 2', $output->getMessage()); $this->assertStringContainsString('"numberOfTasksInProgress": 3', $output->getMessage()); } public function testFindAvailableByUser() { $collection = TaskLogCollection::createEmptyCollection(); $this->taskLogMock ->expects($this->once()) ->method('findAvailableByUser') ->with(TaskLogInterface::SUPER_USER, 10, 0) ->willReturn($collection); $output = $this->subject->__invoke(['--available', '--limit=10', '--offset=0']); $this->assertInstanceOf(common_report_Report::class, $output); $this->assertEquals('[]', $output->getMessage()); } public function testGetTask() { $taskLog = $this->createTakLogEntity('id', 'parentId', 'name', CategorizedStatus::created()); $this->taskLogMock ->expects($this->once()) ->method('getByIdAndUser') ->with('id', TaskLogInterface::SUPER_USER) ->willReturn($taskLog); $output = $this->subject->__invoke(['--get-task=id']); $this->assertInstanceOf(common_report_Report::class, $output); $this->assertStringContainsString('"id": "id"', $output->getMessage()); $this->assertStringContainsString('"taskName": "name"', $output->getMessage()); $this->assertStringContainsString('"status": "' . CategorizedStatus::created() . '"', $output->getMessage()); } public function testArchive() { $taskLog = $this->createTakLogEntity('id', 'parentId', 'name', CategorizedStatus::created()); $this->taskLogMock ->expects($this->once()) ->method('getByIdAndUser') ->with('id', TaskLogInterface::SUPER_USER) ->willReturn($taskLog); $this->taskLogMock ->expects($this->once()) ->method('archive') ->with($taskLog, true) ->willReturn(true); $output = $this->subject->__invoke(['--archive=id', '--force']); $this->assertInstanceOf(common_report_Report::class, $output); $this->assertEquals('Archived: 1', $output->getMessage()); } public function testCancel() { $taskLog = $this->createTakLogEntity('id', 'parentId', 'name', CategorizedStatus::created()); $this->taskLogMock ->expects($this->once()) ->method('getByIdAndUser') ->with('id', TaskLogInterface::SUPER_USER) ->willReturn($taskLog); $this->taskLogMock ->expects($this->once()) ->method('cancel') ->with($taskLog, true) ->willReturn(true); $output = $this->subject->__invoke(['--cancel=id', '--force']); $this->assertInstanceOf(common_report_Report::class, $output); $this->assertEquals('Cancelled: 1', $output->getMessage()); } /** * @param string $id * @param string $parentId * @param string $name * @param CategorizedStatus $status * @return TaskLogEntity */ private function createTakLogEntity($id, $parentId, $name, $status) { return new TaskLogEntity( $id, $parentId, $name, $status, [], 'label', 'owner' ); } }