Category "phpunit"

Phpunit partial mock + proxy Entity

I tried find solution to my issue but didn't find anything. I use: Symfony, Doctrine, PhpUnit I have one entity class InvoiceNumerator: /** * InvoiceNumerat

How to access Session in PHPUnit WebTestCase (Symfony 5)

I'm trying to test methods which requires Sessions in my PHPUnit WebTestCase, with no success. PHP 8.0, Symfony 5.4 Here's my code: When user log-in, I'm saving

Laravel + phpunit + github actions = Failed asserting that '1' is identical to 1

I'm trying to make CI pipeline and run phpunit tests via GitHub actions. First of all: tests work fine on my local machine (mac os). Then, when I do git push my

Laravel Collections. Is there some kind of assertStructure method?

I'm writing tests and I want to assert, that a returned collection has some specific structure. For asserting jsons I'm using assertJsonStructure() method on

PHPUnit gives error: Target [Illuminate\Contracts\View\Factory] is not instantiable

I created a simple test for my new Laravel 7 application. But when I run php artisan test I get the following error. Target [Illuminate\Contracts\View\Factory]

PHPUNIT Test - Expected Status 200 But Received 500

I keep getting status 500 when 200 is expected. These are the files: ExampleTest.php namespace Tests\Feature; use Tests\TestCase; use Illuminate\Foundation\T

PHP Fatal error: Class not found - PHPUnit

I'm trying to use PHPUnit in a PHP project. Here is my project structure (files are in italic font style) controllers Pages.php tests pagesTest.php vendor

How to Mock the Request Class in Laravel?

I'm trying to test a function that depends on $request->all(); in a method. How do I mock the Request class so $request->all(); returns ['includes' =

Cannot return objects in @dataProvider PHPUnit

Is it allowed to return objects from @dataProviders to test methods? public function iOsMessages() { return [ 'update available' => [1,

Autoloading classes in PHPUnit using Composer and autoload.php

I have just installed PHPUnit version 3.7.19 by Sebastian Bergmann via Composer and have written a class I would like to unit test. I would like to have all my

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

I am testing an parameter sent to a mocked event handler. The parameter is an object of "Event" sub-type, which itself has some data nested inside it. I want to

PHPUnit - REST API testing

I have REST API written in php, i want to test it with phpunit. I wrote test like this, it works but response body was empty. I tested it with fiddler, it se

phpunit - testing is painfully slow

I am diving deeper and deeper in the world of unit testing. One issue I encountered, and this is where I would like feedback, is when one runs multiple test su

How to create tests w/Doctrine entities without persisting them (how to set id)

I'm working on tests for a Symfony2 project, and right now I'm looking for a way to create tests involving entity objects without persisting them. The problem i

PHPUnit (Phar) Fatal Error Only When Test Fails

I have chosen to use a Phar of PHPUnit (phpunit-4.8.26.phar) to unit test my custom built PHP Framework and Application. The reason I am using the old stable re

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

I've already read the documentation. Basically I've tried tests while following the BankAccount example. But I get errors: Warning: require_once(PHP/CodeCovera

phpunit - mockbuilder - set mock object internal property

Is it possible to create a mock object with disabled constructor and manually setted protected properties? Here is an idiotic example: class A { protected