浏览代码

changed lu dbo deserialization failed error; updated tests;

tags/0.1.10
Robin Thoni 8 年前
父节点
当前提交
1c3360c6ef

+ 28
- 0
phpunit.xml 查看文件

@@ -0,0 +1,28 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<phpunit backupGlobals="false"
3
+         backupStaticAttributes="false"
4
+         bootstrap="tests/bootstrap.php"
5
+         colors="true"
6
+         convertErrorsToExceptions="true"
7
+         convertNoticesToExceptions="true"
8
+         convertWarningsToExceptions="true"
9
+         processIsolation="false"
10
+         stopOnFailure="false"
11
+         syntaxCheck="false">
12
+    <testsuites>
13
+        <testsuite name="Application Test Suite">
14
+            <directory>./tests/</directory>
15
+        </testsuite>
16
+    </testsuites>
17
+    <filter>
18
+        <whitelist>
19
+            <directory suffix=".php">app/</directory>
20
+        </whitelist>
21
+    </filter>
22
+    <php>
23
+        <env name="APP_ENV" value="testing"/>
24
+        <env name="CACHE_DRIVER" value="array"/>
25
+        <env name="SESSION_DRIVER" value="array"/>
26
+        <env name="QUEUE_DRIVER" value="sync"/>
27
+    </php>
28
+</phpunit>

+ 66
- 0
src/Utils/Dbo/LuBoolDbo.php 查看文件

@@ -0,0 +1,66 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 5/29/16
6
+ * Time: 2:41 PM
7
+ */
8
+
9
+namespace Luticate\Utils\Dbo;
10
+
11
+
12
+use Luticate\Utils\LuBusiness;
13
+use Luticate\Utils\LuDbo;
14
+
15
+class LuBoolDbo extends LuDbo
16
+{
17
+    /**
18
+     * @var $_value bool
19
+     */
20
+    private $_value;
21
+
22
+    /**
23
+     * @return bool
24
+     */
25
+    public function getBool()
26
+    {
27
+        return $this->_value;
28
+    }
29
+
30
+    /**
31
+     * @param bool $value
32
+     */
33
+    public function setBool($value)
34
+    {
35
+        $this->_value = $value;
36
+    }
37
+
38
+    function jsonSerialize()
39
+    {
40
+        return $this->_value;
41
+    }
42
+
43
+    public static function jsonDeserialize($json)
44
+    {
45
+        $bool = null;
46
+        if (is_bool($json)) {
47
+            $bool = $json;
48
+        }
49
+        if (is_string($json)) {
50
+            if (strtolower($json) === "true" || strtolower($json) === "false") {
51
+                $bool = (strtolower($json) === "true");
52
+            }
53
+        }
54
+        if (is_null($bool)) {
55
+            throw new LuDboDeserializeException("Invalid bool value");
56
+        }
57
+        $val = new self();
58
+        $val->setBool($bool);
59
+        return $val;
60
+    }
61
+
62
+    public static function generateSample()
63
+    {
64
+        return "sample string";
65
+    }
66
+}

+ 14
- 0
src/Utils/Dbo/LuDboDeserializeException.php 查看文件

@@ -0,0 +1,14 @@
1
+<?php
2
+/**
3
+ * Created by PhpStorm.
4
+ * User: robin
5
+ * Date: 5/29/16
6
+ * Time: 3:53 PM
7
+ */
8
+
9
+namespace Luticate\Utils\Dbo;
10
+
11
+
12
+class LuDboDeserializeException extends \Exception
13
+{
14
+}

+ 1
- 1
src/Utils/Dbo/LuIntDbo.php 查看文件

@@ -43,7 +43,7 @@ class LuIntDbo extends LuDbo
43 43
     public static function jsonDeserialize($json)
