Skip to main content

Questions tagged [phpunit]

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

0 votes
1 answer
37 views

Laravel - Mock single method in a command using PHP UNIT

I'm trying to test a command where there's a method I want to mock because it makes a call to an external service using Guzzle, but no matter what I try, I can't seem to mock it successfully. It ...
Miguel Heredia's user avatar
1 vote
1 answer
52 views

How can I test that the PHP code under test calls the proper method on a trait?

Edit: After reading one of the comments, I realized I misspoke pretty badly in the original post, I've made some edits to clarify. Essentially, I need to check the results but am struggling with that ...
jrgilman's user avatar
  • 472
1 vote
1 answer
36 views

Mocked method is not used with Instance

Inside my Export class I have created this method: public function getBranches() { return Branch::all(); } I want to Mock this Method. Now I have the following piece of code in a testcase: $mock ...
Gommiboum's user avatar
  • 107
0 votes
0 answers
36 views

tearDownAfterClass not being invoked with PHPUNIT 11 and LARAVEL 11

I cannot figured out why the tearDownAfterClass() is not being called. PHPunit version: "phpunit/phpunit": "^11.2" Laravel version: "laravel/framework": "^11.10&...
Sergio Costa's user avatar
1 vote
0 answers
59 views

How to write unit test for PHP Script without functions?

I'm trying to write a unit test for a PHP script that does not contain any functions or classes. It is just a plain PHP script that returns header('Location: ${url}') when a specific condition is met. ...
Visal's user avatar
  • 660
1 vote
0 answers
83 views

PHPUnit - Error: Call to a member function addContext() on null

When I run tests in GitHub worklfow action on my Laravel project, I get this error from all PHPUnit tests: Error: Call to a member function addContext() on null The addContext() function is not my ...
netdjw's user avatar
  • 5,875
2 votes
1 answer
55 views

Generate code coverage for a single test suite

I wish to determine which files are covered by each of my test suites separately. I am using PHPUnit 10.5 with Xdebug for code coverage on my PHP 8.1 project. Here is what my phpunit.xml configuration ...
Kolobo's user avatar
  • 39
0 votes
0 answers
22 views

Database locked in PHPUnit tests only

In my application SQLite works. But when I create tests in PHPUnit it's locked on the first write. I've hacked in some beginTranaction() and commit() but it still hangs on the commit() call. The test ...
Tac Tacelosky's user avatar
1 vote
1 answer
77 views

Strange behavior of symfony doctrine during phpunit test - field becomes null in database

I am using Symfony v6.4.8 doctrine/orm 2.19.5 phpunit/phpunit 9.6.19 I have build an REST API GET endpoint /api/contract/{$id} in Symfony. It performs an API request at another system, receiving ...
SvenW's user avatar
  • 21
3 votes
1 answer
218 views

How to mock/simulate Laravel JobQueued queue event in test?

I want to test multiple event listeners that listen for Laravel's built-in queue events (all the events that live in the Illuminate\Queue\Events namespace. The listeners are part of a package. ...
user25728292's user avatar
0 votes
0 answers
14 views

phpunit inject mocked object into another mocked object

I want to test the output of method checkCredentials(): Class BuildParticipant { public function __construct(DBConnectionWrapper $db, ?Logger $logger=null) { $this->participant = ...
Tim Morton's user avatar
  • 2,634
0 votes
0 answers
44 views

File Upload Validation test for Livewire component

I have a user creator Livewire component which has a profile picture uploader. Trying to write some the unit tests for the File field of that form, but it doesn't want to work. I'm sure that my ...
domjanzsoo's user avatar
0 votes
1 answer
33 views

Php Laravel PhpUnit Test Returns 404 error

My test result always return 404 but i define route for api. why like this? i cannot find any solution. my test function : public function test_can_update_integration() { $integrationArr = ['...
Mustafa UYSAL's user avatar
0 votes
1 answer
70 views

An error occurred, but no information is displayed

PS : I am new to StackOverflow and in computer science. My question may be blurry, so please be understanding and kindly tell me what I can improve :) I am currently testing my code with PhpUnit ...
Kolobo's user avatar
  • 39
1 vote
1 answer
51 views

laravel unit tests fail with Symfony\Component\Process\Exception\ProcessSignaledException 11

Trying to figure out what broke my development environment. It had been working well on my MacBook and then I updated something, and now most of my PHPUnit test files throw this error: Symfony\...
hanmari's user avatar
  • 1,404

15 30 50 per page
1
2 3 4 5
670