From fe4c76e77bc9640872d34a874780031cf90dd2bd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 9 Nov 2015 12:55:07 +0200 Subject: Merge pull request #4225 from zhanghongyi/loader-test Improve Loader test cases for libraries --- tests/codeigniter/core/Loader_test.php | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index 889ab92e4..db5088d80 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -48,11 +48,9 @@ class Loader_test extends CI_TestCase { // Test a string given to params $this->assertInstanceOf('CI_Loader', $this->load->library($lib, ' ')); - // Create library w/o class - $lib = 'bad_test_lib'; - $this->ci_vfs_create($lib, '', $this->ci_base_root, 'libraries'); + // test non existent lib + $lib = 'non_existent_test_lib'; - // Test non-existent class $this->setExpectedException( 'RuntimeException', 'CI Error: Unable to load the requested class: '.ucfirst($lib) @@ -62,6 +60,19 @@ class Loader_test extends CI_TestCase { // -------------------------------------------------------------------- + public function test_bad_library() + { + $lib = 'bad_test_lib'; + $this->ci_vfs_create(ucfirst($lib), '', $this->ci_app_root, 'libraries'); + $this->setExpectedException( + 'RuntimeException', + 'CI Error: Non-existent class: '.ucfirst($lib) + ); + $this->assertInstanceOf('CI_Loader', $this->load->library($lib)); + } + + // -------------------------------------------------------------------- + public function test_library_extension() { // Create library and extension in VFS @@ -131,6 +142,16 @@ class Loader_test extends CI_TestCase { // Test is_loaded $this->assertEquals($obj, $this->load->is_loaded(ucfirst($lib))); + + // Test to load another class with the same object name + $lib = 'another_test_lib'; + $class = ucfirst($lib); + $this->ci_vfs_create(ucfirst($lib), 'ci_app_root, 'libraries'); + $this->setExpectedException( + 'RuntimeException', + "CI Error: Resource '".$obj."' already exists and is not a ".$class." instance." + ); + $this->load->library($lib, NULL, $obj); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 878e23f8883b2510d573850deb7dca5761cc1848 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 10 Aug 2016 15:15:49 +0300 Subject: Use getMockBuilder() in PHPUnit instead of the deprecated getMock() --- tests/codeigniter/core/Loader_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index db5088d80..c1c4997c4 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -291,7 +291,7 @@ class Loader_test extends CI_TestCase { $this->assertEquals($content.$value, $out); // Mock output class - $output = $this->getMock('CI_Output', array('append_output')); + $output = $this->getMockBuilder('CI_Output')->setMethods(array('append_output'))->getMock(); $output->expects($this->once())->method('append_output')->with($content.$value); $this->ci_instance_var('output', $output); @@ -441,7 +441,7 @@ class Loader_test extends CI_TestCase { { // Mock lang class and test load call $file = 'test'; - $lang = $this->getMock('CI_Lang', array('load')); + $lang = $this->getMockBuilder('CI_Lang')->setMethods(array('load'))->getMock(); $lang->expects($this->once())->method('load')->with($file); $this->ci_instance_var('lang', $lang); $this->assertInstanceOf('CI_Loader', $this->load->language($file)); -- cgit v1.2.3-24-g4f1b From fa986fe738363069d8ae331f0ae331521cd895d3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 10 Jan 2017 12:22:05 +0200 Subject: Add a testcase and changelog entry for #4975 --- tests/codeigniter/core/Loader_test.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/codeigniter/core/Loader_test.php') diff --git a/tests/codeigniter/core/Loader_test.php b/tests/codeigniter/core/Loader_test.php index c1c4997c4..241c415b3 100644 --- a/tests/codeigniter/core/Loader_test.php +++ b/tests/codeigniter/core/Loader_test.php @@ -295,8 +295,10 @@ class Loader_test extends CI_TestCase { $output->expects($this->once())->method('append_output')->with($content.$value); $this->ci_instance_var('output', $output); - // Test view output - $this->assertInstanceOf('CI_Loader', $this->load->view($view, array($var => $value))); + // Test view output and $vars as an object + $vars = new stdClass(); + $vars->$var = $value; + $this->assertInstanceOf('CI_Loader', $this->load->view($view, $vars)); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b