10,050
questions
0
votes
0
answers
18
views
Github Action Runner Not Connecting To Sqlite Database
All the questions in this topic are so advanced, hard to believe that I'm the only one dumb person struggling with this. I have a Github Laravel action runner configured with the following yml file:
...
0
votes
0
answers
32
views
How to Mock S3ClientInterface with PHPUnit 10+
So this question has been asked here before - How to Mock Aws\S3\S3Client for phpunit // how to mock magic methods but the answer there is no longer valid because addMethods was deprecated in PHPUnit ...
0
votes
0
answers
16
views
Unplanned user logout during PhpUnit test
I had a test environment that was working perfectly fine until every request needing authentication started to fail (functionnal tests, class extending webTestCase). I suspect it does so since adding ...
0
votes
0
answers
30
views
Laravel sanctum during testing: "Session store not set on request."
This error happens very often for people, most of the time because SANCTUM_STATEFUL_DOMAINS is not set correctly. I did set it correctly for local development but the error happens during testing, e.g....
0
votes
1
answer
66
views
PHP/Laravel: Error: Call to a member function __call() on null
I’m currently working on a Laravel project and I’m facing an issue with setting up a factory for a pivot table. Specifically, I’m trying to create a factory for a table that serves as a pivot between ...
0
votes
0
answers
21
views
Symfony process component and test environment
Problem: I need to run command in test environment, so I found to use symfony/process component.
Then I tried to run process in this way:
public function testProblem(): void
{
$user = $this->...
-1
votes
0
answers
38
views
Symfony 5 testing: why I can't get environment variables from .env files? [duplicate]
I have .env, .env.test, .env.test.local files in my project.
Variables are specified in .env.test:
APP_ENV=test
APP_DEBUG=1
However, when the test is running (WebTestCase), these variables don't seem ...
0
votes
1
answer
25
views
Laravel Test not updating the new test files
I am using Laravel 11, installed Laravel Breeze and PHPUnit Test. I changed where to store my User model, something like app\Infra\Models\User.php
I run "php artisan test" to run all the ...
0
votes
0
answers
13
views
is there a way for a PHPUnit extension to get information from within the test?
I'm trying to implement a PHPUnit extension and I need data that the test's setUp() put in a static property on a class. (Specifically, Drupal's Database::getAllConnectionInfo().)
It's not there when ...
0
votes
0
answers
55
views
Does PHPunit reset local variables?
I have such as Testcase:
class GenerateTest extends AbstractTestCase
{
private int $requestTime = 0;
...
protected function setUp(): void
{
$this->requestTime = $_SERVER['...
2
votes
1
answer
95
views
Running Tests Across Multiple Repositories from a Single Test Directory
I’m currently working on a website with a somewhat complex architecture, which is structured as follows:
REPO-A
/.git
/files
/SUB-REPO
/.git
/files
REPO-B
/.git
/files
My technical ...
2
votes
0
answers
56
views
Laravel PHPUnit - PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 102400 bytes)
We are experiencing apparent memory leaks with our Laravel 10 application tests.
We recently upgraded from version 8 to 10, hoping this would resolve the issue, however it has not.
Using https://...
2
votes
1
answer
92
views
Laravel 10 - how to mock static function in other class:
in CommonHelper class:
class CommonHelper {
public static function getValue(string $category, string $name)
{
}
}
in MyService class:
public function getContentOrtherService(): ...
0
votes
1
answer
45
views
PHPUnit 'Error : Class "path\to\class\classToTest" not found'
I'm trying to write some unit tests. However no matter what I do I keep getting this error:
Error : Class "path\to\class\classToTest" not found
The test I'm trying to run has a simple ...
1
vote
0
answers
31
views
Laravel Testing with Multiple Databases: Preventing Migrations During Tests / Migrations failing
I'm working on a Laravel project that uses multiple MySQL databases. The main database (core_db) contains system tables like users, migrations, etc., while express_db and regio_db contain most of the ...
2
votes
1
answer
94
views
Laravel 11: Is it possible to force PHPUnit to trigger / "press" CTRL+C to simulate interruption of an artisan command?
I have an artisan command that can run for minutes or hours, processing multitude of records in a loop within the handle() method.
I have introduced the ability to interrupt such a long process by ...
0
votes
1
answer
67
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 ...
1
vote
1
answer
70
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 ...
1
vote
1
answer
55
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 ...
0
votes
0
answers
60
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&...
1
vote
0
answers
63
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.
...
1
vote
0
answers
106
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 ...
2
votes
1
answer
95
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 ...
1
vote
1
answer
60
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 ...
1
vote
1
answer
104
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 ...
3
votes
1
answer
247
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.
...
0
votes
2
answers
42
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 = ...
1
vote
0
answers
73
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 ...
0
votes
1
answer
38
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 = ['...
0
votes
1
answer
75
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 ...
1
vote
1
answer
118
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\...
0
votes
1
answer
33
views
How can I use a PHP-DI Container to pass mock objects while unit testing?
I have a controller that handles various cronjobs and I wanted to write unit tests for each function in the controller. The controller (lets call it TasksController) extends a base controller (let's ...
0
votes
1
answer
56
views
Laravel can't find my table when testing using an alternate connection
I have an application in Laravel that requires the use of different connections. My model User requires a regular "mysql" connection, while the related model, let's call it "...
2
votes
0
answers
54
views
How to write Laravel feature test for streamed content to browser?
I could use some help writing a feature test for a route that returns streamed content. Here's the details...
I have a Laravel route:
Route::get('/export/user/role/{role}', [Admin\ExportUserController:...
1
vote
0
answers
49
views
How to show full diff when assertEquals() fails?
I have a PHPUnit test that's failing but the test output is hiding important part of the failed data. How to make the whole data visible?
To demonstrate the issue, here's a mock test UnitTest.php:
<...
0
votes
1
answer
47
views
Laravel Model Mocking test with PHPUnit
I am trying to mock an update method in PHPUnit but so far shouldReceive('update') is not called.
PostServiceTest.php
public function test_can_update_a_post(): void
{
$mockedPostModel =...
0
votes
0
answers
55
views
Symfony's user login magic in WebTestCase not working
As described in the documentation, I try to log-in the user in a WebTestCase:
class CreateStoreTest extends AbstractCrudTestCase
{
// ...
protected function setUp(): void
{
...
0
votes
0
answers
54
views
UnexpectedResponseException when attempting to take screenshot with Selenium Web Driver in PHP
Error:
Facebook\WebDriver\Exception\Internal\UnexpectedResponseException: Error taking screenshot, no data received from the remote end
/path/to/app/vendor/php-webdriver/webdriver/lib/Exception/...
0
votes
1
answer
70
views
Error: Call to undefined function CodeIgniter\Test\helper() in PHPUnit tests for CodeIgniter project
I am working on a CodeIgniter project and have installed PHPUnit to run unit tests. However, when I execute the tests, I encounter the following error for each test, including the example tests ...
1
vote
0
answers
51
views
Confusion about mock reuse in phpunit
i'm writing some unit tests and became stuck at what i first thought was a bug, but after much frustration seems to be intended (but impossible to find documentation/mention of) behaviour/usage.
The ...
-1
votes
2
answers
39
views
PhpUnit test use Mockery - Bypass exception of method from another class
I have a laravel project and I got a problem with using PhpUnit test use Mockery.
This is the fist time I use Mockery.
Below, I have some pseudo code:
class Mail
{
public static function send($pin){...
2
votes
1
answer
53
views
Why do my PHPUnit tests in NetBeans run but don't result in any code coverage?
I have Xdebug running and in mode xdebug.mode=develop,coverage. I checked this with phpinfo() and got:
Xdebug:
Development Helpers ✔ enabled
Coverage ✔ enabled
I can run my tests, they ...
0
votes
0
answers
19
views
codecoverage with phpunit on netbeans cant find its log
I'm trying to get code-coverage running in netbeans with phpunit 11. My tests are running but I constantly get this output:
Full output can be found in Output window.
Coverage log not found!
Perhaps ...
1
vote
1
answer
67
views
Validating argument at specific mocked method call index? PHPunit/Mockery
So a very simple test: a method persisting some objects gets an array of data.
class A
{
public function __construct(private BucketRepository $repository){}
public function saveObjects(array $...
0
votes
1
answer
148
views
Laravel PHP Unit Tests With Postgres - SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint already exists
In the process of migrating from MySQL to Postgres we are running into this issue with our Laravel PHP Unit tests.
We use seeders, factories, or models in our setUp() or seeding functions to insert ...
0
votes
1
answer
47
views
how to test a controller method echoing something?
I'm diving into a legacy symfony project with some controller methods echoing stuff (I know it's bad, ugly,... and I would change that eventually but for now I must not change any code, just add tests)...
0
votes
1
answer
32
views
PHPUnit test using mockery is failing to intercept a method call on a mocked class
Here is my PHPUnit test (PHPUnit 10.5.2 Mockery 1.6.11)
public function testMergedDocumentsWithSuccessfulInit() {
$params = new \Buan\Request\Parameters([], [], [], []);
$...
0
votes
0
answers
62
views
Unable to pass flags to artisan test command
I have started learning laravel for one of my projects and almost everything works in the test commands except passing the arguments line --drop-databases.
./artisan test --drop-databases
Error ...
0
votes
2
answers
247
views
How to unit test symfony dto with constraint attributes
I have a newly created Symfony 7 app and I have a DTO called: AuthCallbackDto
<?php
declare(strict_types=1);
namespace App\Application\Model\Auth;
use Symfony\Component\Validator\Constraints as ...
0
votes
2
answers
78
views
How do I deal with "The payload is invalid." in Gitlab CI/CD pipeline?
I am trying to run testJob in GitLab CI/CD for my (Laravel 11 + React Typescript with Inertiajs) and I keep ending up with the below error. I have ensured that the APP_KEY is set in the CI/CD ...