ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
AddLabelTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Stefan Hecken <stefan.hecken@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
6use PHPUnit\Framework\TestCase;
7
13class AddLabelTest extends TestCase
14{
15 protected static $labels = array("A", "B", "C");
16 protected static $test_array = array(1, 2, 3);
17 protected static $result_array = array("A" => 1, "B" => 2, "C" => 3);
21 private $f;
22
23 protected function setUp() : void
24 {
25 $dataFactory = new ILIAS\Data\Factory();
26 $language = $this->createMock('\ilLanguage');
27
28 $this->f = new ILIAS\Refinery\Factory($dataFactory, $language);
29 $this->add_label = $this->f->container()->addLabels(self::$labels);
30 }
31
32 protected function tearDown() : void
33 {
34 $this->f = null;
35 $this->add_label = null;
36 }
37
38 public function testTransform()
39 {
40 $with = $this->add_label->transform(self::$test_array);
41 $this->assertEquals(self::$result_array, $with);
42 }
43
44 public function testTransformFails()
45 {
46 $raised = false;
47 try {
48 $with = null;
49 $next_with = $this->add_label->transform($with);
50 } catch (InvalidArgumentException $e) {
51 $raised = true;
52 }
53 $this->assertTrue($raised);
54
55 $raised = false;
56 try {
57 $without = array(1, 2, 3, 4);
58 $with = $this->add_label->transform($without);
59 } catch (InvalidArgumentException $e) {
60 $raised = true;
61 }
62 $this->assertTrue($raised);
63
64 $raised = false;
65 try {
66 $without = "1, 2, 3";
67 $with = $this->add_label->transform($without);
68 } catch (InvalidArgumentException $e) {
69 $raised = true;
70 }
71 $this->assertTrue($raised);
72
73 $raised = false;
74 try {
75 $std_class = new stdClass();
76 $with = $this->add_label->transform($std_class);
77 } catch (InvalidArgumentException $e) {
78 $raised = true;
79 }
80 $this->assertTrue($raised);
81 }
82
83 public function testInvoke()
84 {
85 $add_label = $this->f->container()->addLabels(self::$labels);
86 $with = $add_label(self::$test_array);
87 $this->assertEquals(self::$result_array, $with);
88 }
89
90 public function testInvokeFails()
91 {
92 $add_label = $this->f->container()->addLabels(self::$labels);
93
94 $raised = false;
95 try {
96 $with = null;
97 $next_with = $add_label($with);
98 } catch (InvalidArgumentException $e) {
99 $raised = true;
100 }
101 $this->assertTrue($raised);
102
103 $raised = false;
104 try {
105 $without = array(1, 2, 3, 4);
106 $with = $add_label($without);
107 } catch (InvalidArgumentException $e) {
108 $raised = true;
109 }
110 $this->assertTrue($raised);
111
112 $raised = false;
113 try {
114 $without = "1, 2, 3";
115 $with = $add_label($without);
116 } catch (InvalidArgumentException $e) {
117 $raised = true;
118 }
119 $this->assertTrue($raised);
120
121 $raised = false;
122 try {
123 $std_class = new stdClass();
124 $with = $add_label($std_class);
125 } catch (InvalidArgumentException $e) {
126 $raised = true;
127 }
128 $this->assertTrue($raised);
129 }
130}
TestCase for AddLabel transformations.
static $labels
static $test_array
static $result_array
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20