@@ -75,15 +75,15 @@ public function testMySqlConnectCallsCreateConnectionWithIsolationLevel()
75
75
76
76
public function testPostgresConnectCallsCreateConnectionWithProperArguments ()
77
77
{
78
- $ dsn = 'pgsql:host=foo;dbname= \'bar \';port=111 ' ;
78
+ $ dsn = 'pgsql:host=foo;dbname= \'bar \';port=111;client_encoding= \' utf8 \' ' ;
79
79
$ config = ['host ' => 'foo ' , 'database ' => 'bar ' , 'port ' => 111 , 'charset ' => 'utf8 ' ];
80
80
$ connector = $ this ->getMockBuilder (PostgresConnector::class)->onlyMethods (['createConnection ' , 'getOptions ' ])->getMock ();
81
81
$ connection = m::mock (stdClass::class);
82
82
$ connector ->expects ($ this ->once ())->method ('getOptions ' )->with ($ this ->equalTo ($ config ))->willReturn (['options ' ]);
83
83
$ connector ->expects ($ this ->once ())->method ('createConnection ' )->with ($ this ->equalTo ($ dsn ), $ this ->equalTo ($ config ), $ this ->equalTo (['options ' ]))->willReturn ($ connection );
84
84
$ statement = m::mock (PDOStatement::class);
85
- $ connection ->shouldReceive ('prepare ' )->once ()-> with ( ' set names \' utf8 \'' )->andReturn ($ statement );
86
- $ statement ->shouldReceive ('execute ' )->once ();
85
+ $ connection ->shouldReceive ('prepare ' )->zeroOrMoreTimes ( )->andReturn ($ statement );
86
+ $ statement ->shouldReceive ('execute ' )->zeroOrMoreTimes ();
87
87
$ result = $ connector ->connect ($ config );
88
88
89
89
$ this ->assertSame ($ result , $ connection );
@@ -97,16 +97,15 @@ public function testPostgresConnectCallsCreateConnectionWithProperArguments()
97
97
*/
98
98
public function testPostgresSearchPathIsSet ($ searchPath , $ expectedSql )
99
99
{
100
- $ dsn = 'pgsql:host=foo;dbname= \'bar \'' ;
100
+ $ dsn = 'pgsql:host=foo;dbname= \'bar \';client_encoding= \' utf8 \' ' ;
101
101
$ config = ['host ' => 'foo ' , 'database ' => 'bar ' , 'search_path ' => $ searchPath , 'charset ' => 'utf8 ' ];
102
102
$ connector = $ this ->getMockBuilder (PostgresConnector::class)->onlyMethods (['createConnection ' , 'getOptions ' ])->getMock ();
103
103
$ connection = m::mock (stdClass::class);
104
104
$ connector ->expects ($ this ->once ())->method ('getOptions ' )->with ($ this ->equalTo ($ config ))->willReturn (['options ' ]);
105
105
$ connector ->expects ($ this ->once ())->method ('createConnection ' )->with ($ this ->equalTo ($ dsn ), $ this ->equalTo ($ config ), $ this ->equalTo (['options ' ]))->willReturn ($ connection );
106
106
$ statement = m::mock (PDOStatement::class);
107
- $ connection ->shouldReceive ('prepare ' )->once ()->with ('set names \'utf8 \'' )->andReturn ($ statement );
108
107
$ connection ->shouldReceive ('prepare ' )->once ()->with ($ expectedSql )->andReturn ($ statement );
109
- $ statement ->shouldReceive ('execute ' )->twice ();
108
+ $ statement ->shouldReceive ('execute ' )->once ();
110
109
$ result = $ connector ->connect ($ config );
111
110
112
111
$ this ->assertSame ($ result , $ connection );
@@ -184,33 +183,31 @@ public static function provideSearchPaths()
184
183
185
184
public function testPostgresSearchPathFallbackToConfigKeySchema ()
186
185
{
187
- $ dsn = 'pgsql:host=foo;dbname= \'bar \'' ;
186
+ $ dsn = 'pgsql:host=foo;dbname= \'bar \';client_encoding= \' utf8 \' ' ;
188
187
$ config = ['host ' => 'foo ' , 'database ' => 'bar ' , 'schema ' => ['public ' , '"user" ' ], 'charset ' => 'utf8 ' ];
189
188
$ connector = $ this ->getMockBuilder (PostgresConnector::class)->onlyMethods (['createConnection ' , 'getOptions ' ])->getMock ();
190
189
$ connection = m::mock (stdClass::class);
191
190
$ connector ->expects ($ this ->once ())->method ('getOptions ' )->with ($ this ->equalTo ($ config ))->willReturn (['options ' ]);
192
191
$ connector ->expects ($ this ->once ())->method ('createConnection ' )->with ($ this ->equalTo ($ dsn ), $ this ->equalTo ($ config ), $ this ->equalTo (['options ' ]))->willReturn ($ connection );
193
192
$ statement = m::mock (PDOStatement::class);
194
- $ connection ->shouldReceive ('prepare ' )->once ()->with ('set names \'utf8 \'' )->andReturn ($ statement );
195
193
$ connection ->shouldReceive ('prepare ' )->once ()->with ('set search_path to "public", "user" ' )->andReturn ($ statement );
196
- $ statement ->shouldReceive ('execute ' )->twice ();
194
+ $ statement ->shouldReceive ('execute ' )->once ();
197
195
$ result = $ connector ->connect ($ config );
198
196
199
197
$ this ->assertSame ($ result , $ connection );
200
198
}
201
199
202
200
public function testPostgresApplicationNameIsSet ()
203
201
{
204
- $ dsn = 'pgsql:host=foo;dbname= \'bar \'' ;
202
+ $ dsn = 'pgsql:host=foo;dbname= \'bar \';client_encoding= \' utf8 \' ;application_name= \' Laravel App \' ' ;
205
203
$ config = ['host ' => 'foo ' , 'database ' => 'bar ' , 'charset ' => 'utf8 ' , 'application_name ' => 'Laravel App ' ];
206
204
$ connector = $ this ->getMockBuilder (PostgresConnector::class)->onlyMethods (['createConnection ' , 'getOptions ' ])->getMock ();
207
205
$ connection = m::mock (stdClass::class);
208
206
$ connector ->expects ($ this ->once ())->method ('getOptions ' )->with ($ this ->equalTo ($ config ))->willReturn (['options ' ]);
209
207
$ connector ->expects ($ this ->once ())->method ('createConnection ' )->with ($ this ->equalTo ($ dsn ), $ this ->equalTo ($ config ), $ this ->equalTo (['options ' ]))->willReturn ($ connection );
210
208
$ statement = m::mock (PDOStatement::class);
211
- $ connection ->shouldReceive ('prepare ' )->once ()->with ('set names \'utf8 \'' )->andReturn ($ statement );
212
- $ connection ->shouldReceive ('prepare ' )->once ()->with ('set application_name to \'Laravel App \'' )->andReturn ($ statement );
213
- $ statement ->shouldReceive ('execute ' )->twice ();
209
+ $ connection ->shouldReceive ('prepare ' )->zeroOrMoreTimes ()->andReturn ($ statement );
210
+ $ statement ->shouldReceive ('execute ' )->zeroOrMoreTimes ();
214
211
$ result = $ connector ->connect ($ config );
215
212
216
213
$ this ->assertSame ($ result , $ connection );
0 commit comments