ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TransformationsCustomTest Class Reference

TestCase for Custom transformations. More...

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

Public Member Functions

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

Data Fields

const TEST_STRING = "Test"
 

Protected Member Functions

 setUp ()
 
 tearDown ()
 

Detailed Description

Member Function Documentation

◆ setUp()

TransformationsCustomTest::setUp ( )
protected

Definition at line 16 of file TransformationsCustomTest.php.

17 {
18 $this->f = new Transformation\Factory();
19 $this->custom = $this->f->custom(
20 function ($value) {
21 if (!is_string($value)) {
22 throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
23 }
24 return $value;
25 }
26 );
27 }

◆ tearDown()

TransformationsCustomTest::tearDown ( )
protected

Definition at line 29 of file TransformationsCustomTest.php.

30 {
31 $this->f = null;
32 $this->custom = null;
33 }

◆ testInvoke()

TransformationsCustomTest::testInvoke ( )

Definition at line 72 of file TransformationsCustomTest.php.

73 {
74 $custom = $this->f->custom(
75 function ($value) {
76 if (!is_string($value)) {
77 throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
78 }
79 return $value;
80 }
81 );
82
83 $result = $custom(self::TEST_STRING);
84 $this->assertEquals(self::TEST_STRING, $result);
85 }
$result

References $result.

◆ testInvokeFails()

TransformationsCustomTest::testInvokeFails ( )

Definition at line 87 of file TransformationsCustomTest.php.

88 {
89 $custom = $this->f->custom(
90 function ($value) {
91 if (!is_string($value)) {
92 throw new InvalidArgumentException("'" . gettype($value) . "' is not a string.");
93 }
94 return $value;
95 }
96 );
97
98 $raised = false;
99 try {
100 $lower_string = $custom(array());
101 } catch (InvalidArgumentException $e) {
102 $this->assertEquals("'array' is not a string.", $e->getMessage());
103 $raised = true;
104 }
105 $this->assertTrue($raised);
106
107 $raised = false;
108 try {
109 $lower_string = $custom(12345);
110 } catch (InvalidArgumentException $e) {
111 $this->assertEquals("'integer' is not a string.", $e->getMessage());
112 $raised = true;
113 }
114 $this->assertTrue($raised);
115
116 $raised = false;
117 try {
118 $std_class = new stdClass();
119 $lower_string = $custom($std_class);
120 } catch (InvalidArgumentException $e) {
121 $this->assertEquals("'object' is not a string.", $e->getMessage());
122 $raised = true;
123 }
124 $this->assertTrue($raised);
125 }

◆ testTransform()

TransformationsCustomTest::testTransform ( )

Definition at line 35 of file TransformationsCustomTest.php.

36 {
37 $result = $this->custom->transform(self::TEST_STRING);
38 $this->assertEquals(self::TEST_STRING, $result);
39 }

References $result.

◆ testTransformFails()

TransformationsCustomTest::testTransformFails ( )

Definition at line 41 of file TransformationsCustomTest.php.

42 {
43 $raised = false;
44 try {
45 $lower_string = $this->custom->transform(array());
46 } catch (InvalidArgumentException $e) {
47 $this->assertEquals("'array' is not a string.", $e->getMessage());
48 $raised = true;
49 }
50 $this->assertTrue($raised);
51
52 $raised = false;
53 try {
54 $lower_string = $this->custom->transform(12345);
55 } catch (InvalidArgumentException $e) {
56 $this->assertEquals("'integer' is not a string.", $e->getMessage());
57 $raised = true;
58 }
59 $this->assertTrue($raised);
60
61 $raised = false;
62 try {
63 $std_class = new stdClass();
64 $lower_string = $this->custom->transform($std_class);
65 } catch (InvalidArgumentException $e) {
66 $this->assertEquals("'object' is not a string.", $e->getMessage());
67 $raised = true;
68 }
69 $this->assertTrue($raised);
70 }

Field Documentation

◆ TEST_STRING

const TransformationsCustomTest::TEST_STRING = "Test"

Definition at line 14 of file TransformationsCustomTest.php.


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