22
33namespace Mpyw \LaravelMySqlSystemVariableManager \Tests ;
44
5+ use InvalidArgumentException ;
56use Mpyw \LaravelMySqlSystemVariableManager \MySqlConnection ;
6- use PDOException ;
7+ use Mpyw \ LaravelMySqlSystemVariableManager \ Value ;
78
89class BasicVariableAssignmentTest extends TestCase
910{
@@ -39,13 +40,21 @@ public function provideBasicVariables(): array
3940 'assigning boolean (emulated) ' => ['foreign_key_checks ' , true , '1 ' , false , '0 ' ],
4041 'assigning string (native) ' => ['tx_isolation ' , false , 'REPEATABLE-READ ' , 'read-committed ' , 'READ-COMMITTED ' ],
4142 'assigning string (emulated) ' => ['tx_isolation ' , true , 'REPEATABLE-READ ' , 'read-committed ' , 'READ-COMMITTED ' ],
43+ 'assigning wrapped float (native) ' => ['long_query_time ' , false , 10.0 , Value::float (15.0 ), 15.0 ],
44+ 'assigning wrapped float (emulated) ' => ['long_query_time ' , true , '10.000000 ' , Value::float (15.0 ), '15.000000 ' ],
45+ 'assigning wrapped integer (native) ' => ['long_query_time ' , false , 10.0 , Value::int (15 ), 15.0 ],
46+ 'assigning wrapped integer (emulated) ' => ['long_query_time ' , true , '10.000000 ' , Value::int (15 ), '15.000000 ' ],
47+ 'assigning wrapped boolean (native) ' => ['foreign_key_checks ' , false , 1 , Value::bool (false ), 0 ],
48+ 'assigning wrapped boolean (emulated) ' => ['foreign_key_checks ' , true , '1 ' , Value::bool (false ), '0 ' ],
49+ 'assigning wrapped string (native) ' => ['tx_isolation ' , false , 'REPEATABLE-READ ' , Value::str ('read-committed ' ), 'READ-COMMITTED ' ],
50+ 'assigning wrapped string (emulated) ' => ['tx_isolation ' , true , 'REPEATABLE-READ ' , Value::str ('read-committed ' ), 'READ-COMMITTED ' ],
4251 ];
4352 }
4453
4554 public function testAssigningNullThrowsExceptionOnNative (): void
4655 {
47- $ this ->expectException (PDOException ::class);
48- $ this ->expectExceptionMessage (" SQLSTATE[42000]: Syntax error or access violation: 1231 Variable 'foreign_key_checks' can't be set to the value of 'NULL' " );
56+ $ this ->expectException (InvalidArgumentException ::class);
57+ $ this ->expectExceptionMessage (' The value must be a scalar or Mpyw\LaravelMySqlSystemVariableManager\ValueInterface instance. ' );
4958
5059 $ this ->onNativeConnection (function (MySqlConnection $ db ) {
5160 $ db ->setSystemVariable ('foreign_key_checks ' , null );
@@ -55,24 +64,33 @@ public function testAssigningNullThrowsExceptionOnNative(): void
5564
5665 public function testAssigningNullThrowsExceptionOnEmulation (): void
5766 {
58- $ this ->expectException (PDOException ::class);
59- $ this ->expectExceptionMessage (" SQLSTATE[42000]: Syntax error or access violation: 1231 Variable 'foreign_key_checks' can't be set to the value of 'NULL' " );
67+ $ this ->expectException (InvalidArgumentException ::class);
68+ $ this ->expectExceptionMessage (' The value must be a scalar or Mpyw\LaravelMySqlSystemVariableManager\ValueInterface instance. ' );
6069
6170 $ this ->onEmulatedConnection (function (MySqlConnection $ db ) {
6271 $ db ->setSystemVariable ('foreign_key_checks ' , null );
6372 $ db ->getPdo ();
6473 });
6574 }
6675
67- public function testAssigningNullDoesNotThrowOnUnresolvedConnection (): void
76+ public function testAssigningNullThrowsOnUnresolvedNativeConnection (): void
6877 {
78+ $ this ->expectException (InvalidArgumentException::class);
79+ $ this ->expectExceptionMessage ('The value must be a scalar or Mpyw\LaravelMySqlSystemVariableManager\ValueInterface instance. ' );
80+
6981 $ this ->onNativeConnection (function (MySqlConnection $ db ) {
7082 $ db ->setSystemVariable ('foreign_key_checks ' , null );
7183 });
84+ }
85+
86+ public function testAssigningNullThrowsOnUnresolvedEmulatedConnection (): void
87+ {
88+ $ this ->expectException (InvalidArgumentException::class);
89+ $ this ->expectExceptionMessage ('The value must be a scalar or Mpyw\LaravelMySqlSystemVariableManager\ValueInterface instance. ' );
90+
7291 $ this ->onEmulatedConnection (function (MySqlConnection $ db ) {
7392 $ db ->setSystemVariable ('foreign_key_checks ' , null );
7493 });
75- $ this ->assertTrue (true );
7694 }
7795
7896 public function testAssignmentPriorityOnLazilyResolvedConnection (): void
0 commit comments