Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit and CodeIgniter

for a couple of days I'm trying to get PHPUnit working with Codeigniter in PHPStorm. I've installed PHPUnit via Composer and this seems to work fine on simple unit tests which don't involve CodeIgniter.

I've followed a (simple) guide on how to set up PHPUnit with Codeigniter in an IDE, found here: http://www.jamesfairhurst.co.uk/posts/view/codeigniter_phpunit_and_netbeans

But the debugger in PHPStorm keeps returning the same error, the HTML and CSS of the 404 page (of codeigniter) and 'Process finished with exit code 0'. The same goes when trying to run from the Terminal.

As described in the guide I've set up an .xml configuration file for PHPUnit wich loads an bootstrap file which should initialise Codeigniter.

<phpunit bootstrap="bootstrap.php"
     colors="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnFailure="false"
     syntaxCheck="false"
     verbose="true">
</phpunit>

I'm quite lost right now, how can I make PHPUnit work with Codeigniter in PHPStorm? I'm suspecting it has something to do with the output class. But then again, I'm new to PHPUnit and just recently started with CodeIgniter.

Any help would be welcome!

like image 546
Sander Avatar asked Jan 16 '14 10:01

Sander


People also ask

What is unit testing in CodeIgniter?

Unit testing is an approach to software development in which tests are written for each function in your application. If you are not familiar with the concept you might do a little googling on the subject. CodeIgniter's Unit Test class is quite simple, consisting of an evaluation function and two result functions.

Which testing tool is used to test the code through the controller?

withURI(string $uri) This is helpful if you need to check URI segments within your controller. The only parameter is a string representing a valid URI: <? php $results = $this->withURI('http://example.com/forums/categories') ->controller(\App\Controllers\ForumController::class) ->execute('showCategories');

What is the purpose of unit testing?

The main objective of unit testing is to isolate written code to test and determine if it works as intended. Unit testing is an important step in the development process, because if done correctly, it can help detect early flaws in code which may be more difficult to find in later testing stages.


1 Answers

First of all, I feel like a real idiot. Here's how I fixed my problem:

  1. Updated XAMPP. I had PHP 5.3.1, while 5.3.3 was required for PHPUnit.
  2. I followed this guide in detail: http://www.jamesfairhurst.co.uk/posts/view/codeigniter_phpunit_and_netbeans

The guide is written for netbeans, but works (almost) the same as PHPStorm. Works like a charm now!

like image 122
Sander Avatar answered Sep 19 '22 04:09

Sander