@@ -52,29 +52,35 @@ public function testHasTableWhenSchemaUnqualifiedAndSearchPathMissing()
52
52
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn (null );
53
53
$ connection ->shouldReceive ('getConfig ' )->with ('schema ' )->andReturn (null );
54
54
$ grammar = m::mock (PostgresGrammar::class);
55
+ $ processor = m::mock (PostgresProcessor::class);
55
56
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
56
- $ grammar ->shouldReceive ('compileTableExists ' )->andReturn ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " );
57
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " , ['laravel ' , 'public ' , 'foo ' ])->andReturn (['countable_result ' ]);
57
+ $ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
58
+ $ grammar ->shouldReceive ('compileTables ' )->andReturn ('sql ' );
59
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([['schema ' => 'public ' , 'name ' => 'foo ' ]]);
58
60
$ connection ->shouldReceive ('getTablePrefix ' );
59
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
60
61
$ builder = $ this ->getBuilder ($ connection );
62
+ $ processor ->shouldReceive ('processTables ' )->andReturn ([['schema ' => 'public ' , 'name ' => 'foo ' ]]);
61
63
62
- $ builder ->hasTable ('foo ' );
64
+ $ this ->assertTrue ($ builder ->hasTable ('foo ' ));
65
+ $ this ->assertTrue ($ builder ->hasTable ('public.foo ' ));
63
66
}
64
67
65
68
public function testHasTableWhenSchemaUnqualifiedAndSearchPathFilled ()
66
69
{
67
70
$ connection = $ this ->getConnection ();
68
71
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('myapp,public ' );
69
72
$ grammar = m::mock (PostgresGrammar::class);
73
+ $ processor = m::mock (PostgresProcessor::class);
70
74
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
71
- $ grammar ->shouldReceive ('compileTableExists ' )->andReturn ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " );
72
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " , ['laravel ' , 'myapp ' , 'foo ' ])->andReturn (['countable_result ' ]);
75
+ $ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
76
+ $ grammar ->shouldReceive ('compileTables ' )->andReturn ('sql ' );
77
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([['schema ' => 'myapp ' , 'name ' => 'foo ' ]]);
73
78
$ connection ->shouldReceive ('getTablePrefix ' );
74
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
75
79
$ builder = $ this ->getBuilder ($ connection );
80
+ $ processor ->shouldReceive ('processTables ' )->andReturn ([['schema ' => 'myapp ' , 'name ' => 'foo ' ]]);
76
81
77
- $ builder ->hasTable ('foo ' );
82
+ $ this ->assertTrue ($ builder ->hasTable ('foo ' ));
83
+ $ this ->assertTrue ($ builder ->hasTable ('myapp.foo ' ));
78
84
}
79
85
80
86
public function testHasTableWhenSchemaUnqualifiedAndSearchPathFallbackFilled ()
@@ -83,14 +89,17 @@ public function testHasTableWhenSchemaUnqualifiedAndSearchPathFallbackFilled()
83
89
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn (null );
84
90
$ connection ->shouldReceive ('getConfig ' )->with ('schema ' )->andReturn (['myapp ' , 'public ' ]);
85
91
$ grammar = m::mock (PostgresGrammar::class);
92
+ $ processor = m::mock (PostgresProcessor::class);
86
93
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
87
- $ grammar ->shouldReceive ('compileTableExists ' )->andReturn ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " );
88
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " , ['laravel ' , 'myapp ' , 'foo ' ])->andReturn (['countable_result ' ]);
94
+ $ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
95
+ $ grammar ->shouldReceive ('compileTables ' )->andReturn ('sql ' );
96
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([['schema ' => 'myapp ' , 'name ' => 'foo ' ]]);
89
97
$ connection ->shouldReceive ('getTablePrefix ' );
90
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
91
98
$ builder = $ this ->getBuilder ($ connection );
99
+ $ processor ->shouldReceive ('processTables ' )->andReturn ([['schema ' => 'myapp ' , 'name ' => 'foo ' ]]);
92
100
93
- $ builder ->hasTable ('foo ' );
101
+ $ this ->assertTrue ($ builder ->hasTable ('foo ' ));
102
+ $ this ->assertTrue ($ builder ->hasTable ('myapp.foo ' ));
94
103
}
95
104
96
105
public function testHasTableWhenSchemaUnqualifiedAndSearchPathIsUserVariable ()
@@ -99,41 +108,43 @@ public function testHasTableWhenSchemaUnqualifiedAndSearchPathIsUserVariable()
99
108
$ connection ->shouldReceive ('getConfig ' )->with ('username ' )->andReturn ('foouser ' );
100
109
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('$user ' );
101
110
$ grammar = m::mock (PostgresGrammar::class);
111
+ $ processor = m::mock (PostgresProcessor::class);
102
112
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
103
- $ grammar ->shouldReceive ('compileTableExists ' )->andReturn ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " );
104
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " , ['laravel ' , 'foouser ' , 'foo ' ])->andReturn (['countable_result ' ]);
113
+ $ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
114
+ $ grammar ->shouldReceive ('compileTables ' )->andReturn ('sql ' );
115
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([['schema ' => 'foouser ' , 'name ' => 'foo ' ]]);
105
116
$ connection ->shouldReceive ('getTablePrefix ' );
106
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
107
117
$ builder = $ this ->getBuilder ($ connection );
118
+ $ processor ->shouldReceive ('processTables ' )->andReturn ([['schema ' => 'foouser ' , 'name ' => 'foo ' ]]);
108
119
109
- $ builder ->hasTable ('foo ' );
120
+ $ this ->assertTrue ($ builder ->hasTable ('foo ' ));
121
+ $ this ->assertTrue ($ builder ->hasTable ('foouser.foo ' ));
110
122
}
111
123
112
124
public function testHasTableWhenSchemaQualifiedAndSearchPathMismatches ()
113
125
{
114
126
$ connection = $ this ->getConnection ();
115
127
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('public ' );
116
128
$ grammar = m::mock (PostgresGrammar::class);
129
+ $ processor = m::mock (PostgresProcessor::class);
117
130
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
118
- $ grammar ->shouldReceive ('compileTableExists ' )->andReturn ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " );
119
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " , ['laravel ' , 'myapp ' , 'foo ' ])->andReturn (['countable_result ' ]);
131
+ $ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
132
+ $ grammar ->shouldReceive ('compileTables ' )->andReturn ('sql ' );
133
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([['schema ' => 'myapp ' , 'name ' => 'foo ' ]]);
120
134
$ connection ->shouldReceive ('getTablePrefix ' );
121
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
122
135
$ builder = $ this ->getBuilder ($ connection );
136
+ $ processor ->shouldReceive ('processTables ' )->andReturn ([['schema ' => 'myapp ' , 'name ' => 'foo ' ]]);
123
137
124
- $ builder ->hasTable ('myapp.foo ' );
138
+ $ this -> assertTrue ( $ builder ->hasTable ('myapp.foo ' ) );
125
139
}
126
140
127
141
public function testHasTableWhenDatabaseAndSchemaQualifiedAndSearchPathMismatches ()
128
142
{
143
+ $ this ->expectException (\InvalidArgumentException::class);
144
+
129
145
$ connection = $ this ->getConnection ();
130
- $ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('public ' );
131
146
$ grammar = m::mock (PostgresGrammar::class);
132
147
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
133
- $ grammar ->shouldReceive ('compileTableExists ' )->andReturn ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " );
134
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ("select * from information_schema.tables where table_catalog = ? and table_schema = ? and table_name = ? and table_type = 'BASE TABLE' " , ['mydatabase ' , 'myapp ' , 'foo ' ])->andReturn (['countable_result ' ]);
135
- $ connection ->shouldReceive ('getTablePrefix ' );
136
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
137
148
$ builder = $ this ->getBuilder ($ connection );
138
149
139
150
$ builder ->hasTable ('mydatabase.myapp.foo ' );
@@ -146,10 +157,9 @@ public function testGetColumnListingWhenSchemaUnqualifiedAndSearchPathMissing()
146
157
$ connection ->shouldReceive ('getConfig ' )->with ('schema ' )->andReturn (null );
147
158
$ grammar = m::mock (PostgresGrammar::class);
148
159
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
149
- $ grammar ->shouldReceive ('compileColumns ' )->with ('laravel ' , ' public ' , 'foo ' )->andReturn ('sql ' );
150
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([' countable_result ' ]);
160
+ $ grammar ->shouldReceive ('compileColumns ' )->with ('public ' , 'foo ' )->andReturn ('sql ' );
161
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([[ ' name ' => ' some_column ' ] ]);
151
162
$ connection ->shouldReceive ('getTablePrefix ' );
152
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
153
163
$ processor = m::mock (PostgresProcessor::class);
154
164
$ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
155
165
$ processor ->shouldReceive ('processColumns ' )->andReturn ([['name ' => 'some_column ' ]]);
@@ -164,10 +174,9 @@ public function testGetColumnListingWhenSchemaUnqualifiedAndSearchPathFilled()
164
174
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('myapp,public ' );
165
175
$ grammar = m::mock (PostgresGrammar::class);
166
176
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
167
- $ grammar ->shouldReceive ('compileColumns ' )->with ('laravel ' , ' myapp ' , 'foo ' )->andReturn ('sql ' );
168
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([' countable_result ' ]);
177
+ $ grammar ->shouldReceive ('compileColumns ' )->with ('myapp ' , 'foo ' )->andReturn ('sql ' );
178
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([[ ' name ' => ' some_column ' ] ]);
169
179
$ connection ->shouldReceive ('getTablePrefix ' );
170
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
171
180
$ processor = m::mock (PostgresProcessor::class);
172
181
$ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
173
182
$ processor ->shouldReceive ('processColumns ' )->andReturn ([['name ' => 'some_column ' ]]);
@@ -183,10 +192,9 @@ public function testGetColumnListingWhenSchemaUnqualifiedAndSearchPathIsUserVari
183
192
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('$user ' );
184
193
$ grammar = m::mock (PostgresGrammar::class);
185
194
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
186
- $ grammar ->shouldReceive ('compileColumns ' )->with ('laravel ' , ' foouser ' , 'foo ' )->andReturn ('sql ' );
187
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([' countable_result ' ]);
195
+ $ grammar ->shouldReceive ('compileColumns ' )->with ('foouser ' , 'foo ' )->andReturn ('sql ' );
196
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([[ ' name ' => ' some_column ' ] ]);
188
197
$ connection ->shouldReceive ('getTablePrefix ' );
189
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
190
198
$ processor = m::mock (PostgresProcessor::class);
191
199
$ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
192
200
$ processor ->shouldReceive ('processColumns ' )->andReturn ([['name ' => 'some_column ' ]]);
@@ -201,10 +209,9 @@ public function testGetColumnListingWhenSchemaQualifiedAndSearchPathMismatches()
201
209
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('public ' );
202
210
$ grammar = m::mock (PostgresGrammar::class);
203
211
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
204
- $ grammar ->shouldReceive ('compileColumns ' )->with ('laravel ' , ' myapp ' , 'foo ' )->andReturn ('sql ' );
205
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([' countable_result ' ]);
212
+ $ grammar ->shouldReceive ('compileColumns ' )->with ('myapp ' , 'foo ' )->andReturn ('sql ' );
213
+ $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn ([[ ' name ' => ' some_column ' ] ]);
206
214
$ connection ->shouldReceive ('getTablePrefix ' );
207
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
208
215
$ processor = m::mock (PostgresProcessor::class);
209
216
$ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
210
217
$ processor ->shouldReceive ('processColumns ' )->andReturn ([['name ' => 'some_column ' ]]);
@@ -215,17 +222,12 @@ public function testGetColumnListingWhenSchemaQualifiedAndSearchPathMismatches()
215
222
216
223
public function testGetColumnWhenDatabaseAndSchemaQualifiedAndSearchPathMismatches ()
217
224
{
225
+ $ this ->expectException (\InvalidArgumentException::class);
226
+
218
227
$ connection = $ this ->getConnection ();
219
228
$ connection ->shouldReceive ('getConfig ' )->with ('search_path ' )->andReturn ('public ' );
220
229
$ grammar = m::mock (PostgresGrammar::class);
221
230
$ connection ->shouldReceive ('getSchemaGrammar ' )->once ()->andReturn ($ grammar );
222
- $ grammar ->shouldReceive ('compileColumns ' )->with ('mydatabase ' , 'myapp ' , 'foo ' )->andReturn ('sql ' );
223
- $ connection ->shouldReceive ('selectFromWriteConnection ' )->with ('sql ' )->andReturn (['countable_result ' ]);
224
- $ connection ->shouldReceive ('getTablePrefix ' );
225
- $ connection ->shouldReceive ('getConfig ' )->with ('database ' )->andReturn ('laravel ' );
226
- $ processor = m::mock (PostgresProcessor::class);
227
- $ connection ->shouldReceive ('getPostProcessor ' )->andReturn ($ processor );
228
- $ processor ->shouldReceive ('processColumns ' )->andReturn ([['name ' => 'some_column ' ]]);
229
231
$ builder = $ this ->getBuilder ($ connection );
230
232
231
233
$ builder ->getColumnListing ('mydatabase.myapp.foo ' );
0 commit comments