40 require_once(
"libs/composer/vendor/autoload.php");
41 require_once(
"./Services/ActiveRecord/Connector/class.arConnector.php");
42 require_once(
"./Services/ActiveRecord/Connector/class.arConnectorMap.php");
63 public function setUp(): void
66 $dic[Bucket::class] =
function (
$c) {
78 $a = $factory->createInstance(PlusJob::class);
80 $b = $factory->createInstance(PlusJob::class);
82 $c = $factory->createInstance(PlusJob::class);
89 $userInteraction = $factory->createInstance(DownloadInteger::class);
90 $userInteraction->setInput([
$c]);
92 $bucket->setTask($userInteraction);
100 public function testSave()
103 $bucketConnector = Mockery::namedMock(
"bucketConnectorMock", \arConnector::class);
105 $valueConnector = Mockery::namedMock(
"valueConnectorMock", \arConnector::class);
107 $taskConnector = Mockery::namedMock(
"taskConnectorMock", \arConnector::class);
109 $valueToTaskConnector = Mockery::namedMock(
"valueToTaskConnectorMock", \arConnector::class);
117 $bucketConnector->shouldReceive(
"nextID")->once()->andReturn(1);
118 $bucketConnector->shouldReceive(
"create")->once();
121 $bucketConnector->shouldReceive(
"affectedRows")->once()->andReturn(1);
122 $bucketConnector->shouldReceive(
"update")->once()->andReturn(
true);
125 for ($i = 0; $i < 4; $i++) {
127 $taskConnector->shouldReceive(
"affectedRows")->once()->andReturn(0);
128 $taskConnector->shouldReceive(
"nextID")->once()->andReturn(1);
129 $taskConnector->shouldReceive(
"create")->once();
132 $taskConnector->shouldReceive(
"affectedRows")->once()->andReturn(1);
133 $taskConnector->shouldReceive(
"update")->once();
137 $valueConnector->shouldReceive(
"affectedRows")->times(7)->andReturn(0);
138 $valueConnector->shouldReceive(
"nextID")->times(7)->andReturn(1);
139 $valueConnector->shouldReceive(
"create")->times(7);
142 $valueToTaskConnector->shouldReceive(
"affectedRows")->times(7)->andReturn(0);
143 $valueToTaskConnector->shouldReceive(
"nextID")->times(7)->andReturn(1);
144 $valueToTaskConnector->shouldReceive(
"create")->times(7);
146 $this->persistence->setConnector($bucketConnector);
147 $this->persistence->saveBucketAndItsTasks($this->bucket);
153 $this->expectException(SerializationException::class);
155 $this->persistence->updateBucket($this->bucket);
158 public function testUpdateObserver()
163 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
168 $observerConnector->shouldReceive(
"read")->once()->andReturn([1 =>
new BucketContainer()]);
169 $observerConnector->shouldReceive(
"update")->once()->andReturn(
true);
171 $this->persistence->setConnector($observerConnector);
172 $this->persistence->updateBucket($this->bucket);
175 public function testGetObserverIdsOfUser()
178 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
181 $observerConnector->shouldReceive(
"readSet")->once()->andReturn([[
"id" => 2], [
"id" => 3]]);
183 $this->persistence->setConnector($observerConnector);
184 $observer_ids = $this->persistence->getBucketIdsOfUser(5);
185 $this->assertEquals($observer_ids, [0 => 2, 1 => 3]);
188 public function testGetObserverIdsByState()
191 $observerConnector = Mockery::namedMock(
"observerConnectorMock", \arConnector::class);
194 $observerConnector->shouldReceive(
"readSet")->once()->andReturn([[
"id" => 2], [
"id" => 3]]);
196 $this->persistence->setConnector($observerConnector);
197 $observer_ids = $this->persistence->getBucketIdsByState(
State::RUNNING);
198 $this->assertEquals($observer_ids, [2 => 2, 3 => 3]);
202 public function testUserInteraction()
204 $this->expectException(UserInteractionRequiredException::class);
208 $taskManager->executeTask($this->bucket->getTask(),
new MockObserver());
211 public function testContinueUserInteraction()
224 self::assertEquals($this->bucket->getCurrentTask()->getType(), $download_integer->getType());
226 $options = $download_integer->getOptions([]);
228 $dismiss = $download_integer->getRemoveOption();
230 $this->bucket->userInteraction($dismiss);
236 public function testContinueUserInteraction2()
242 $c = $this->bucket->getTask();
244 $x = $factory->createInstance(PlusJob::class);
246 $x->setInput([
$c, 1]);
249 $this->bucket->setTask($x);
262 self::assertEquals($this->bucket->getCurrentTask()->getType(), $download_integer->getType());
264 $options = $download_integer->getOptions([]);
266 $dismiss = $download_integer->getRemoveOption();
268 $this->bucket->userInteraction($dismiss);
272 $result = $taskManager->executeTask($this->bucket->getTask(),
new NonPersistingObserver($this->bucket));
273 self::assertEquals(5, $result->getValue());
static instance(\ilDBInterface $db)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testCannotUpdateUnknownBucket()
static register(ActiveRecord $activeRecord, arConnector $arConnector)
Customizing of pimple-DIC for ILIAS.
Class NonPersistingObserver.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
Class BackgroundTaskTest.