ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
TaskTest.php
Go to the documentation of this file.
1 <?php
2 
20 
21 require_once("libs/composer/vendor/autoload.php");
22 
33 class TaskTest extends TestCase
34 {
35  public function testPlusTask()
36  {
37  $dic = new Container();
38 
39  $factory = new Injector($dic, new BaseDependencyMap());
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 BasicTaskManager(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  };
70  $factory = new Injector($dic, new BaseDependencyMap());
71 
72  $t = $factory->createInstance(PlusJob::class);
73  $t->setInput([1, 4]);
74 
75  $taskManager = new BasicTaskManager(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  };
89  $factory = new Injector($dic, new BaseDependencyMap());
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();
102  $factory = new Injector($dic, new BaseDependencyMap());
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 
122  $factory = new Injector($dic, new BaseDependencyMap());
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 BasicTaskManager(Mockery::mock(Persistence::class));
150  $finalValue = $taskManager->executeTask($t2, new MockObserver());
151  $this->assertEquals($finalValue->getValue(), 8);
152  }
153 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
$factory
Definition: metadata.php:47
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:15
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
Class BackgroundTaskTest.
Definition: TaskTest.php:33