23
23
24
24
use TypeError ;
25
25
use PHPUnit \Framework \TestCase ;
26
- use WikibaseSolutions \CypherDSL \ErrorHandling \ ErrorHelper ;
26
+ use WikibaseSolutions \CypherDSL \Traits \ ErrorTrait ;
27
27
28
28
/**
29
29
* Dummy classes
@@ -34,24 +34,44 @@ class ErrorHelperDummyExtendsA extends ErrorHelperDummyA {};
34
34
class ErrorHelperDummyExtendsB extends ErrorHelperDummyB {};
35
35
36
36
/**
37
- * @covers \WikibaseSolutions\CypherDSL\ErrorHandling\ErrorHelper
37
+ * Tester/Mock class
38
38
*/
39
- class ErrorHelperTest extends TestCase
39
+ class ErrorImpl {
40
+ use ErrorTrait;
41
+
42
+ /**
43
+ * Overcome private method problems
44
+ */
45
+ public function call ($ funcName , $ args ) {
46
+ return call_user_func_array ([self ::class, $ funcName ], $ args );
47
+ }
48
+ }
49
+
50
+ /**
51
+ * @covers \WikibaseSolutions\CypherDSL\Traits\ErrorTrait
52
+ */
53
+ class ErrorTraitTest extends TestCase
40
54
{
55
+ protected ErrorImpl $ errorImpl ;
56
+
57
+ public function setUp () : void {
58
+ $ this ->errorImpl = new ErrorImpl ();
59
+ }
60
+
41
61
/**
42
62
* @doesNotPerformAssertions
43
63
* @dataProvider CorrectAssertionsProvider
44
64
*/
45
65
public function testAssertClass ($ classNames , $ userInput ) {
46
- ErrorHelper:: assertClass ( ' foo ' , $ classNames , $ userInput );
66
+ $ this -> errorImpl -> call ( ' assertClass ' , [ ' foo ' , $ classNames , $ userInput] );
47
67
}
48
68
49
69
/**
50
70
* @dataProvider failingAssertionsProvider
51
71
*/
52
72
public function testAssertClassFailure ($ classNames , $ userInput ) {
53
73
$ this ->expectException (TypeError::class);
54
- ErrorHelper:: assertClass ( ' foo ' , $ classNames , $ userInput );
74
+ $ this -> errorImpl -> call ( ' assertClass ' , [ ' foo ' , $ classNames , $ userInput] );
55
75
}
56
76
57
77
public function correctAssertionsProvider () {
@@ -74,44 +94,35 @@ public function failingAssertionsProvider() {
74
94
public function testGetTypeErrorText () {
75
95
$ this ->assertEquals (
76
96
'$foo should be a WikibaseSolutions\CypherDSL\Tests\Unit\ErrorHandling\ErrorHelperDummyA object, integer "5" given. ' ,
77
- ErrorHelper:: getTypeErrorText ( ' foo ' , [ErrorHelperDummyA::class], 5 )
97
+ $ this -> errorImpl -> call ( ' getTypeErrorText ' , [ ' foo ' , [ErrorHelperDummyA::class], 5 ] )
78
98
);
79
99
$ this ->assertEquals (
80
100
'$foo should be a ' .
81
101
'WikibaseSolutions\CypherDSL\Tests\Unit\ErrorHandling\ErrorHelperDummyA or ' .
82
102
'WikibaseSolutions\CypherDSL\Tests\Unit\ErrorHandling\ErrorHelperDummyB object, integer "5" given. ' ,
83
- ErrorHelper:: getTypeErrorText ( ' foo ' , [ErrorHelperDummyA::class, ErrorHelperDummyB::class], 5 )
103
+ $ this -> errorImpl -> call ( ' getTypeErrorText ' , [ ' foo ' , [ErrorHelperDummyA::class, ErrorHelperDummyB::class], 5 ] )
84
104
);
85
105
}
86
106
87
- public function testGetUserInputInfo () {
88
- $ this ->assertEquals (
89
- 'string "foo" ' ,
90
- ErrorHelper::getUserInputInfo ('foo ' )
91
- );
92
- $ this ->assertEquals (
93
- 'integer "5" ' ,
94
- ErrorHelper::getUserInputInfo (5 )
95
- );
96
- $ this ->assertEquals (
97
- 'double "3.14" ' ,
98
- ErrorHelper::getUserInputInfo (3.14 )
99
- );
100
- $ this ->assertEquals (
101
- 'boolean "1" ' ,
102
- ErrorHelper::getUserInputInfo (true )
103
- );
104
- $ this ->assertEquals (
105
- 'array ' ,
106
- ErrorHelper::getUserInputInfo (['foo ' , 'bar ' ])
107
- );
108
- $ this ->assertEquals (
109
- 'anonymous class instance ' ,
110
- ErrorHelper::getUserInputInfo (new class (){})
111
- );
107
+ /**
108
+ * @dataProvider getUserInputInfoProvider
109
+ */
110
+ public function testGetUserInputInfo ($ expected , $ input ) {
112
111
$ this ->assertEquals (
113
- ' WikibaseSolutions\CypherDSL\Tests\Unit\ErrorHandling\ErrorHelperDummyA ' ,
114
- ErrorHelper:: getUserInputInfo ( new ErrorHelperDummyA () )
112
+ $ expected ,
113
+ $ this -> errorImpl -> call ( ' getUserInputInfo ' , [ $ input ] )
115
114
);
116
115
}
116
+
117
+ public function getUserInputInfoProvider () {
118
+ return [
119
+ [ 'string "foo" ' , 'foo ' ],
120
+ [ 'integer "5" ' , 5 ],
121
+ [ 'double "3.14" ' , 3.14 ],
122
+ [ 'boolean "1" ' , true ],
123
+ [ 'array ' , ['foo ' , 'bar ' ] ],
124
+ [ 'anonymous class instance ' , new class (){} ],
125
+ [ 'WikibaseSolutions\CypherDSL\Tests\Unit\ErrorHandling\ErrorHelperDummyA ' , new ErrorHelperDummyA ()]
126
+ ];
127
+ }
117
128
}
0 commit comments