ILIAS  release_7 Revision v7.30-3-g800a261c036
TaskTest.php
Go to the documentation of this file.
1<?php
2
5use ILIAS\BackgroundTasks\Implementation\Bucket\BucketMock;
19use PHPUnit\Framework\TestCase;
20
21require_once("libs/composer/vendor/autoload.php");
22
33class TaskTest extends TestCase
34{
35 public function testPlusTask()
36 {
37 $dic = new Container();
38
40
41 $a = new IntegerValue();
42 $a->setValue(1);
43 $b = new IntegerValue();
44 $b->setValue(2);
45 $c = new IntegerValue();
46 $c->setValue(3);
47
49 $t1 = $factory->createInstance(PlusJob::class);
50 $t1->setInput([$a, $b]);
51
53 $t2 = $factory->createInstance(PlusJob::class);
54 $t2->setInput([$t1, $c]);
55
56 $this->assertTrue($t2->getOutputType()->equals(new SingleType(IntegerValue::class)));
57
58 $taskManager = new \ILIAS\BackgroundTasks\Implementation\TaskManager\SyncTaskManager(Mockery::mock(Persistence::class));
60 $finalValue = $taskManager->executeTask($t2, new MockObserver());
61 $this->assertEquals($finalValue->getValue(), 6);
62 }
63
64 public function testValueWrapper()
65 {
66 $dic = new Container();
67 $dic[Bucket::class] = function ($c) {
68 return new BucketMock();
69 };
71
72 $t = $factory->createInstance(PlusJob::class);
73 $t->setInput([1, 4]);
74
75 $taskManager = new \ILIAS\BackgroundTasks\Implementation\TaskManager\SyncTaskManager(Mockery::mock(Persistence::class));
77 $finalValue = $taskManager->executeTask($t, new MockObserver());
78 $this->assertEquals($finalValue->getValue(), 5);
79 }
80
81 public function testTypeCheck()
82 {
83 $this->expectException(InvalidArgumentException::class);
84
85 $dic = new Container();
86 $dic[Bucket::class] = function ($c) {
87 return new BucketMock();
88 };
90
91 $a = new IntegerValue(1);
92 $b = new StringValue("hello");
93
95 $t1 = $factory->createInstance(PlusJob::class);
96 $t1->setInput([$a, $b]);
97 }
98
99 public function testAggregation()
100 {
101 $dic = new Container();
103
104 $list = new ListValue();
105 $list->setValue([1, "hello", 3.0]);
106
108 $t1 = $factory->createInstance(ConcatenationJob::class);
109 $t1->setInput([$list]);
110
111 $output = $t1->run([$list], new MockObserver());
112 $this->assertEquals($output->getValue(), "1, hello, 3");
113 }
114
115 public function testUnfoldTask()
116 {
117 $dic = new Container();
118 $dic[Bucket::class] = function ($c) {
119 return new BasicBucket();
120 };
121
123
127 $t0 = $factory->createInstance(PlusJob::class);
128 $t0->setInput([1, 1]);
129
131 $t1 = $factory->createInstance(PlusJob::class);
132 $t1->setInput([$t0, 2]);
133
135 $t25 = $factory->createInstance(PlusJob::class);
136 $t25->setInput([2, 2]);
137
139 $t2 = $factory->createInstance(PlusJob::class);
140 $t2->setInput([$t1, $t25]);
141
142 $this->assertTrue($t2->getOutputType()->equals(new SingleType(IntegerValue::class)));
143
144 $list = $t2->unfoldTask();
145 $this->assertEquals($list, [$t2, $t1, $t0, $t25]);
146
148 $taskManager = new \ILIAS\BackgroundTasks\Implementation\TaskManager\SyncTaskManager(Mockery::mock(Persistence::class));
150 $finalValue = $taskManager->executeTask($t2, new MockObserver());
151 $this->assertEquals($finalValue->getValue(), 8);
152 }
153}
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:19
Class BackgroundTaskTest.
Definition: TaskTest.php:34
$c
Definition: cli.php:37
$factory
Definition: metadata.php:58
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
$dic
Definition: result.php:13