Questions tagged [phpunit]

PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks.

Latest stable version: 8.2 (April 2019)

Installation via PHAR

wget https://phar.phpunit.de/phpunit-8.phar
php phunit.phar

Installation via Composer

composer require --dev phpunit/phpunit ^8
9985 questions
4
votes
1 answer

Testing JSON response with Laravel

I prepared a sample API with Laravel. It always returns this object: { "a": 1, "b": 2 } Now, I'd like to understand better how to test it with phpunit. I found there are assertJson and assertJsonFragment methods and I fail to understand the…
Robo Robok
  • 21,132
  • 17
  • 68
  • 126
4
votes
0 answers

When I turn on Xdebug, phpunit bootstrap setting didn't work

I have a problem when using Xdebug and PHPUnit. Because I want to use AspectMock, so I create bootstrap in phpunit.xml configuration and it goes well. However, when I try to turn on Xdebug to generate coverage report, it didn't use my bootstrap…
Sunny-work
  • 41
  • 2
4
votes
1 answer

Pass by reference in a callback when mocking in PHPUnit

I have an interface I want to mock, and mock the behaviour of one of it's methods. So I have created a callback that mocks the behaviour very simply. This test passes if I create a new object that is based on this interface, but I would like to mock…
johnwards
  • 1,901
  • 3
  • 18
  • 27
4
votes
1 answer

PHP Fatal error: Uncaught Error: Call to undefined method PHPUnit\Util\Configuration::getExtensionConfiguration()

I am trying to follow the instructions here https://laravel.com/docs/5.6/testing. On the Environment section here what I did. php artisan env --env=testing and then run phpunit but after that, this message show up PHP Fatal error: Uncaught Error:…
Fil
  • 8,225
  • 14
  • 59
  • 85
4
votes
2 answers

phpunit only shows help / usage information, no testresult

After some trouble installing phpunit (manually in the end) on wamp and windows 7, it now starts but only shows the usage information you see when you just type in phpunit. No matter in what directory I am, no matter which directory I point phpunit…
Maaike
  • 43
  • 3
4
votes
1 answer

Expected status code 200 but received 302

i'm trying to perform a test to check if 1 - the user is authenticated 2 - has permission to view the requested page every time i run the test i get this error Expected status code 200 but received 302. namespace Tests\Feature\Category; class…
bishoy wagih
  • 41
  • 1
  • 4
4
votes
1 answer

Testing old PHP versions with PHPUnit 7

I am using Composer for dependencies. My project's dependencies require PHP 5.5 or later, so I want to test my project on PHP 5.5 - 7.2 (latest) with PHPUnit 7. I set up Travis CI tests with different PHP versions: language: php php: - '5.5' -…
Filip Š
  • 746
  • 2
  • 13
  • 22
4
votes
1 answer

How can I mock an autowired service to symfony controller in phpunit functional tests?

Non-problematic context Let's say in Symfony 3.3 we have a default controller that paints "Hello, world!": class DefaultController extends Controller { public function indexAction() : Response { return new Response( 'Hello, world!'…
Xavi Montero
  • 9,239
  • 7
  • 57
  • 79
4
votes
1 answer

Unit testing Laravel password reset email - mailable not queued

I am using the auth that came with Laravel. I am testing the page where you put in your email and when you hit the submit button a password reset email will be sent to your email. The password reset email is sent when I do it manually. But I created…
4
votes
3 answers

Unable to install phpunit ,Conclusion: don't install phpunit/phpunit 6.5.8

I have php 7.0.29 version installed on my vagrant setup on windows 10. When I run following command composer require --dev phpunit/phpunit I get errors as mentioned Using version ^6.5 for phpunit/phpunit ./composer.json has been updated Loading…
Mukesh
  • 7,630
  • 21
  • 105
  • 159
4
votes
2 answers

How to access a private service in Symfony 3.4 phpunit tests?

I want to test a service who send mail. I have create a unit test but i have some deprecation warning and i want to know the good use. In my setUp() function i get the service like this $this->container = self::$kernel->getContainer(); …
eldiablo62
  • 305
  • 4
  • 17
4
votes
1 answer

Test if Eloquent Observer`s method fires an event

The app I am working on fires an event, when one of the Eloquent model attributes is updated. The Eloquent model is called Job and it is supposed to fire JobCustomerTotalAmountDueChanged when the duration attribute is updated. I have the following…
Amade
  • 3,665
  • 2
  • 26
  • 54
4
votes
2 answers

PHPT - Unable to run sample tests that use --POST_RAW--

This .PHPT test completes: (from PHPT docs) File: strtr.phpt --TEST-- strtr() function - basic test for strstr() --FILE-- "hi", "hi"=>"hello", "a"=>"A",…
Ian
  • 11,920
  • 27
  • 61
  • 77
4
votes
1 answer

How to use mock in Lumen using Mockery

How to use mock in lumen framework? I use the Lumen framework. The documents of lumen are very simple. I don't know how to use mockery or facades to mock Models. I tried some means, but no one worked. I want to mock two points of UserModel in…
yang li
  • 41
  • 2
4
votes
0 answers

laravel testing requires multiple databases trying to use sqlite duplicate tables

My testing journey continues... In an app I have multiple databases 1. which is for the backend content with users for the back end and other stuff 2. the front end and users for the front end. To carry out a test I need to create a user for the…
Ray
  • 3,018
  • 8
  • 50
  • 91
1 2 3
99
100