| 24 | use Psr\Log\LoggerInterface; |
| 25 | |
| 26 | class DatasetServiceTest extends TestCase { |
| 27 | protected function tearDown(): void { |
| 28 | $this->setContextChatAvailable(null); |
| 29 | if (class_exists('\OC')) { |
| 30 | \OC::$server = null; |
| 31 | } |
| 32 | parent::tearDown(); |
| 33 | } |
| 34 | |
| 35 | public function testProviderKeepsDatasetUpdateSuccessfulWhenContextChatFails(): void { |
| 36 | if (!class_exists('\OC')) { |
| 37 | eval('class OC { public static $server; }'); |
| 38 | } |
| 39 | |
| 40 | $contextChatManager = new class() { |
| 41 | public function submitContent(int $datasetId): void { |
| 42 | throw new \InvalidArgumentException('Entity which should be updated has no id'); |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | \OC::$server = new class($contextChatManager) { |
| 47 | private $contextChatManager; |
| 48 | |
| 49 | public function __construct($contextChatManager) { |
| 50 | $this->contextChatManager = $contextChatManager; |
| 51 | } |
| 52 | |
| 53 | public function query(string $class) { |
| 54 | return $this->contextChatManager; |
| 55 | } |
| 56 | }; |
| 57 | |
| 58 | $logger = $this->createMock(LoggerInterface::class); |
| 59 | $logger->expects($this->once()) |
| 60 | ->method('warning') |
| 61 | ->with( |
| 62 | 'Analytics context chat indexing failed', |
| 63 | $this->callback(function (array $context): bool { |
| 64 | $this->assertSame(11, $context['datasetId']); |
| 65 | $this->assertInstanceOf(\InvalidArgumentException::class, $context['exception']); |
| 66 | return true; |
| 67 | }) |
| 68 | ); |
| 69 | |
| 70 | $this->setContextChatAvailable(true); |
| 71 | |
| 72 | $service = $this->createService($logger); |
| 73 | |
| 74 | $this->assertTrue($service->provider(11)); |
| 75 | } |
| 76 | |
| 77 | public function testUpdateRejectsForeignDatasetBeforeSideEffects(): void { |
| 78 | $datasetMapper = $this->createMock(DatasetMapper::class); |
| 79 | $datasetMapper->expects($this->once())->method('readOwn')->with(77)->willReturn(false); |
| 80 | $datasetMapper->expects($this->never())->method('update'); |
| 81 | $reportMapper = $this->createMock(ReportMapper::class); |
| 82 | $reportMapper->expects($this->never())->method('increaseVersionByDataset'); |
| 83 |
nothing calls this directly
no outgoing calls
no test coverage detected