Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
PU_test_dcp_parsemethod.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package Dcp\Pu
5 */
6 
7 namespace Dcp\Pu;
8 
9 require_once 'PU_testcase_dcp.php';
10 
12 {
13  /**
14  * @dataProvider dataGoodStruct
15  */
16  public function testParseMethodCall($callName, $expectedStructs)
17  {
18  $err = '';
19 
20  $oParse = new \parseFamilyMethod();
21  $struct = $oParse->parse($callName);
22  $err = $struct->getError();
23 
24  $this->assertEmpty($err, sprintf("function struct error detected : %s, %s", $err, print_r($struct, true)));
25  foreach ($expectedStructs as $key => $expectedValue) {
26  if (is_array($expectedValue)) {
27  $values = $struct->$key;
28  foreach ($expectedValue as $kv => $singleValue) {
29  if (is_array($singleValue)) {
30  foreach ($singleValue as $k => $v) {
31  $this->assertEquals($v, $values[$kv]->$k, sprintf("test struct %s/%s [%s]", $key, $k . "[$kv]", print_r($values, true)));
32  }
33  } else {
34  $this->assertEquals($singleValue, $values[$kv], sprintf("testout struct %s/%s ", $key . "[$kv]", print_r($struct, true)));
35  }
36  }
37  } else {
38  $this->assertEquals($expectedValue, $struct->$key);
39  }
40  //$this->assertContains($expectedError, $err, sprintf("not the correct error reporting : %s", $err));
41 
42  }
43  }
44  /**
45  * test struct errors
46  * @dataProvider databadStruct
47  */
48  public function testParseMethodCallErrors($callName, $expectedErrors)
49  {
50  $err = '';
51  $oParse = new \parseFamilyMethod();
52  $struct = $oParse->parse($callName);
53  $err = $struct->getError();
54 
55  $this->assertNotEmpty($err, sprintf("function struct no error detected :%s", print_r($struct, true)));
56  foreach ($expectedErrors as $expectedError) {
57 
58  $this->assertContains($expectedError, $err, sprintf('not the correct error reporting : "%s" : %s', $err, print_r($struct, true)));
59  }
60  }
61 
62  public function dataGoodStruct()
63  {
64  return array(
65  // test simple function
66  array(
67  "::getTitle():OUT",
68  array(
69  "methodName" => "getTitle",
70  "outputs" => array(
71  "OUT"
72  )
73  )
74  ) ,
75  // test simple function
76  array(
77  "::getTitle ()",
78  array(
79  "methodName" => "getTitle",
80  "className" => ""
81  )
82  ) ,
83  // test simple function
84  array(
85  "myClass::getTitle ()",
86  array(
87  "methodName" => "getTitle",
88  "className" => "myClass"
89  )
90  ) ,
91  // test attr string arg
92  array(
93  '::getTitle( "ONE" ): OUT',
94  array(
95  "methodName" => "getTitle",
96  "inputs" => array(
97  array(
98  "name" => "ONE",
99  "type" => "string"
100  )
101  ) ,
102  "outputs" => array(
103  "OUT"
104  )
105  )
106  ) ,
107  // test with namespace
108  array(
109  'foo\\bar::getSomething("ONE","TWO"):OUT',
110  array(
111  "methodName" => "getSomething",
112  "className" => "foo\\bar",
113  "inputs" => array(
114  array(
115  "name" => "ONE",
116  "type" => "string"
117  ),
118  array(
119  "name" => "TWO",
120  "type" => "string"
121  )
122  ),
123  "outputs" => array(
124  "OUT"
125  )
126  )
127  )
128  );
129  }
130 
131  public function databadStruct()
132  {
133  return array(
134  // test no parenthesis
135  array(
136  "test()",
137  array(
138  "ATTR1251",
139  "test"
140  )
141  ) ,
142  array(
143  "::test",
144  array(
145  "ATTR1201",
146  "test"
147  )
148  ) ,
149  array(
150  "::test two()",
151  array(
152  "ATTR1252",
153  "test two"
154  )
155  ) ,
156  array(
157  "class one::testTwo()",
158  array(
159  "ATTR1253",
160  "class one"
161  )
162  ) ,
163  array(
164  "::testTwo():ONE,TWO",
165  array(
166  "ATTR1254"
167  )
168  ) ,
169  array(
170  "::testTwo() ONE",
171  array(
172  "ATTR1201"
173  )
174  )
175  );
176  }
177 }
178 ?>
testParseMethodCall($callName, $expectedStructs)
testParseMethodCallErrors($callName, $expectedErrors)
if($file) if($subject==""&&$file) if($subject=="") $err
← centre documentaire © anakeen