44 44
     {
45 45
         if (!is_numeric($json) || intval($json) != $json) {
46
-            LuBusiness::badInput("Invalid integer value");
46
+            throw new LuDboDeserializeException("Invalid integer value");
47 47
         }
48 48
         $val = new self();
49 49
         $val->setInt(intval($json));

+ 1
- 1
src/Utils/Dbo/LuIntDboArray.php 查看文件

@@ -35,7 +35,7 @@ class LuIntDboArray extends LuDbo
35 35
     public static function jsonDeserialize($json)
36 36
     {
37 37
         if (!is_array($json)) {
38
-            LuBusiness::badInput("Invalid array value");
38
+            throw new LuDboDeserializeException("Invalid array value");
39 39
         }
40 40
         $dbo = new self();
41 41
         $array = [];

+ 1
- 1
src/Utils/Dbo/LuStringDbo.php 查看文件

@@ -43,7 +43,7 @@ class LuStringDbo extends LuDbo
43 43
     public static function jsonDeserialize($json)
44 44
     {
45 45
         if (is_object($json) || is_array($json) || is_bool($json) || is_null($json)) {
46
-            LuBusiness::badInput("Invalid string value");
46
+            throw new LuDboDeserializeException("Invalid string value");
47 47
         }
48 48
         $val = new self();
49 49
         $val->setString($json . "");

+ 1
- 1
src/Utils/Dbo/LuStringDboArray.php 查看文件

@@ -35,7 +35,7 @@ class LuStringDboArray extends LuDbo
35 35
     public static function jsonDeserialize($json)
36 36
     {
37 37
         if (!is_array($json)) {
38
-            LuBusiness::badInput("Invalid array value");
38
+            throw new LuDboDeserializeException("Invalid array value");
39 39
         }
40 40
         $dbo = new self();
41 41
         $array = [];

test/LuIntDboArrayTest.php → tests/LuIntDboArrayTest.php 查看文件

@@ -1,4 +1,5 @@
1 1
 <?php
2
+use Luticate\Utils\Dbo\LuDboDeserializeException;
2 3
 use Luticate\Utils\Dbo\LuIntDboArray;
3 4
 use Luticate\Utils\Dbo\LuIntDbo;
4 5
 
@@ -44,84 +45,84 @@ class LuIntDboArrayTest extends \PHPUnit_Framework_TestCase
44 45
 
45 46
     public function testArrayStringIntPlusData()
46 47
     {
47
-        $this->expectException(AbortException::class);
48
+        $this->expectException(LuDboDeserializeException::class);
48 49
         LuIntDboArray::jsonDeserialize(["42test"]);
49 50
     }
50 51
 
51 52
     public function testArrayMultipleStringIntPlusData()
52 53
     {
53
-        $this->expectException(AbortException::class);
54
+        $this->expectException(LuDboDeserializeException::class);
54 55
         LuIntDboArray::jsonDeserialize(["42", 42, "42test"]);
55 56
     }
56 57
     
57 58
     public function testIntString()
58 59
     {
59
-        $this->expectException(AbortException::class);
60
+        $this->expectException(LuDboDeserializeException::class);
60 61
         LuIntDboArray::jsonDeserialize("42");
61 62
     }
62 63
     
63 64
     public function testInt()
64 65
     {
65
-        $this->expectException(AbortException::class);
66
+        $this->expectException(LuDboDeserializeException::class);
66 67
         LuIntDboArray::jsonDeserialize(42);
67 68
     }
68 69
     public function testIntNegativeString()
69 70
     {
70
-        $this->expectException(AbortException::class);
71
+        $this->expectException(LuDboDeserializeException::class);
71 72
         LuIntDboArray::jsonDeserialize("-42");
72 73
     }
73 74
 
74 75
     public function testIntNegative()
75 76
     {
76
-        $this->expectException(AbortException::class);
77
+        $this->expectException(LuDboDeserializeException::class);
77 78
         LuIntDboArray::jsonDeserialize(-42);
78 79
     }
79 80
 
80 81
     public function testFloat()
81 82
     {
82
-        $this->expectException(AbortException::class);
83
+        $this->expectException(LuDboDeserializeException::class);
83 84
         LuIntDboArray::jsonDeserialize(42.42);
84 85
     }
85 86
 
86 87
     public function testFloatString()
87 88
     {
88
-        $this->expectException(AbortException::class);
89
+        $this->expectException(LuDboDeserializeException::class);
89 90
         LuIntDboArray::jsonDeserialize("42.42");
90 91
     }
91 92
 
92 93
     public function testExponentialString()
93 94
     {
94
-        $this->expectException(AbortException::class);
95
+        $this->expectException(LuDboDeserializeException::class);
95 96
         LuIntDboArray::jsonDeserialize("42e+01");
96 97
     }
97 98
 
98 99
     public function testBool()
99 100
     {
100
-        $this->expectException(AbortException::class);
101
+        $this->expectException(LuDboDeserializeException::class);
101 102
         LuIntDboArray::jsonDeserialize(true);
102 103
     }
103 104
 
104 105
     public function testBoolString()
105 106
     {
106
-        $this->expectException(AbortException::class);
107
+        $this->expectException(LuDboDeserializeException::class);
107 108
         LuIntDboArray::jsonDeserialize("true");
108 109
     }
109 110
 
110 111
     public function testArrayFloat()
111 112
     {
112
-        $this->expectException(AbortException::class);
113
+        $this->expectException(LuDboDeserializeException::class);
113 114
         LuIntDboArray::jsonDeserialize([42.42]);
114 115
     }
115 116
 
116 117
     public function testNull()
117 118
     {
118
-        $this->expectException(AbortException::class);
119
+        $this->expectException(LuDboDeserializeException::class);
119 120
         LuIntDboArray::jsonDeserialize(null);
120 121
     }
121 122
 
122 123
     public function testObject()
123 124
     {
124
-        $this->expectException(AbortException::class);
125
+        $this->expectException(LuDboDeserializeException::class);
125 126
         LuIntDboArray::jsonDeserialize(new self());
126 127
     }
127 128
 }

test/LuIntDboTest.php → tests/LuIntDboTest.php 查看文件

@@ -1,4 +1,5 @@
1 1
 <?php
2
+use Luticate\Utils\Dbo\LuDboDeserializeException;
2 3
 use Luticate\Utils\Dbo\LuIntDbo;
3 4
 
4 5
 /**
@@ -35,73 +36,73 @@ class LuIntDboTest extends \PHPUnit_Framework_TestCase
35 36
 
36 37
     public function testStringIntPlusData()
37 38
     {
38
-        $this->expectException(AbortException::class);
39
+        $this->expectException(LuDboDeserializeException::class);
39 40
         LuIntDbo::jsonDeserialize("42test");
40 41
     }
41 42
 
42 43
     public function testFloat()
43 44
     {
44
-        $this->expectException(AbortException::class);
45
+        $this->expectException(LuDboDeserializeException::class);
45 46
         LuIntDbo::jsonDeserialize(42.42);
46 47
     }
47 48
 
48 49
     public function testFloatString()
49 50
     {
50
-        $this->expectException(AbortException::class);
51
+        $this->expectException(LuDboDeserializeException::class);
51 52
         LuIntDbo::jsonDeserialize("42.42");
52 53
     }
53 54
 
54 55
     public function testExponentialString()
55 56
     {
56
-        $this->expectException(AbortException::class);
57
+        $this->expectException(LuDboDeserializeException::class);
57 58
         LuIntDbo::jsonDeserialize("42e+01");
58 59
     }
59 60
 
60 61
     public function testBool()
61 62
     {
62
-        $this->expectException(AbortException::class);
63
+        $this->expectException(LuDboDeserializeException::class);
63 64
         LuIntDbo::jsonDeserialize(true);
64 65
     }
65 66
 
66 67
     public function testBoolString()
67 68
     {
68
-        $this->expectException(AbortException::class);
69
+        $this->expectException(LuDboDeserializeException::class);
69 70
         LuIntDbo::jsonDeserialize("true");
70 71
     }
71 72
 
72 73
     public function testArrayEmpty()
73 74
     {
74
-        $this->expectException(AbortException::class);
75
+        $this->expectException(LuDboDeserializeException::class);
75 76
         LuIntDbo::jsonDeserialize([]);
76 77
     }
77 78
 
78 79
     public function testArrayString()
79 80
     {
80
-        $this->expectException(AbortException::class);
81
+        $this->expectException(LuDboDeserializeException::class);
81 82
         LuIntDbo::jsonDeserialize(["42"]);
82 83
     }
83 84
 
84 85
     public function testArrayInt()
85 86
     {
86
-        $this->expectException(AbortException::class);
87
+        $this->expectException(LuDboDeserializeException::class);
87 88
         LuIntDbo::jsonDeserialize([42]);
88 89
     }
89 90
 
90 91
     public function testArrayFloat()
91 92
     {
92
-        $this->expectException(AbortException::class);
93
+        $this->expectException(LuDboDeserializeException::class);
93 94
         LuIntDbo::jsonDeserialize([42.42]);
94 95
     }
95 96
 
96 97
     public function testNull()
97 98
     {
98
-        $this->expectException(AbortException::class);
99
+        $this->expectException(LuDboDeserializeException::class);
99 100
         LuIntDbo::jsonDeserialize(null);
100 101
     }
101 102
 
102 103
     public function testObject()
103 104
     {
104
-        $this->expectException(AbortException::class);
105
+        $this->expectException(LuDboDeserializeException::class);
105 106
         LuIntDbo::jsonDeserialize(new self());
106 107
     }
107 108
 }

test/LuStringDboArrayTest.php → tests/LuStringDboArrayTest.php 查看文件

@@ -1,4 +1,5 @@
1 1
 <?php
2
+use Luticate\Utils\Dbo\LuDboDeserializeException;
2 3
 use Luticate\Utils\Dbo\LuStringDboArray;
3 4
 use Luticate\Utils\Dbo\LuStringDbo;
4 5
 
@@ -62,72 +63,72 @@ class LuStringDboArrayTest extends \PHPUnit_Framework_TestCase
62 63
 
63 64
     public function testArrayMultipleTypes()
64 65
     {
65
-        $this->expectException(AbortException::class);
66
+        $this->expectException(LuDboDeserializeException::class);
66 67
         LuStringDboArray::jsonDeserialize(["42", 42, "42test", null]);
67 68
     }
68 69
     
69 70
     public function testIntString()
70 71
     {
71
-        $this->expectException(AbortException::class);
72
+        $this->expectException(LuDboDeserializeException::class);
72 73
         LuStringDboArray::jsonDeserialize("42");
73 74
     }
74 75
     
75 76
     public function testInt()
76 77
     {
77
-        $this->expectException(AbortException::class);
78
+        $this->expectException(LuDboDeserializeException::class);
78 79
         LuStringDboArray::jsonDeserialize(42);
79 80
     }
80 81
     public function testIntNegativeString()
81 82
     {
82
-        $this->expectException(AbortException::class);
83
+        $this->expectException(LuDboDeserializeException::class);
83 84
         LuStringDboArray::jsonDeserialize("-42");
84 85
     }
85 86
 
86 87
     public function testIntNegative()
87 88
     {
88
-        $this->expectException(AbortException::class);
89
+        $this->expectException(LuDboDeserializeException::class);
89 90
         LuStringDboArray::jsonDeserialize(-42);
90 91
     }
91 92
 
92 93
     public function testFloat()
93 94
     {
94
-        $this->expectException(AbortException::class);
95
+        $this->expectException(LuDboDeserializeException::class);
95 96
         LuStringDboArray::jsonDeserialize(42.42);
96 97
     }
97 98
 
98 99
     public function testFloatString()
99 100
     {
100
-        $this->expectException(AbortException::class);
101
+        $this->expectException(LuDboDeserializeException::class);
101 102
         LuStringDboArray::jsonDeserialize("42.42");
102 103
     }
103 104
 
104 105
     public function testExponentialString()
105 106
     {
106
-        $this->expectException(AbortException::class);
107
+        $this->expectException(LuDboDeserializeException::class);
107 108
         LuStringDboArray::jsonDeserialize("42e+01");
108 109
     }
109 110
 
110 111
     public function testBool()
111 112
     {
112
-        $this->expectException(AbortException::class);
113
+        $this->expectException(LuDboDeserializeException::class);
113 114
         LuStringDboArray::jsonDeserialize(true);
114 115
     }
115 116
 
116 117
     public function testBoolString()
117 118
     {
118
-        $this->expectException(AbortException::class);
119
+        $this->expectException(LuDboDeserializeException::class);
119 120
         LuStringDboArray::jsonDeserialize("true");
120 121
     }
121 122
 
122 123
     public function testNull()
123 124
     {
124
-        $this->expectException(AbortException::class);
125
+        $this->expectException(LuDboDeserializeException::class);
125 126
         LuStringDboArray::jsonDeserialize(null);
126 127
     }
127 128
 
128 129
     public function testObject()
129 130
     {
130
-        $this->expectException(AbortException::class);
131
+        $this->expectException(LuDboDeserializeException::class);
131 132
         LuStringDboArray::jsonDeserialize(new self());
132 133
     }
133 134
 }

test/LuStringDboTest.php → tests/LuStringDboTest.php 查看文件

@@ -1,4 +1,5 @@
1 1
 <?php
2
+use Luticate\Utils\Dbo\LuDboDeserializeException;
2 3
 use Luticate\Utils\Dbo\LuStringDbo;
3 4
 
4 5
 /**
@@ -59,7 +60,7 @@ class LuStringDboTest extends \PHPUnit_Framework_TestCase
59 60
 
60 61
     public function testBool()
61 62
     {
62
-        $this->expectException(AbortException::class);
63
+        $this->expectException(LuDboDeserializeException::class);
63 64
         LuStringDbo::jsonDeserialize(true);
64 65
     }
65 66
 
@@ -71,37 +72,37 @@ class LuStringDboTest extends \PHPUnit_Framework_TestCase
71 72
 
72 73
     public function testArrayEmpty()
73 74
     {
74
-        $this->expectException(AbortException::class);
75
+        $this->expectException(LuDboDeserializeException::class);
75 76
         LuStringDbo::jsonDeserialize([]);
76 77
     }
77 78
 
78 79
     public function testArrayString()
79 80
     {
80
-        $this->expectException(AbortException::class);
81
+        $this->expectException(LuDboDeserializeException::class);
81 82
         LuStringDbo::jsonDeserialize(["42"]);
82 83
     }
83 84
 
84 85
     public function testArrayInt()
85 86
     {
86
-        $this->expectException(AbortException::class);
87
+        $this->expectException(LuDboDeserializeException::class);
87 88
         LuStringDbo::jsonDeserialize([42]);
88 89
     }
89 90
 
90 91
     public function testArrayFloat()
91 92
     {
92
-        $this->expectException(AbortException::class);
93
+        $this->expectException(LuDboDeserializeException::class);
93 94
         LuStringDbo::jsonDeserialize([42.42]);
94 95
     }
95 96
 
96 97
     public function testNull()
97 98
     {
98
-        $this->expectException(AbortException::class);
99
+        $this->expectException(LuDboDeserializeException::class);
99 100
         LuStringDbo::jsonDeserialize(null);
100 101
     }
101 102
 
102 103
     public function testObject()
103 104
     {
104
-        $this->expectException(AbortException::class);
105
+        $this->expectException(LuDboDeserializeException::class);
105 106
         LuStringDbo::jsonDeserialize(new self());
106 107
     }
107 108
 }

test/TestBusiness.php → tests/TestBusiness.php 查看文件


test/TestDataAccess.php → tests/TestDataAccess.php 查看文件


test/bootstrap.php → tests/bootstrap.php 查看文件


正在加载...
取消
保存