19declare(strict_types=1);
31use PHPUnit\Framework\Attributes\DataProvider;
32use PHPUnit\Framework\MockObject\MockObject;
33use PHPUnit\Framework\TestCase;
42 protected function setUp(): void
47 $this->
logger = $this->createMock(ilLogger::class);
48 $logger_factory = $this->createMock(ilLoggerFactory::class);
49 $logger_factory->method(
'getComponentLogger')->willReturn($this->
logger);
50 $this->dic[
'ilLoggerFactory'] = $logger_factory;
52 $this->persistence = $this->createMock(Persistence::class);
55 $ini = $this->createMock(ilIniFile::class);
56 $ini->method(
'readVariable')->willReturn(
'5');
63 private function schedule(array ...$responses): void
65 $this->scheduled_queries = 0;
67 $this->persistence->method(
'getBucketIdsByState')->willReturnCallback(
68 function (
int $state) use ($responses, &$index): array {
69 if ($state === State::RUNNING) {
72 $this->scheduled_queries++;
83 $output_type = $this->createMock(Type::class);
84 $value_type = $this->createMock(Type::class);
85 $value_type->method(
'isExtensionOf')->willReturn(
true);
87 $value = $this->createMock(Value::class);
88 $value->method(
'getType')->willReturn($value_type);
90 $job = $this->createMock(Job::class);
91 $job->method(
'getInput')->willReturn([]);
92 $job->method(
'getOutputType')->willReturn($output_type);
93 $job->method(
'run')->willReturn($value);
95 $bucket = $this->createMock(Bucket::class);
96 $bucket->method(
'getTask')->willReturn($job);
112 'missing task container' => [
'The requested task with container id 5 could not be found in the database.'],
113 'missing value container' => [
'The requested value with container id 9 could not be found in the database.'],
117 #[DataProvider('corruptContainerProvider')]
123 $bucket->method(
'setState')->willReturnCallback(
function (
int $state) use (&$finished):
void {
124 if ($state === State::FINISHED) {
129 $this->persistence->method(
'loadBucket')->willReturnCallback(
138 $this->persistence->expects($this->once())->method(
'deleteBucketById')->with(1);
139 $this->persistence->expects($this->atLeastOnce())->method(
'updateBucket')->with($bucket);
143 $this->assertTrue($finished);
144 $this->assertSame(2, $this->scheduled_queries);
151 $this->persistence->method(
'loadBucket')->willReturnCallback(
152 function (
int $id) use (&$loaded):
Bucket {
157 $this->persistence->expects($this->never())->method(
'deleteBucketById');
158 $this->
logger->expects($this->once())->method(
'error');
162 $this->assertSame([1], $loaded);
170 $this->persistence->method(
'loadBucket')->willReturnCallback(
171 function (
int $id) use ($bucket, &$loaded):
Bucket {
180 $this->persistence->expects($this->never())->method(
'deleteBucketById');
181 $this->persistence->expects($this->atLeastOnce())->method(
'updateBucket')->with($bucket);
185 $this->assertSame([1, 2], $loaded);
194 $this->persistence->method(
'loadBucket')->willReturnCallback(
195 function (
int $id) use ($bucket, &$loaded):
Bucket {
197 if (
$id === 1 ||
$id === 2) {
204 $this->persistence->method(
'deleteBucketById')->willReturnCallback(
205 function (
int $id) use (&$deleted):
void {
212 $this->assertSame([1, 2, 3], $loaded);
213 $this->assertSame([1, 2], $deleted);
214 $this->assertSame(2, $this->scheduled_queries);
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
testDatabaseErrorStopsWorkerWithoutDeleting()
testCorruptContainerDeletesBucketAndRunsNext(string $message)
testMissingBucketIsSkippedWithoutDeleteAndNextRuns()
MockObject &Persistence $persistence
static corruptContainerProvider()
schedule(array ... $responses)
MockObject &ilLogger $logger
testCorruptBucketsDoNotReloadTheScheduledList()
Customizing of pimple-DIC for ILIAS.
Class ilDatabaseException.
Component logger with individual log levels by component id.