Bläddra i källkod

get real type for doc values; tests

tags/0.1.11
Robin Thoni 8 år sedan
förälder
incheckning
b5c61f18a8
3 ändrade filer med 48 tillägg och 5 borttagningar
  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 Visa fil

@@ -133,12 +133,28 @@ class LuDocParser
133 133
                         $constraint->setMethod($methodName);
134 134
                         $args = [];
135 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 137
                             $args = $argMatches[1];
138 138
                             foreach ($args as $key => $arg) {
139
+                                $argLower = strtolower($arg);
139 140
                                 if ($arg[0] == '"' || $arg[0] == "'") {
140 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 160
                         $constraint->setArguments($args);

+ 27
- 0
src/Utils/Dbo/LuStringDbo.php Visa fil

@@ -54,4 +54,31 @@ class LuStringDbo extends LuDbo
54 54
     {
55 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 Visa fil

@@ -109,10 +109,10 @@ class LuDocParserTest extends \PHPUnit_Framework_TestCase
109 109
                 "Constraints" => []],
110 110
             'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\nand another\n",
111 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
         ];

Laddar…
Avbryt
Spara