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

How do I test Laravel's built in verify email notification?

I am creating a test for Laravel's built-in email verification and am unsure how to test this via PHPUnit. I'm able to receive the notification emails using mailtrap.io but am unable to make the PHPUnit test pass. Here is my test: namespace…
James Higgins
  • 61
  • 1
  • 4
4
votes
2 answers

How do I get php code coverage to run over phpt test cases?

I have a test environment that runs the component tests for a product. I found that recently it was tough to test and successfully mock php's is_uploaded_file() and move_uploaded_file() but after a lot of searching and research I came upon PHPT.…
Etienne Marais
  • 1,660
  • 1
  • 22
  • 40
4
votes
1 answer

Symfony 4 - Functional Test - Client not following redirects though followRedirects is true

I have been trying to start implementing some functionnal tests in the Symfony 4 application I am working on and I am failing to be redirected and eventually get a 200 response code from my index page even though I get a 200 response in the end when…
ZFL
  • 43
  • 6
4
votes
1 answer

Unit testing with hashed passwords

Right now I'm using the Zend Framework and messing around with that and phpunit. Here is my dilemma. When I create a user I hash the password in the user table. I add two salts, a static one from the application and one that is randomly generated. I…
Jerry Saravia
  • 3,737
  • 3
  • 24
  • 39
4
votes
1 answer

PHPUnit Fatal error: Allowed memory size exhausted

When I run my tests, PHPUnit 8 crashes and generates a Fatal error: Allowed memory size of x bytes exhausted. I think it only crashes when some tests fail. When I used it yesterday for the first time I set up 2 very simple tests comparing 2 strings.…
Equiphract
  • 107
  • 1
  • 11
4
votes
0 answers

Why symfony container is build in test environment when I run phpunit whereas .env defines APP_ENV as dev?

I face a problem with env variables and running tests with phpunit on symfony 4.2 framework. According to the documentation, .env and services.yaml are loaded first but if the APP_ENV is defined and set to a value like test, the container will be…
Dralucas
  • 229
  • 2
  • 6
4
votes
2 answers

How to write PHP Unit Test for Static Methods

I am very new to PHP Unit Testing. I am trying to create Unit Test for the following function: $context = $args[0]; if (Subscriber::instance()->isSubscriber()) { $context['body_class'] .= ' ' . $this->bodyClass; } return…
user991041
  • 81
  • 1
  • 2
  • 5
4
votes
4 answers

PHPUnit: How to save an arguments passed to stub method

Method setValue() In class SomeClass accepts arguments and no way to get this arguments back for make assertion. Can I create a stub for method setValue() that allows save an arguments passed to this method? class SomeClass { public function…
Darkside
  • 659
  • 8
  • 20
4
votes
1 answer

multiple tests clashing in phing

We have a Phing script that is used by Hudson to build/test our PHP site. Some of our unit tests load the main function library; others use a mock to avoid having to do so (or to provide specific faked results for the test). The unit tests all run…
Spudley
  • 166,037
  • 39
  • 233
  • 307
4
votes
2 answers

Laravel 5.6. PHPUnit. Order-insensitive assertJson() method

In my business logic I don't care about the order of elements. Here is my example of a test $this->getJson('/api/order-attempts') ->assertJson([ 'data' => [ ['status' => 'error'], ['status' => 'error'], …
D.R.
  • 2,540
  • 3
  • 24
  • 49
4
votes
2 answers

Test fails because of date time formatting when searching for model in database

Since Laravel 5.6, Eloquent Date Casting is available. So I've got a model MyModel with: class MyModel extends Model { protected $casts = ['from' => 'date:Y-m-d', 'to' => 'date:Y-m-d']; protected $dates = ['from', 'to']; } And the…
quick-brown-fox
  • 61
  • 1
  • 13
4
votes
4 answers

Using mock objects in PHP inside functions that instantiate their own objects

I have been looking into how to add unit testing coverage to a large, existing codebase written in PHP. Many functions in both static and instantiable classes make a call to a library or instantiate an object in order to obtain connections to…
Eliot
  • 5,450
  • 3
  • 32
  • 30
4
votes
3 answers

Issue upgrading to phpunit 3.5.13

I have been using phpunit for a while, starting with 3.5.8, subsequently upgrading to 3.5.10 and now on 3.5.11 I wanted to upgrade to 3.5.13 today using the commands: pear channel-update pear.phpunit.de pear upgrade phpunit/PHPUnit Unfortunately…
Hanno
  • 43
  • 1
  • 5
4
votes
2 answers

How to unit test a method calling a function that has a side-effect by changing an argument passed by reference?

I have a method that makes a call to a builtin PHP function, openssl_random_pseudo_bytes. public function generateRandomBytes() { $crypto_secure = TRUE; // $crypto_secure is passed by reference and will be set to FALSE by //…
rurouniwallace
  • 2,027
  • 6
  • 25
  • 47
4
votes
1 answer

ZF + Doctrine2 phpUnit error: PDOExeption: You cannot serialize or unserialize PDO instances

I'm using DynamicGuys doctrine2 integration into zend framework(https://github.com/dynamicguy/zf1doctrine2). It works, but if i want to make tests with phpUnit i get this error: PDOExeption: You cannot serialize or unserialize PDO instances I've…
Danielss89
  • 863
  • 1
  • 11
  • 17
1 2 3
99
100