We’re having an issue with PHPUnit sometimes failing to correctly run our test suite in CI. The behaviour manifests as roughly 1/3 tests failing to start and the CI step timing out. Interestingly enough, we don’t see this behaviour: Locally on our machines Every time we run the tests Occur with the dusk tests Our setup is to run the
Tag: unit-testing
Testing method which need log in
I want to testing some method like user (method need log in user). $user = User::find(1); $response = $this->actingAs($user)->json(‘POST’, ‘/store/post’, [ ‘title’ => ‘Hello …
Having issue with Symfony 3 Unit testing that has session enabled
I am new in unit testing. I have Symfony 3 console command application which is using symfony session for temporary data store. In my unit test class I extend KernelTestCase which give me error while I tested it but if I extend SymfonyComponentHttpKernelEventListenerTestSessionListener class then the error gone and passed the test. After some time I realize that it always
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 one that
How to mock properly IlluminateHttpRequest class from Laravel
I’m trying to test a method from a class which contains a method using the request() helper from Laravel. This is the method: Category class The test should make this helper to catch properly the URI when doing getRequestUri() but it’s actually returning an empty string. This is one of the thousand tries that I gave to the test. Test
WP_Ajax_UnitTestCase does not throw WPAjaxDieStopException
Ok so I am testing my ajax callbacks for my wordpress plugin. So I basically followed instructions here https://codesymphony.co/wp-ajax-plugin-unit-testing/ Here is my ajax callback function Here is my test Now here are the issues It doesn’t throw WPAjaxDieStopException exception like its suppose to when I do this code $this->setExpectedException( ‘WPAjaxDieStopException’ ); it fails the test https://snag.gy/JSTqHV.jpg It prints out that
Laravel 5 console (artisan) command unit tests
I am migrating my Laravel 4.2 app to 5.1 (starting with 5.0) and am a lot of trouble with my console command unit tests. I have artisan commands for which I need to test the produced console output, …
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 introducing any new frameworks? Answer Since you mentioned you don’t want to use any other
Mocking classes that created with app()->make
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():
Dependency injection on dynamically created objects
I’m using reflection to test if a class has a particular parent class and then returning an instance of it. I want to be able to unit test these instantiated objects but I don’t know if there is any way to use dependency injection in this case. My thought was to use factories to get dependencies. Is the factory pattern