ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
TransformationsCustomTest Class Reference

TestCase for Custom transformations. More...

+ Inheritance diagram for TransformationsCustomTest:
+ Collaboration diagram for TransformationsCustomTest:

Public Member Functions

 testTransform ()
 
 testTransformFails ()
 
 testInvoke ()
 
 testInvokeFails ()
 
 testApplyToWithValidValueReturnsAnOkResult ()
 

Data Fields

const TEST_STRING = "Test"
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Private Attributes

 $custom
 
 $f
 

Detailed Description

Member Function Documentation

◆ setUp()

TransformationsCustomTest::setUp ( )
protected

Definition at line 27 of file TransformationsCustomTest.php.

27  : void
28  {
29  $language = $this->createMock(\ilLanguage::class);
30  $this->f = new Factory(new ILIAS\Data\Factory(), $language);
31 
32  $this->custom = $this->f->custom()->transformation(
33  function ($value) {
34  if (!is_string($value)) {
35  throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
36  }
37  return $value;
38  }
39  );
40  }
Class ChatMainBarProvider .

◆ tearDown()

TransformationsCustomTest::tearDown ( )
protected

Definition at line 42 of file TransformationsCustomTest.php.

42  : void
43  {
44  $this->f = null;
45  $this->custom = null;
46  }

◆ testApplyToWithValidValueReturnsAnOkResult()

TransformationsCustomTest::testApplyToWithValidValueReturnsAnOkResult ( )

Definition at line 140 of file TransformationsCustomTest.php.

References $factory.

141  {
142  $factory = new \ILIAS\Data\Factory();
143  $valueObject = $factory->ok(self::TEST_STRING);
144 
145  $resultObject = $this->custom->applyTo($valueObject);
146 
147  $this->assertEquals(self::TEST_STRING, $resultObject->value());
148  $this->assertFalse($resultObject->isError());
149  }
$factory
Definition: metadata.php:58

◆ testInvoke()

TransformationsCustomTest::testInvoke ( )

Definition at line 85 of file TransformationsCustomTest.php.

References $custom, and $result.

86  {
87  $custom = $this->f->custom()->transformation(
88  function ($value) {
89  if (!is_string($value)) {
90  throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
91  }
92  return $value;
93  }
94  );
95 
96  $result = $custom(self::TEST_STRING);
97  $this->assertEquals(self::TEST_STRING, $result);
98  }
$result

◆ testInvokeFails()

TransformationsCustomTest::testInvokeFails ( )

Definition at line 100 of file TransformationsCustomTest.php.

References $custom, and Vendor\Package\$e.

101  {
102  $custom = $this->f->custom()->transformation(
103  function ($value) {
104  if (!is_string($value)) {
105  throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
106  }
107  return $value;
108  }
109  );
110 
111  $raised = false;
112  try {
113  $lower_string = $custom(array());
114  } catch (InvalidArgumentException $e) {
115  $this->assertEquals("'array' is not a string.", $e->getMessage());
116  $raised = true;
117  }
118  $this->assertTrue($raised);
119 
120  $raised = false;
121  try {
122  $lower_string = $custom(12345);
123  } catch (InvalidArgumentException $e) {
124  $this->assertEquals("'integer' is not a string.", $e->getMessage());
125  $raised = true;
126  }
127  $this->assertTrue($raised);
128 
129  $raised = false;
130  try {
131  $std_class = new stdClass();
132  $lower_string = $custom($std_class);
133  } catch (InvalidArgumentException $e) {
134  $this->assertEquals("'object' is not a string.", $e->getMessage());
135  $raised = true;
136  }
137  $this->assertTrue($raised);
138  }

◆ testTransform()

TransformationsCustomTest::testTransform ( )

Definition at line 48 of file TransformationsCustomTest.php.

References $result.

49  {
50  $result = $this->custom->transform(self::TEST_STRING);
51  $this->assertEquals(self::TEST_STRING, $result);
52  }
$result

◆ testTransformFails()

TransformationsCustomTest::testTransformFails ( )

Definition at line 54 of file TransformationsCustomTest.php.

References Vendor\Package\$e.

55  {
56  $raised = false;
57  try {
58  $lower_string = $this->custom->transform(array());
59  } catch (InvalidArgumentException $e) {
60  $this->assertEquals("'array' is not a string.", $e->getMessage());
61  $raised = true;
62  }
63  $this->assertTrue($raised);
64 
65  $raised = false;
66  try {
67  $lower_string = $this->custom->transform(12345);
68  } catch (InvalidArgumentException $e) {
69  $this->assertEquals("'integer' is not a string.", $e->getMessage());
70  $raised = true;
71  }
72  $this->assertTrue($raised);
73 
74  $raised = false;
75  try {
76  $std_class = new stdClass();
77  $lower_string = $this->custom->transform($std_class);
78  } catch (InvalidArgumentException $e) {
79  $this->assertEquals("'object' is not a string.", $e->getMessage());
80  $raised = true;
81  }
82  $this->assertTrue($raised);
83  }

Field Documentation

◆ $custom

TransformationsCustomTest::$custom
private

Definition at line 20 of file TransformationsCustomTest.php.

Referenced by testInvoke(), and testInvokeFails().

◆ $f

TransformationsCustomTest::$f
private

Definition at line 25 of file TransformationsCustomTest.php.

◆ TEST_STRING

const TransformationsCustomTest::TEST_STRING = "Test"

Definition at line 15 of file TransformationsCustomTest.php.


The documentation for this class was generated from the following file: