Permalink
Browse files

Replaced evals with getMock usage in Loader tests

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
1 parent c2f59ef commit 8889db7e1b1768ecfb76e9e73598541042a9edc1 @dchill42 committed Oct 23, 2012
Showing with 8 additions and 16 deletions.
  1. +8 −16 tests/codeigniter/core/Loader_test.php
@@ -264,15 +264,12 @@ public function test_load_view()
$this->assertEquals($content.$value, $out);
// Mock output class
- $class = 'Mock_Load_Output';
- $prop = 'output';
- eval('class '.$class.' { public function append_output($out) { $this->'.$prop.' = $out; } }');
- $this->ci_instance_var('output', new $class());
+ $output = $this->getMock('CI_Output', array('append_output'));
+ $output->expects($this->once())->method('append_output')->with($content.$value);
+ $this->ci_instance_var('output', $output);
// Test view output
- $this->load->view($view, array($var => $value));
- $this->assertObjectHasAttribute($prop, $this->ci_obj->output);
- $this->assertEquals($content.$value, $this->ci_obj->output->$prop);
+ $this->assertNull($this->load->view($view, array($var => $value)));
}
// --------------------------------------------------------------------
@@ -397,17 +394,12 @@ public function test_loading_multiple_helpers()
public function test_language()
{
- // Create mock Lang class with load stub
- $class = 'Mock_Load_Lang';
- $prop = '_file';
- eval('class '.$class.' { public function load($file, $lang) { $this->'.$prop.' = $file; } }');
- $this->ci_instance_var('lang', new $class());
-
- // Does the right file get loaded?
+ // Mock lang class and test load call
$file = 'test';
+ $lang = $this->getMock('CI_Lang', array('load'));
+ $lang->expects($this->once())->method('load')->with($file);
+ $this->ci_instance_var('lang', $lang);
$this->assertNull($this->load->language($file));
- $this->assertObjectHasAttribute($prop, $this->ci_obj->lang);
- $this->assertEquals($file, $this->ci_obj->lang->$prop);
}
// --------------------------------------------------------------------

0 comments on commit 8889db7

Please sign in to comment.