In some of my tests, I have a user model I have created and I run some methods that need to save certain attributes. In rails, I would typically call something like user.reload which would repopulate the attributes from the database. Is there a way in laravel to do that? I read through the api and couldn’t find a method
Tag: unit-testing
Should I be unit testing every piece of code
I have been starting unit testing recently and am wondering, should I be writing unit tests for 100% code coverage? This seems futile when I end up writing more unit testing code than production code. I am writing a PHP Codeigniter project and sometimes it seems I write so much code just to test one small function. For Example this
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 …
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
PHP and unit testing assertions with decimals
I have a method that returns a float like 1.234567890.I want to test that it really does so. However, it seems that this returned float has different precision on different platforms so how do I …
Best practices to test protected methods with PHPUnit
I found the discussion on Do you test private method informative. I have decided, that in some classes, I want to have protected methods, but test them. Some of these methods are static and short. Because most of the public methods make use of them, I will probably be able to safely remove the tests later. But for starting with