• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TOAST and CI 3

#1
Hi,

I am trying to use TOAST to perform Unit Testing with a lightweight library.

I have managed to get it to work, but I still have a couple of questions (which more CI related than pure TOAST).

Here is an example of a class (don't look at the test ... it's just for testing ;-) TOAST):
PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

require_once(
APPPATH '/controllers/test/Toast.php');
require_once(
APPPATH '/controllers/Calendrier.php'); //Require the tested class's file

class Calendrier_test extends Toast
{
 private 
$theController;
 function 
__construct() {
 
parent::__construct(__FILE__);
 
$this->theController = new Calendrier(true); //Instantiate class
 
}
 function 
_pre() {
 
//Prepare unit test user database entry
 
}

 function 
test_index() {
 
$this->load->model('Reservation_model');
 
$theCount 0;$this->message '';
 foreach (
$this->theController->Reservation_model->getAllResType() as $row) {
 
$this->message .= ' val = ' $row->typ_nm
 
$theCount++;
 }
 
$this->message .= '  $theCount = ' $theCount
 
$this->_assert_equals($theCount2);
 }

 function 
_post() {
 
//Remove unit test office from database
 
}
}
?>

First of all in autoload.php I have this line:
PHP Code:
$autoload['libraries'] = array('database' ,'firePHP''ion_auth'); 
But I had to remove the last 2 libs as they won't get loaded, I get the error message :
Quote:Severity: Error
Message: Class 'CI_FirePHP' not found
Filename: core/Common.php
Line Number: 196
Any idea on how to fix this ?

One thing that I don't understand, is that I have to instantiate the controler (with variable $theControler) and to load the model !
I understand that I need to load the model, but then, why I can not write :
PHP Code:
$this->Reservation_model->getAllResType() 
(this generates the following error :
Quote:Severity: Notice
Message: Undefined property: Calendrier_test::$Reservation_model
Filename: test/Calendrier_test.php
)

And last but not least, the Toast_all method generates an error 403 You don't have permission to access /test/Calendrier_test/show_results . Permissions were set to 777 for all directories and files and I still get the error. The Toast_all is using curl.
I have asked the maintainer but I am asking here too ... just in case.


Thanks in advance for any reply (even for only one of the points),
L@u
Reply

#2
I've fixed the Toast_all URL problem (related to the way CURL was called).

The two others problem are related to the way controler/model are tested and the tested class being instantiated in the constructor.

I am hoping to get a good example of doing this, but if someone has an example of testing classes, it will be great.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.