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
39
votes
11 answers

Selenium 2 (WebDriver) and Phpunit?

Any one know how to use Selenium 2 with Phpunit? Are there any Selenium 2 samples in PHP?
Paul R Rogers
  • 914
  • 1
  • 9
  • 19
39
votes
3 answers

PHPUnit :: get message: OK, but incomplete or skipped tests! without any information where is happen

Get message: OK, but incomplete or skipped tests! without any information where is happen. Only the: ..I........ How can i find where is the problem? Thanks
Ben
  • 25,389
  • 34
  • 109
  • 165
39
votes
3 answers

PHPUnit, mocked interfaces, and instanceof

Sometimes in my code, I'll check to see if a particular object implements an interface: if ($instance instanceof Interface) {}; However, creating mocks of said interface in PHPUnit, I can't seem to pass that test. // class name is…
Bryan M.
  • 17,142
  • 8
  • 46
  • 60
39
votes
12 answers

Phpunit error in PhpStorm

I am running tests in PhpStorm and I get this error. Does anyone know what on earth could be causing it? PHP Fatal error: Class 'PHPUnit_TextUI_ResultPrinter' not found in C:\Users\administrator1\AppData\Local\Temp\ide-phpunit.php on line 249 I…
b85411
  • 9,420
  • 15
  • 65
  • 119
39
votes
4 answers

Creating a base test-class for PHPUnit and extending it for common functionality results in class not found error

I'm running PHPUnit using a bootstrap file for autoloading classes (generated by composer). All my tests load up classes just fine, but for two of my tests, I made a "base" test class which extends \PHPUnit\Framework\TestCase (similar to…
r.bilgil
  • 889
  • 2
  • 10
  • 15
39
votes
6 answers

PHPUnit: Verifying that array has a key with given value

Given the following class: Other = $Other; } public function query () { $params = array( 'key1' => 'Value…
Anti Veeranna
  • 11,485
  • 4
  • 42
  • 63
39
votes
10 answers

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…
Mauro
  • 1,447
  • 1
  • 26
  • 46
39
votes
7 answers

PHPUnit doesn't continue test after expecting an exception

Why doesn't PHPUnit do last exception assertion in this code? public function testConfigOverriding() { $this->dependencyContainer = new DependencyContainer(__DIR__ . "/../../Resources/valid_json.json"); $this->assertEquals('overriden',…
user2742648
38
votes
2 answers

Symfony 2 + Doctrine 2 + PHPUnit 3.5: Serialization of closure exception

I tried to find something about this on Google but nothing came out. I have a TestCase class that inherits from WebTestCase, with some methods that I want to use in all my unit/functional tests:
Adrian
  • 547
  • 1
  • 5
  • 10
38
votes
2 answers

Match JsonStructure in PhpUnit Test - Laravel 5.4

I am creating a unit test and want to test the JSON structure returned in the response. I am aware that the TestResponse provides a method assertJsonStructure to match the structure of your JSON response. But for some reason I am unable to map the…
Farooq Ahmed Khan
  • 3,975
  • 3
  • 27
  • 36
38
votes
6 answers

How to Determine if PHPUnit Tests are Running?

I currently have a problem that I have to work around in legacy code to get our interaction with a PHP Extension to work properly (Singleton Testing Question). As such, I do not want to execute this code when running our normal production code with…
Steven Scott
  • 10,234
  • 9
  • 69
  • 117
37
votes
2 answers

PHPUnit 6.1.x throws array_merge() error when my test class uses its own constructor method

I get this error: 1) XTest::testX array_merge(): Argument #1 is not an array ERRORS! Tests: 1, Assertions: 0, Errors: 1. On this test case: use PHPUnit\Framework\TestCase; class XTest extends TestCase { function __construct() {} …
Dennis
  • 7,907
  • 11
  • 65
  • 115
37
votes
2 answers

What is the difference between createMock and getMockBuilder in phpUnit?

For the love of my life I can't figure out the difference between createMock($type) and getMockBuilder($type) I am going through the original documentation and there is just a one liner which I didn't understand. ... you can use the…
Chris Roy
  • 945
  • 1
  • 7
  • 19
37
votes
5 answers

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 assert that the returned value is 1.23456789? If I…
Tower
  • 98,741
  • 129
  • 357
  • 507
37
votes
7 answers

How can I get IDE autocomplete for PHPUnit?

I am using Symfony2, everything is installed, my tests work so good so far. I'd like to get an autocompletion of PHPUnit's methods. Symfony's WebTestCase class extends from PHPUnit_Framework_TestCase just like below: abstract class WebTestCase…
Vitalii Zurian
  • 17,858
  • 4
  • 64
  • 81