phpunit

Why is PHPUnit ignoring assertions when expecting an exception?

I have a simple unit test case (extensive question here) on a configuration class that by design triggers PHP errors on type mismatches and undefined configuration settings. In addition to the error, the method is exited returning false. In my test case, I want to have a number of tests that fail. Trouble is, I can't do a simple 'assert...

phpunit and autoloader

I'm trying to use autoloader with phpunit this way: in phpunit.xml I put bootstrap="bootstrap.php" in bootstrap.php I put define( 'TESTING', true ); putenv( 'APPLICATION_ENV=testing' ); function __autoload($className) { include_once __autoloadFilename($className); } function __autoloadFilename($className) { return...

"Web interface" to PHPUnit tests?

Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result. I develop web applications, and the day-to-day workflow usually switches between the IDE and the browser. I would like to have the unit testing in the same environment. ...

How to use PHPunit's Database Test Case Methods of Query to compare with doctrine query

How to use PHPunit's Database Test Case Methods of Query to compare with doctrine query i m using phpunit with doctrine framework .. i want to test my doctrine query with phpunit query with using phpunit framework methods.. any buddy with Doctrine Query and PhpUnit Query plz Contact... //Bhavin Rana. ...

Code coverage with phpunit; can't get to one place.

In the xdebug code coverage, it shows the line "return false;" (below "!$r") as not covered by my tests. But, the $sql is basically hard-coded. How do I get coverage on that? Do I overwrite "$table" somehow? Or kill the database server for this part of the test? I guess this is probably telling me I'm not writing my model very well,...

How to mock test a web service in PHPUnit across multiple tests?

I am attempting to test a web service interface class using PHPUnit. Basically, this class makes calls to a SoapClient object. I am attempting to test this class in PHPUnit using the "getMockFromWsdl" method described here: http://www.phpunit.de/manual/current/en/test-doubles.html#test-doubles.stubbing-and-mocking-web-services However,...

PHPUnit: force display of asserted values

When in PHPUnit test fails, actual and expected values are displayed. But when the test passes, this information is not displayed. How to force PHPUnit to always display expected and actual assertion result? ...

phpunit - generate tests for all the classes from a directory

Hi! I have a directoy structure, and all the classes of the business logic are placed in the app_dir/lib/ directory. I would like to generate unit tests for all the classes from this lib/ folder. The problem is, that I haven't found any option to specify the source directory, only the source file: from app_dir: phpunit --skeleton-c...

PHPUnit - multiple stubs of same class

I'm building unit tests for class Foo, and I'm fairly new to unit testing. A key component of my class is an instance of BarCollection which contains a number of Bar objects. One method in Foo iterates through the collection and calls a couple methods on each Bar object in the collection. I want to use stub objects to generate a serie...

Zend_Test_PHPUnit_ControllerTestCase: Test view parameters and not rendered output

Hi, I'm using Zend_Test_PHPUnit_ControllerTestCase to test my controllers. This class provides various ways to test the rendered output, but I don't want to get my view scripts involved. I'd like to test my view's vars. Is there a way to access to the controllers view object? Here is an example, what I'm trying to do: <?php class Contr...

Getting a "No default module defined for this application" exception while running controller unit tests in zend framework

I have an application with the default directory structure, for an application without custom modules (see structure figure at the end). I have written a ControllerTestCase.php file as instructed in many tutorials, and I've created the appropriate bootstrap file as well (once again, see figures at the end). I've written some model te...

Unit testing file operations - where to maintain mock directory structure?

I'm still new to Unit testing, and specifically PHPUnit as the testing framework. Suppose I'm building a unit test for a resource loader class. The class looks for resources to load in two directories (a global and a user-specific one). To test the class, I would like to set up a mock testing directory containing some resource files. I...

Finding patterns of failure in a Unit Test

I'm new to Unit Testing, and I'm only getting into the routine of building test suites. I have what is going to be a rather large project that I want to build tests for from the start. I'm trying to figure out general strategies and patterns for building test suites. When you look at a class, many tests come to you obviously due to the ...

Unit Testing Codeigniter Classes with fooStack - clashes

I'm having 'fun' testing interactions in a CodeIgniter based web app. It seems when running the entire test suite "phpunit AllTests.php" it loads all of the test classes, their targets (Systems under Test) and creates a PHPUnit_Framework_TestSuite instance which presumably iterates over the classes which extend CIUnit_TestCase and runs ...

PHPUnit and autoloaders: Determining whether code is running in test-scope?

Premise I know that writing code to act differently when a test is run is hilariously bad practise, but I may've actually come across a scenario in which it may be necessary. Specifically, I'm trying to test a very specific wrapper for HTML Purifier in the Zend framework - a View Helper, to be exact. The HTML Purifier autoloader is nec...

Stub PHP native methods

In my unit test, i'm looking to stub the behaviour of php's inbuilt file_get_contents() method. Is there a way to stub native methods in PHP (such as file_get_contents() or print_r()) and the likes? ...

Unit Test json output in Zend Framework

The Zend Tutorial lists many assertions to check the output generated by a request. http://framework.zend.com/manual/en/zend.test.phpunit.html But they all seem to assume that the output is html. I need to test json output instead. Are there any assertions helpful to check json, or is there at least a generic way to make assertions ag...

PHPUnit doesn't recognize file_exists()

I've set up a project with unit test files in NetBeans. I set bootstrap to C:\www\foo\_tests\TestAutoload.php and put simple autoload method to this file: function __autoload( $class_name ) { // series of ifs if ( ... ) { $file_name = ... } if ( file_exists ( $file_name ) ) { require_once( $file_name ); ...

echo command not found while testing selenium with phpunit

I am getting an ERROR: Unknown command: 'echo' executing a selenium script with phpunit. Based on the output that echo command should be included in my version of PHPUnit. The selenium script does execute successfully in the firefox selenium IDE. mkdir_build: phpunit: [exec] PHPUnit 3.4.12 by Sebastian Bergmann. [exec] ...

How can I access global variables inside PHPUnit 3.4.9?

I'm trying to write tests for some legacy code with PHPUnit 3.4.9, but it seems that all my global variables are invisible. How can I access global variables inside PHPUnit 3.4.9? ...