From 6500f3c84a33117d9d5b0674677aba28a8d0f2fb Mon Sep 17 00:00:00 2001 From: Damien Date: Sat, 6 Feb 2021 09:53:08 +1300 Subject: [PATCH] PHPUnit Tests Resolves #200 and also fixed phpunit error `expectExceptionMessageRegExp() is deprecated in PHPUnit 8 and will be removed in PHPUnit 9. Use expectExceptionMessageMatches() instead.` --- tests/ConfigTest.php | 16 ++++++++-------- tests/DInjectorTest.php | 4 ++-- tests/DatabaseTest.php | 2 +- tests/ezSchemaTest.php | 2 +- tests/ezsqlModelTest.php | 2 +- tests/mysqli/mysqliTest.php | 2 +- tests/pdo/pdo_mysqlTest.php | 12 ++++++------ tests/pdo/pdo_pgsqlTest.php | 6 +++--- tests/pdo/pdo_sqliteTest.php | 6 +++--- tests/pdo/pdo_sqlsrvTest.php | 6 +++--- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 5cd8f0e..b824dd7 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -45,7 +45,7 @@ public function testErrorMysqli() } $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = Config::initialize('mysqli', [self::TEST_DB_USER, self::TEST_DB_PASSWORD]); } @@ -88,7 +88,7 @@ public function testErrorPdo() $dsn = 'mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=3306'; $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = Config::initialize('pdo', [$dsn]); } @@ -102,7 +102,7 @@ public function test__callPdo() $dsn = 'mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=3306'; $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[does not exist]/'); + $this->expectExceptionMessageMatches('/[does not exist]/'); $settings = new Config('pdo', [$dsn, self::TEST_DB_USER, self::TEST_DB_PASSWORD]); $settings->getNotAnProperty(); } @@ -145,7 +145,7 @@ public function testErrorPgsql() } $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = Config::initialize('pgsql', [self::TEST_DB_USER, self::TEST_DB_PASSWORD]); } @@ -185,7 +185,7 @@ public function testErrorSqlsrv() } $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = new Config('sqlsrv', [self::TEST_DB_USER, self::TEST_DB_PASSWORD]); } @@ -224,21 +224,21 @@ public function testErrorSqlite3() } $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = new Config('sqlite3', [self::TEST_SQLITE_DB_DIR]); } public function test_construct() { $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = new Config('', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); } public function test_constructArgs() { $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details to connect to database]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details to connect to database]/'); $settings = new Config('mysqli'); } } diff --git a/tests/DInjectorTest.php b/tests/DInjectorTest.php index f92cfb6..849405d 100644 --- a/tests/DInjectorTest.php +++ b/tests/DInjectorTest.php @@ -52,7 +52,7 @@ public function testAutoWire_Error() { $container = new DInjector(); $this->expectException(ContainerException::class); - $this->expectExceptionMessageRegExp('/[is not instantiable]/'); + $this->expectExceptionMessageMatches('/[is not instantiable]/'); $baz = $container->autoWire('ezsql\Tests\Baz'); } @@ -70,7 +70,7 @@ public function testGet_Error() { $container = new DInjector(); $this->expectException(NotFoundException::class); - $this->expectExceptionMessageRegExp('/[does not exists]/'); + $this->expectExceptionMessageMatches('/[does not exists]/'); $baz = $container->get('Baz'); } } diff --git a/tests/DatabaseTest.php b/tests/DatabaseTest.php index dcdd9b2..a163c3a 100644 --- a/tests/DatabaseTest.php +++ b/tests/DatabaseTest.php @@ -105,7 +105,7 @@ public function testInitialize_Pdo() public function testInitialize_Error() { $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[Missing configuration details]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details]/'); $mysqli = Database::initialize('', [self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); } } diff --git a/tests/ezSchemaTest.php b/tests/ezSchemaTest.php index d7757f2..a322f30 100644 --- a/tests/ezSchemaTest.php +++ b/tests/ezSchemaTest.php @@ -104,7 +104,7 @@ public function test__call_Error() $this->assertFalse(column('id', INTR, 32, AUTO, PRIMARY)); $db = mysqlInstance([self::TEST_DB_USER, self::TEST_DB_PASSWORD, self::TEST_DB_NAME]); $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/[does not exist]/'); + $this->expectExceptionMessageMatches('/[does not exist]/'); $this->assertNull(column('id', 'DOS', 32)); } diff --git a/tests/ezsqlModelTest.php b/tests/ezsqlModelTest.php index 55c28d0..c01ba64 100644 --- a/tests/ezsqlModelTest.php +++ b/tests/ezsqlModelTest.php @@ -43,7 +43,7 @@ public function testSetCache_Timeout() public function testGetNotProperty() { $this->expectException(\Exception::class); - $this->expectExceptionMessageRegExp('/does not exist/'); + $this->expectExceptionMessageMatches('/does not exist/'); $res = $this->object->getNotProperty(); } diff --git a/tests/mysqli/mysqliTest.php b/tests/mysqli/mysqliTest.php index 8761817..9374784 100644 --- a/tests/mysqli/mysqliTest.php +++ b/tests/mysqli/mysqliTest.php @@ -616,7 +616,7 @@ public function testQuery_prepared() public function test__construct_Error() { - $this->expectExceptionMessageRegExp('/[Missing configuration details]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details]/'); $this->assertNull(new ez_mysqli()); } diff --git a/tests/pdo/pdo_mysqlTest.php b/tests/pdo/pdo_mysqlTest.php index a46f2a2..e6f48a4 100644 --- a/tests/pdo/pdo_mysqlTest.php +++ b/tests/pdo/pdo_mysqlTest.php @@ -293,9 +293,9 @@ public function testJoins() $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; @@ -316,8 +316,8 @@ public function testJoins() --$o; } - $this->assertEquals(0, $this->object->query('DROP TABLE unit_test')); - $this->assertEquals(0, $this->object->query('DROP TABLE unit_test_child')); + $this->assertEquals(0, $this->object->drop('unit_test')); + $this->assertEquals(0, $this->object->drop('unit_test_child')); } public function testBeginTransactionCommit() @@ -443,7 +443,7 @@ public function testQuery_prepared() public function test__Construct_Error() { - $this->expectExceptionMessageRegExp('/[Missing configuration details]/'); + $this->expectExceptionMessageMatches('/[Missing configuration details]/'); $this->assertNull(new ez_pdo()); } diff --git a/tests/pdo/pdo_pgsqlTest.php b/tests/pdo/pdo_pgsqlTest.php index 58a91eb..f08eef0 100644 --- a/tests/pdo/pdo_pgsqlTest.php +++ b/tests/pdo/pdo_pgsqlTest.php @@ -215,9 +215,9 @@ public function testJoins() $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; diff --git a/tests/pdo/pdo_sqliteTest.php b/tests/pdo/pdo_sqliteTest.php index 2cc1348..fc49a5f 100644 --- a/tests/pdo/pdo_sqliteTest.php +++ b/tests/pdo/pdo_sqliteTest.php @@ -244,9 +244,9 @@ public function testJoins() $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1; diff --git a/tests/pdo/pdo_sqlsrvTest.php b/tests/pdo/pdo_sqlsrvTest.php index de8e82b..d9a52cb 100644 --- a/tests/pdo/pdo_sqlsrvTest.php +++ b/tests/pdo/pdo_sqlsrvTest.php @@ -219,9 +219,9 @@ public function testJoins() $this->object->insert('unit_test', array('id' => '2', 'test_key' => 'testing 2')); $this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3')); $this->object->query('CREATE TABLE unit_test_child(child_id integer, child_test_key varchar(50), parent_id integer, PRIMARY KEY (child_id))'); - $this->object->insert('unit_test', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); - $this->object->insert('unit_test', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); - $this->object->insert('unit_test', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); + $this->object->insert('unit_test_child', array('child_id' => '1', 'child_test_key' => 'testing child 1', 'parent_id' => '3')); + $this->object->insert('unit_test_child', array('child_id' => '2', 'child_test_key' => 'testing child 2', 'parent_id' => '2')); + $this->object->insert('unit_test_child', array('child_id' => '3', 'child_test_key' => 'testing child 3', 'parent_id' => '1')); $result = $this->object->selecting('unit_test_child', '*', leftJoin('unit_test_child', 'unit_test', 'parent_id', 'id')); $i = 1;