2

I'm testing out some models from a CodeIgniter project via CLI, the method in question has two arguments:

public function get_questions_from_block($block_name, $return_array = FALSE)

I have tried this:

php index.php test_controller get_question_block_name example_block TRUE

but it returns 0 or FALSE. How do I pass multiple arguments through CLI ? Do I have to use :

$_SERVER['argv'];  

to get all the arguments? Or is there an easier way?

1 Answer 1

1

You can use getopt() rather than $_SERVER['argv']

But in this case, I don't think that will help you (without heavy code modification).

Perhaps you should check out the unit-test class that CI provides.

In that, you could simply run a series of tests against your model by doing something like the following in a separate unit testing file:

$this->load->model('test_model');
$this->unit->run(
    $this->test_model->get_questions_from_block(args),
    $expected_behavior /* what should be returned */,
    $test_name /* name your test */
);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for that, I really should be writing unit-tests on this piece of code anyway, It's great that codeigniter has a unit-test class shipped with the framework.
You can always use PHPUnit too. Personal preference I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.