I have this code in my __construrct: Now, when i’m unit testing i know that i can mock Guard and pass it’s mock to $auth, but how can i mock dbUserService ? it’s instantiated trough the IoC container. Answer You can use the instance() method of the IoC container to mock any class instanciated with make():
Tag: phpunit
PHPUnit: “Class ‘Eloquent’ not found” when using @dataProvider
I’m running into an issue when writing unit tests with PHPUnit using @dataProvider in a Laravel app. The error I’m receiving is: PHP Fatal error: Class ‘Eloquent’ not found in /path/to/project/app/…
Laravel – Testing what happens after a redirect
I have a controller that after submitting a email, performs a redirect to the home, like this: I am writing the tests for it, and I am not sure how to make phpunit to follow the redirect, to test the success message: If I substitute the code on the controller for this, and I remove the first 2 asserts, it
Set Expected Exception in Codeception Functional Cept
I want to do something like: In a functional cept. Any chance to do so? Above code will work in isolation but if I run codecept run, the tests get stuck once the test with the expected exception is complete. Here’s my setup: YML: Answer I think this is a known problem with the Laravel 4 module for codeception, not
Run test in phpunit with specific php version
I have installed multiple PHP versions on my Mac and want to run unit-tests against a specific PHP version (or against multipls versions) Here’s the php versions I have: My test case looks like this: When I run the test I get this response: How can I run the tests with the php version 5.2.17? Update: I discover that PHPUnit
PHPUnit assert no method is called
I have a ClassA that uses a ServiceB. In a certain case, ClassA should end up not invoking any methods of ServiceB. I now want to test this and verity no methods are indeed called. This can be done …
Fatal Error – Too many open files
I try to run PHPUnit Tests in my new machine and I get this error: PHP Fatal error: Uncaught exception ‘UnexpectedValueException’ with message ‘RecursiveDirectoryIterator::__construct(/usr/lib/php/pear/File/Iterator): failed to open dir: Too many open files’ in /usr/lib/php/pear/File/Iterator/Factory.php:114 The same code on the old machine run well… New machine environment: PHP Version: PHP 5.3.21 (cli) Older: PHP 5.3.14 PHPUnit output every time: Answer This
Non-testable base class extending PHPUnit_Framework_TestCase
Summary How can I create a base class that extends PHPUnit_Framework_TestCase and use that for subclassing actual test cases, without having the base class itself tested by PHPUnit? Further …
How to output in CLI during execution of PHP Unit tests?
When running a PHPUnit test, I would like to be able to dump output so I can debug one or two things. I have tried the following (similar to the PHPUnit Manual example); With the following result: Notice there is none of the expected output. I’m using the HEAD versions of the git repos as of September 19th, 2011. Output
PHPUnit: expects method meaning
When I create a new mock I need to call the expects method. What exactly it does? What about its arguments? I can’t find the reason anywhere (I’ve tried docs). I’ve read the sources but I can’t understand it. Answer expects() – Sets how many times you expect a method to be called: If you know, that method is called