Welcome Guest, Not a member yet? Register   Sign In
Poll: CI4: Easier way to create app tests?
You do not have permission to vote in this poll.
yes
75.86%
22 75.86%
no
13.79%
4 13.79%
maybe
10.34%
3 10.34%
Total 29 vote(s) 100%
* You voted for this item. [Show Results]

Application tests?
#1

<<From Orionstar>>

CI should encourage application tests. To make the life of the devs easier CI should provide mocks for the system files and an easy way to create application tests with PHPUnit and these should be bundled into the downloadable versions.
James Parry
Project Lead
Reply
#2

PHPUnit is good!

https://github.com/fmalk/codeigniter-phpunit
Reply
#3

yes, mock system must be created so we can test our code easily..
Reply
#4

For example, `rediret()` in URL helper calls `exit()`. So we can't test code using `redirect()`. It stops phpunit itself.

To solve this problem, when we provide a mock for it, what shall we do `MY_url_helper.php`?
As you know if user has `MY_url_helper.php`, `redirect()` in `MY_url_helper.php` is used.

If we override `redirect()` in `MY_url_helper.php`, the changes he/she made is gone.
If `MY_url_helper.php` overrides the mock, phpunit stops with `exit()`.

This an example of `exit()` problem. I don't know how to solve it.

Any idea?
Reply
#5

@kenjis

What kind of result do you expect to be returned from a controller? Even there is no the so-called 'exit' problem, what is the common way to check whether a controller passes the test?

An ordinary controller method that simply shows a page simply puts something within the output buffer and then returns NULL. What is to be checked here?
Reply
#6

> What kind of result do you expect to be returned from a controller?

At least, I exptect a controller never terminate phpunit.

How do you test a controller like this? https://github.com/kenjis/ci-app-for-ci-...direct.php

CI's redirect() calls exit() and terminates phpunit.

> An ordinary controller method that simply shows a page simply puts something within the output buffer and then returns NULL. What is to be checked here?

The output buffer and/or returned value.
Reply
#7

I don't know how useful is to evaluate the HTML output within the buffer, determine for sure whether it is good or bad would be problematic. Logic to be tested is easier to be within models and libraries while the controller is the glue, as simple as possible. Anyway...

A fake (loaded before the normal) function redirect() for testing can be created. Inside this new function header(...) is omited or faked, ok. Then exit; statement stays as a problem.

If exit is simply replaced by return, then within the controller code execution will continue wrongly. Yet another return is needed for finishing contoller method execution immediately. This means that inside the fake function redirect(), at the end there should be code that removes the last position from the stack. I don't know how this manipulation can be done. For illustration here is a RFC that proposes how to return with skipping stack levels http://www.serverphorums.com/read.php?7,1163989 Somehow implemented, this effect might be the solution.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB