I have written an action which create a temporary file and returned it with a BinaryFileResponse and delete it after. Something like this : $response = new BinaryFileResponse($this->getFile($…
Tag: phpunit
Laravel / PHPUnit: Asserting sameness of two models
When integration testing (using a database) in Laravel. What is the best way to assert that two instances of the same Eloquent model are the same? AssertEquals $model $model Simply using ->assertEquals($modelOne, $modelTwo); wont work as even if they are the same PHPUnit checks class properties such as was…
How to write a PHP unit test for a method that uses live database data?
How exactly do I write a test for a method that uses live database? Consider this code: I have A LOT of methods like the one above, and so I want to ensure that my tests are solid and will not change when the database data changes. I am looking for advice/solution towards best-in-class unit testing method and…
Forward slash in Bash on Mac
I have this bash(version 3.2 on MacOS) function What it’s suppose to do is run phpunit with proper regex, here i am converting * to (.)* and wrapping filter to be case insensitive. Now The problem is that parsed command works perfectly fine(matched test cases run), when i run directly at terminal. But i…
500 status code for symfony functional test
I’m performing a test just to see if a certain route is working. The page/route is found at http://localhost/login and when I go there in the browser it works fine and I’ve tested this with no cookies and my cache cleared. However, as soon as I test it in the phpunit LoginControllerTest class I re…
Run only one unit test from a test suite in laravel
Using phpunit command Laravel will run all unit tests in our project. How to run one or specific Unit Tests in Laravel 5.1? I just want to run testFindToken from my test suite. Answer Use this command to run a specific test from your test suite. If you want to be more specific about your file then pass the fi…
Laravel : phpunit cannot open file ExampleTest.php
Hi i am quit new in Laravel PHPUnit, getting the following error : I don’t have idea why i am getting this error. I installed PHPUnit globally and when i run “phpunit” in terminal it runs fine. But I want to run it on specific file like : Thanks In Advance. Answer Make sure you are on the pr…
Run one file or map in phpunit
I’m using laravel and I’ve written some test files. But how can I exec only one file? When I do for example: phpunit tests/resulttesting/school/deleteSchoolForRealTest It throws an error: Cannot …
How can I filter by “ends with” using PHPUnit’s –filter option?
I’m trying to filter a PHPUnit test suite. When I try to filter by test name using –filter, the tests that exactly match the specified string are executed, but so are any tests that begin with the string. eg. If I have two tests, testExample and testExampleTwo, the following runs both tests: How c…
PHP Mocking Final Class
I am attempting to mock a php final class but since it is declared final I keep receiving this error: PHPUnit_Framework_Exception: Class “DoctrineORMQuery” is declared “final” and cannot be mocked. Is there anyway to get around this final behavior just for my unit tests without introdu…