File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed
tests/Integration/Support Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -115,16 +115,25 @@ protected function resolve($name)
115
115
throw new RuntimeException ("Instance [ {$ name }] does not specify a {$ this ->driverKey }. " );
116
116
}
117
117
118
- if (isset ($ this ->customCreators [$ config [$ this ->driverKey ]])) {
118
+ $ driverName = $ config [$ this ->driverKey ];
119
+
120
+ if (isset ($ this ->customCreators [$ driverName ])) {
119
121
return $ this ->callCustomCreator ($ config );
120
122
} else {
121
- $ createMethod = 'create ' .ucfirst ($ config [$ this ->driverKey ]).ucfirst ($ this ->driverKey );
123
+ $ createMethod = 'create ' .ucfirst ($ driverName ).ucfirst ($ this ->driverKey );
124
+
125
+ if (method_exists ($ this , $ createMethod )) {
126
+ return $ this ->{$ createMethod }($ config );
127
+
128
+ }
129
+
130
+ $ createMethod = 'create ' .Str::studly ($ driverName ).ucfirst ($ this ->driverKey );
122
131
123
132
if (method_exists ($ this , $ createMethod )) {
124
133
return $ this ->{$ createMethod }($ config );
125
- } else {
126
- throw new InvalidArgumentException ("Instance {$ this ->driverKey } [ {$ config [$ this ->driverKey ]}] is not supported. " );
127
134
}
135
+
136
+ throw new InvalidArgumentException ("Instance {$ this ->driverKey } [ {$ config [$ this ->driverKey ]}] is not supported. " );
128
137
}
129
138
}
130
139
Original file line number Diff line number Diff line change @@ -34,6 +34,15 @@ public function __construct($config)
34
34
};
35
35
}
36
36
37
+ protected function createMysqlDatabaseConnectionDriver (array $ config ) {
38
+ return new class ($ config )
39
+ {
40
+ public function __construct (public $ config )
41
+ {
42
+ }
43
+ };
44
+ }
45
+
37
46
/**
38
47
* Get the default instance name.
39
48
*
@@ -74,6 +83,11 @@ public function getInstanceConfig($name)
74
83
'driver ' => 'bar ' ,
75
84
'bar-option ' => 'option-value ' ,
76
85
];
86
+ case 'mysql_database-connection ' :
87
+ return [
88
+ 'driver ' => 'mysql_database-connection ' ,
89
+ 'mysql_database-connection-option ' => 'option-value '
90
+ ];
77
91
default :
78
92
return [];
79
93
}
Original file line number Diff line number Diff line change @@ -18,10 +18,15 @@ public function test_configurable_instances_can_be_resolved()
18
18
$ barInstance = $ manager ->instance ('bar ' );
19
19
$ this ->assertSame ('option-value ' , $ barInstance ->config ['bar-option ' ]);
20
20
21
+ $ mysqlInstance = $ manager ->instance ('mysql_database-connection ' );
22
+ $ this ->assertSame ('option-value ' , $ mysqlInstance ->config ['mysql_database-connection-option ' ]);
23
+
21
24
$ duplicateFooInstance = $ manager ->instance ('foo ' );
22
25
$ duplicateBarInstance = $ manager ->instance ('bar ' );
26
+ $ duplicateMysqlInstance = $ manager ->instance ('mysql_database-connection ' );
23
27
$ this ->assertEquals (spl_object_hash ($ fooInstance ), spl_object_hash ($ duplicateFooInstance ));
24
28
$ this ->assertEquals (spl_object_hash ($ barInstance ), spl_object_hash ($ duplicateBarInstance ));
29
+ $ this ->assertEquals (spl_object_hash ($ mysqlInstance ), spl_object_hash ($ duplicateMysqlInstance ));
25
30
}
26
31
27
32
public function test_unresolvable_instances_throw_errors ()
You can’t perform that action at this time.
0 commit comments