From dfa52f3ed31696c58fdc85273f4408559233b19e Mon Sep 17 00:00:00 2001 From: Gabriel Caruso Date: Fri, 8 Dec 2017 17:25:02 -0200 Subject: Refactoring tests --- tests/codeigniter/libraries/Encryption_test.php | 4 ++-- .../codeigniter/libraries/Form_validation_test.php | 4 ++-- tests/codeigniter/libraries/Table_test.php | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'tests/codeigniter/libraries') diff --git a/tests/codeigniter/libraries/Encryption_test.php b/tests/codeigniter/libraries/Encryption_test.php index 99c5d4b9d..8e411d9fa 100644 --- a/tests/codeigniter/libraries/Encryption_test.php +++ b/tests/codeigniter/libraries/Encryption_test.php @@ -151,7 +151,7 @@ class Encryption_test extends CI_TestCase { 'hmac_key' => str_repeat("\x0", 16) ); - $this->assertTrue(is_array($this->encryption->__get_params($params))); + $this->assertInternalType('array', $this->encryption->__get_params($params)); $params['base64'] = TRUE; $params['hmac_digest'] = 'sha512'; @@ -257,7 +257,7 @@ class Encryption_test extends CI_TestCase { return $this->markTestSkipped('ext/mcrypt is deprecated since PHP 7.1 and will generate notices here.'); } - $this->assertTrue(is_resource($this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc'))); + $this->assertInternalType('resource', $this->encryption->__driver_get_handle('mcrypt', 'rijndael-128', 'cbc')); } // -------------------------------------------------------------------- diff --git a/tests/codeigniter/libraries/Form_validation_test.php b/tests/codeigniter/libraries/Form_validation_test.php index 90dd721a3..04bd670ad 100644 --- a/tests/codeigniter/libraries/Form_validation_test.php +++ b/tests/codeigniter/libraries/Form_validation_test.php @@ -374,7 +374,7 @@ class Form_validation_test extends CI_TestCase { $this->form_validation->run(); $error_msg = $this->form_validation->error('foo'); - $this->assertTrue(strrpos($error_msg, $prefix) === 0); + $this->assertStringStartsWith($prefix, $error_msg); $this->assertTrue(strrpos($error_msg, $suffix, -strlen($suffix)) === (strlen($error_msg) - strlen($suffix))); $_POST = array(); @@ -489,7 +489,7 @@ class Form_validation_test extends CI_TestCase { $this->form_validation->set_data($data); $valid = $this->form_validation->run('', $data); - $this->assertEquals(TRUE, $valid); + $this->assertTrue($valid); $this->assertEquals('Dick', $data['person']['firstname']); $this->assertEquals('Tracy', $data['person']['lastname']); } diff --git a/tests/codeigniter/libraries/Table_test.php b/tests/codeigniter/libraries/Table_test.php index 8e7452474..f505a43fc 100644 --- a/tests/codeigniter/libraries/Table_test.php +++ b/tests/codeigniter/libraries/Table_test.php @@ -67,7 +67,7 @@ class Table_test extends CI_TestCase { $this->table->add_row('your', 'pony', 'stinks'); $this->table->add_row('my pony', '>', 'your pony'); - $this->assertEquals(count($this->table->rows), 3); + $this->assertCount(3, $this->table->rows); $this->assertEquals( array( @@ -188,8 +188,8 @@ class Table_test extends CI_TestCase { } $this->assertFalse($this->table->auto_heading); - $this->assertEquals(count($this->table->heading), 3); - $this->assertEquals(count($this->table->rows), 2); + $this->assertCount(3, $this->table->heading); + $this->assertCount(2, $this->table->rows); $this->table->clear(); @@ -213,7 +213,7 @@ class Table_test extends CI_TestCase { $this->table->clear(); $this->table->set_from_array($data); - $this->assertEquals(count($this->table->rows), 2); + $this->assertCount(2, $this->table->rows); $expected = array( array('data' => 'name'), @@ -270,14 +270,14 @@ class Table_test extends CI_TestCase { $table = $this->table->generate($data); // Test the table header - $this->assertTrue(strpos($table, 'Name') !== FALSE); - $this->assertTrue(strpos($table, 'Color') !== FALSE); - $this->assertTrue(strpos($table, 'Size') !== FALSE); + $this->assertContains('Name', $table); + $this->assertContains('Color', $table); + $this->assertContains('Size', $table); // Test the first entry - $this->assertTrue(strpos($table, 'Fred') !== FALSE); - $this->assertTrue(strpos($table, 'Blue') !== FALSE); - $this->assertTrue(strpos($table, 'Small') !== FALSE); + $this->assertContains('Fred', $table); + $this->assertContains('Blue', $table); + $this->assertContains('Small', $table); } } @@ -297,4 +297,4 @@ class DB_result_dummy extends CI_DB_result array('name' => 'Foo Bar', 'email' => 'foo@bar.com') ); } -} \ No newline at end of file +} -- cgit v1.2.3-24-g4f1b