Browse Source

get real type for doc values; tests

tags/0.1.11
Robin Thoni 8 years ago
parent
commit
b5c61f18a8
3 changed files with 48 additions and 5 deletions
  1. 17
    1
      src/Utils/Business/LuDocParser.php
  2. 27
    0
      src/Utils/Dbo/LuStringDbo.php
  3. 4
    4
      tests/LuDocParserTest.php

+ 17
- 1
src/Utils/Business/LuDocParser.php View File

133
                         $constraint->setMethod($methodName);
133
                         $constraint->setMethod($methodName);
134
                         $args = [];
134
                         $args = [];
135
                         $argMatches = [];
135
                         $argMatches = [];
136
-                        if (preg_match_all('/ *(-?(?:\d*\.\d+|\d+|true|false|"[^"]*"|\'[^\']*\'))/', $line, $argMatches) !== false) {
136
+                        if (preg_match_all('/ *(-?(?:\d*\.\d+|\d+|true|false|null|"[^"]*"|\'[^\']*\'))/', $line, $argMatches) !== false) {
137
                             $args = $argMatches[1];
137
                             $args = $argMatches[1];
138
                             foreach ($args as $key => $arg) {
138
                             foreach ($args as $key => $arg) {
139
+                                $argLower = strtolower($arg);
139
                                 if ($arg[0] == '"' || $arg[0] == "'") {
140
                                 if ($arg[0] == '"' || $arg[0] == "'") {
140
                                     $args[$key] = substr($arg, 1, count($arg) - 2);
141
                                     $args[$key] = substr($arg, 1, count($arg) - 2);
141
                                 }
142
                                 }
143
+                                else if ($argLower == "true") {
144
+                                    $args[$key] = true;
145
+                                }
146
+                                else if ($argLower == "false") {
147
+                                    $args[$key] = false;
148
+                                }
149
+                                else if ($argLower == "null") {
150
+                                    $args[$key] = null;
151
+                                }
152
+                                else if (strpos($arg, ".") !== false) {
153
+                                    $args[$key] = floatval($arg);
154
+                                }
155
+                                else {
156
+                                    $args[$key] = intval($arg);
157
+                                }
142
                             }
158
                             }
143
                         }
159
                         }
144
                         $constraint->setArguments($args);
160
                         $constraint->setArguments($args);

+ 27
- 0
src/Utils/Dbo/LuStringDbo.php View File

54
     {
54
     {
55
         return "sample string";
55
         return "sample string";
56
     }
56
     }
57
+    
58
+    protected function getLength($trim)
59
+    {
60
+        return strlen($trim ? trim($this->_value) : $this->_value);
61
+    }
62
+
63
+    public function between($min, $max, $trim = true)
64
+    {
65
+        $len = self::getLength($trim);
66
+        if ($len < $min || $len > $max) {
67
+            throw new LuDboConstraintException("String length must be between ${min} and ${max} inclusive");
68
+        }
69
+    }
70
+
71
+    public function min($min, $trim = true)
72
+    {
73
+        if (self::getLength($trim) < $min) {
74
+            throw new LuDboConstraintException("String length must be greater or equal to ${min}");
75
+        }
76
+    }
77
+
78
+    public function max($max, $trim = true)
79
+    {
80
+        if (self::getLength($trim) > $max) {
81
+            throw new LuDboConstraintException("String length must be smaller or equal to ${max}");
82
+        }
83
+    }
57
 }
84
 }

+ 4
- 4
tests/LuDocParserTest.php View File

109
                 "Constraints" => []],
109
                 "Constraints" => []],
110
             'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\nand another\n",
110
             'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\nand another\n",
111
                 "Constraints" => [
111
                 "Constraints" => [
112
-                    ["Method" => "min", "Arguments" => ["42"]],
113
-                    ["Method" => "max", "Arguments" => ["42"]],
114
-                    ["Method" => "between", "Arguments" => ["0", "42"]],
115
-                    ["Method" => "another", "Arguments" => ["1", "2", "42.42", "true", "false", "a string", "string"]]
112
+                    ["Method" => "min", "Arguments" => [42]],
113
+                    ["Method" => "max", "Arguments" => [42]],
114
+                    ["Method" => "between", "Arguments" => [0, 42]],
115
+                    ["Method" => "another", "Arguments" => [1, 2, 42.42, true, false, "a string", "string"]]
116
                 ]
116
                 ]
117
             ]
117
             ]
118
         ];
118
         ];

Loading…
Cancel
Save