Browse Source

changed lu dbo deserialization failed error; updated tests;

tags/0.1.10
Robin Thoni 8 years ago
parent
commit
1c3360c6ef

+ 28
- 0
phpunit.xml View File

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 View File

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 View File

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 View File

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

+ 1
- 1
src/Utils/Dbo/LuIntDboArray.php View File

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

+ 1
- 1
src/Utils/Dbo/LuStringDbo.php View File

43
     public static function jsonDeserialize($json)
43
     public static function jsonDeserialize($json)
44
     {
44
     {
45
         if (is_object($json) || is_array($json) || is_bool($json) || is_null($json)) {
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
         $val = new self();
48
         $val = new self();
49
         $val->setString($json . "");
49
         $val->setString($json . "");

+ 1
- 1
src/Utils/Dbo/LuStringDboArray.php View File

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

test/LuIntDboArrayTest.php → tests/LuIntDboArrayTest.php View File

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

test/LuIntDboTest.php → tests/LuIntDboTest.php View File

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

test/LuStringDboArrayTest.php → tests/LuStringDboArrayTest.php View File

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

test/LuStringDboTest.php → tests/LuStringDboTest.php View File

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

test/TestBusiness.php → tests/TestBusiness.php View File


test/TestDataAccess.php → tests/TestDataAccess.php View File


test/bootstrap.php → tests/bootstrap.php View File


Loading…
Cancel
Save