Questions tagged [phpunit]

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

Filter by
Sorted by
Tagged with
-1 votes
0 answers
35 views

Data provider laravel phpunit doesn't work: Argument #2 ($code) must be of type int, string given

I'm trying to do testing on a Laravel application using Phpunit and data provider (I want to test for each field being wrong, so I thought it would be awesome to use a Data Provider) However, I can't ...
coderz's user avatar
  • 70
0 votes
0 answers
21 views

PHPUnit 10: parseTestMethodAnnotations() is not working as it is removed from PHPUnit/Util/Test

Recently I have upgraded from PHPUnit 9.6 to 10.4 and I am facing some difficulties while upgrading. For ex, I have below code: use PHPUnit\Util\Test as TestUtil; $annotations = TestUtil::...
Nishant's user avatar
  • 21
0 votes
0 answers
38 views

Laravel PHPUnit : Can't use Config::get() when setUp() method is present

I have a unit test similar to this in Laravel 9: namespace Tests\Unit; use Tests\TestCase; use App\Models\CompanyContact; use Config; class CompanyContactTest extends TestCase { private $...
Oli's user avatar
  • 68
0 votes
1 answer
19 views

How to return different values from mock object depending on parameter

I want to mock the return values of a redis server. Depending on the key I need to get back different fake values. Since this would be still easy I want as a return value the content of a file on my ...
Calamity Jane's user avatar
0 votes
0 answers
22 views

How do I test Laravel Cashier Checkout Redirect in PEST PHP tests?

I have this subscribeToPlan method which will redirect the logged in user to Stripe's hosted checkout page. public function subscribeToPlan(StripePlan $plan): \Laravel\Cashier\Checkout { return ...
Ask17's user avatar
  • 82
0 votes
3 answers
38 views

PHPUnit: Running Tests that Use a Specific Attribute

I'm using the RequiresFunction attribute in a few of my tests. I want to pass arguments to phpunit that will run the tests with that attribute and the name of the required function (if possible). ...
Sonny's user avatar
  • 8,216
0 votes
0 answers
16 views

Run Codeception Acceptance Test within two Integration Tests coded in simple PHPUnit

Consider the following Integration test file extract based on PHPUnit: ... /** * @return void */ public function test_first() { $this->assertTrue(true); } /** * @depends ...
DevelJoe's user avatar
  • 916
2 votes
1 answer
19 views

phpunit setup in Docker Container

I have following docker-compose.yml file for PHP Docker application. I tried to setup PHPUnit in this docker container. But It is showing following error Error response from daemon: failed to create ...
Mani Kanta's user avatar
1 vote
0 answers
22 views

Call to undefined method Test::component() in Laravel package testing

I have a Laravel package that will provide UI components (in Blade) and I want to write some unit tests for these components. I am using PHPunit 10.4 and orchestra testbench 8.15. Base testcase: class ...
user22983507's user avatar
1 vote
1 answer
22 views

PHPUnit Mocking methods calls in a mocked method

I'm trying to write a basic unit test to see if a method is called in another method. I have a class like the following: class Hello { public function doSomething($something) { if ($...
sipher_z's user avatar
  • 1,231
-1 votes
1 answer
68 views

Unit tеsting against protеcted properties [duplicate]

Ideas how to write good OOP code, SOLID, incapsulation, loose coupling and so lead to not using public properties use as little getters as possible Say we have code class Some { protected int $x; ...
Mike's user avatar
  • 9
0 votes
0 answers
15 views

Can PHPUnit code coverage produce HTML diff of two coverages that correspond to two git commits

In the same sense that when I want to review code, I am reviewing only changes, I would also be interested only in the changes of unit coverage. So, what I'd like to see is the difference of the code ...
user_51's user avatar
0 votes
0 answers
46 views

Php unit test gives error in default laravel application

in default laravl application when I run phpunit it always gives me the error: PHP Fatal error: Uncaught Error: Call to undefined function each() in C:\xampp\php\pear\PHPUnit\Util\Getopt.php:80 Stack ...
Mohammad Darweesh's user avatar
-2 votes
4 answers
161 views

How to assign a belongsTo relation in Laravel without saving to database?

I have the following 2 models: <?php namespace App\Models; class Product extends Model { //some other property of the Model public function productType() { return $this->...
cytsunny's user avatar
  • 4,840
0 votes
1 answer
18 views

Why can't my Drupal PHPUnit test seem to autoload a shared test fixture/utility class?

In my Drupal 10.x project, I have a test that is attempting to mock a class that I created to be used by multiple tests (call it Drupal\Tests\my_module\MyTestObject). The code looks something like ...
GuyPaddock's user avatar
  • 2,390
0 votes
0 answers
32 views

How to use `setMockClassName` from phpunit with a class-string correctly?

Recently, the maintainer of PHPUnit made a change to the "setMockClassName" method so that it now accepts only class-strings instead of regular strings. I'm currently handling this ...
Chubby Cows's user avatar
0 votes
0 answers
33 views

PHPUnitCode Coverage readonly classes

I have a project with Laravel 9, phpunit/php-code-coverage: "^9.2" and phpunit/phpunit: "^9.3.3". I can run individual tests and everything works correctly, but if I try to ...
juan manuel Sivianes Guisasola's user avatar
0 votes
0 answers
38 views

Issues in executing unit test in Laravel 8

I am using Laravel 8 and PHP 7.4 When I run the below command php artisan test --filter ActivityTests I get error: "Warning: TTY mode is not supported on Windows platform. PHPUnit requires the &...
Ish's user avatar
  • 1
0 votes
0 answers
33 views

Laravel Mockery phpunit error: Unresolvable dependency resolving

Fairly new to testing but can't this test with a facade to work correctly. The code itself is working correctly. Just want the test to work also :') The serviceprovider: <?php class ...
Martijn Bastiaansen's user avatar
0 votes
2 answers
35 views

Test multi storage in laravel

I have a issue while trying to mock multi Storage in laravel test enviromnment. Here is my my code: public function sftp ( Sibling $sibling ) { $file_paths = Storage::build($sibling->config)...
Erfan Sabouri's user avatar
0 votes
0 answers
49 views

Laravel: mocking service class in job

I want to mock a service class for a test, but I can not. My test protected function setUp() : void { parent::setUp(); Queue::fake(); $this->client = $this->createClient(); } ...
LaszloP's user avatar
  • 179
0 votes
0 answers
32 views

Symfony 6.2 - EasyAdmin 4 phpunit test - Mandatory _locale

Within an application that I am building I got a admin with an locale variable (en/nl) #[Route('/{_locale<%app.supported_locales%>}/admin', name: 'admin')] public function index(): Response ...
Yoran Schreuder Peters's user avatar
0 votes
0 answers
40 views

Tests not hitting breakpoints in Docker + XDebug + VSCode setup

Already spent good part of the night and a several hours today, going through dozens of articles, videos and whatnot, I haven't been able to make it work. This is a Laravel 10 application, where I'm ...
dotNET's user avatar
  • 33.8k
0 votes
1 answer
54 views

PHPUnit how to mock or change the value of a class constant

I've got a class that has a constant that is accessed by various methods in the class. It has been a constant for long time (legacy code) and we don't wanna change it to be a regular var so I'm stuck ...
HerbertRedford's user avatar
0 votes
1 answer
41 views

PHPUnit: Ignore tests completely based on dataProvider parameters

I want to test (functional) my Symfony controllers with PHPUnit 9.6 and in order to not have to have the same test cases in each test class, I had the idea to make an abstract class that contains the ...
Nono's user avatar
  • 1,073
0 votes
1 answer
9 views

phpunit error Argument 1 passed to PHPUnit\Runner\TestSuiteSorter::reorderTestsInSuite must be an instance of PHPUnit\Framework\Test

I'm using PHPUnit 9.6.10 by Sebastian Bergmann and contributors. and when i run phpunit why can i see the following error? Argument 1 passed to PHPUnit\Runner\TestSuiteSorter::reorderTestsInSuite() ...
Matt Doran's user avatar
  • 2,058
-1 votes
1 answer
48 views

Wrong request parameters when testing an api route

I have a test that calls a function in a controller: public function testAuthentication() { $user = $this->createUser(); $this->actingAs($user)->withoutMiddleware(); $project = $...
Gnvt's user avatar
  • 31
0 votes
0 answers
54 views

phpunit configuration file doesn't load - Uncaught PHPUnit\Util\Xml\Exception

I have a phpunit.xml file in the root of my project. When I run vendor/bin/phpunit web/core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php, this file is picked up and the tests run ...
joachim's user avatar
  • 29k
0 votes
0 answers
12 views

PHPUnit 8 exit code 0 on database connection faluire

I'm running into what I think it's a strange behavior for PHPUnit (8.5.26 on PHP 7.4): if the database connection fails, the app throws an exception but the exit code is still 0. Is this an expected ...
Maxxer's user avatar
  • 1,038
1 vote
1 answer
79 views

php artisan test ignore phpunit.xml

When I run my tests with Phpstorm everthing works as expected and the connection switches to mysql_test. But when I run php artisan test manually the connection wont switch and remain mysql. phpunit....
arya_la's user avatar
  • 450
0 votes
0 answers
34 views

Is it possible to only run tests that touch changed code in php

I have a testsuite that takes several minutes to complete so it starts to get annoying to run them all before each push (they will still be run in the deployment pipeline as well) So I was wondering ...
Chris's user avatar
  • 13.4k
0 votes
1 answer
24 views

AspectMock not working in Codeception framework & yii2 framework

I want to mock the static methods, so I am using the AspectMock library https://github.com/Codeception/AspectMock. I tried to mock one static method but it doesnt return the expected mocked result. ...
Omi's user avatar
  • 3,994
0 votes
1 answer
20 views

In CoreClassReflection.php Class Does Not Exist While Using Infection

I try to use Infection to evaluate my testcase using php, I have 2 file (Displayuser.php, displayuserTest.php) for the first file Displayuser.php the code like this, this file under func folder <?...
arasyid tutorial's user avatar
1 vote
0 answers
31 views

How can I properly test DateTime in my service?

I am having difficulties on how to test my service properly, as it uses DateTime. From what I have read, everything I need to do is to "isolate" the "collaborator" and a good way ...
John Doe's user avatar
-1 votes
1 answer
60 views

How to override $request query parameters in phpunit

I am modifying subject_type query parameter value inside the controller using $request->merge, it is working as expected while sending request using the browser or any API testing client. But the ...
Bhautik Chudasama's user avatar
0 votes
1 answer
33 views

Uncaught PHP Exception LogicException: "Unable to add global "ea" as the runtime or the extensions

In browser, easyadmin is working fine. But when I run test case which asserts redirection logic to EasyAdmin's dashboard controller after login, it failed with the following error: Uncaught PHP ...
Erkhembayar Gantulga's user avatar
0 votes
1 answer
32 views

PHPUnit calling same method twice with willReturnOnConsecutiveCalls results in empty data

Problem: How to test same method (getNextUniqueBunch) with different results? function exampleQuestion() { $rows = []; $rowsAgain = []; while ($bunch = $this->_dataSourceModel->...
rocky's user avatar
  • 631
0 votes
0 answers
54 views

PHPUnit server side coverage with curl requests [duplicate]

I have some tests for an old PHP app, and it have inline tests and some curl requests to test APIs. The PHPUnit coverage, using Xdebug, isn't detecting the curl requests. Is there a way to follow this ...
Matsuda's user avatar
0 votes
0 answers
86 views

Laravel sail test works but vendor/bin/phpunit doesn't

I've setup a work flow using github actions and when it gets to this command there are 3 failed tests vendor/bin/phpunit But during this command on my machine they all pass sail artisan test The ...
jordan dolan's user avatar
0 votes
1 answer
71 views

how to remove deprecation on doctrine AbstractFixture::getReference()

In PHPUnit 10, I have somes fixtures between entities and they share references. I have the following deprecation and i can't manage to remove it : Argument $class of Doctrine\Common\DataFixtures\...
Garfield's user avatar
  • 111
0 votes
1 answer
25 views

How to Mock $wpdb->prefix using WP_Mock and Mockery?

🗺️ My Environment PHP 7.4 WordPress 6.2 WP_Mock 1.0 PHPUnit 9.6.11 Mockery 1.6.6 🖥️ Code: TestCase use PHPUnit\Framework\TestCase; use WP_Mock; use Mockery; class WPAB_Database_Service_Test ...
Adrien Villalonga's user avatar
0 votes
1 answer
73 views

PHPUnit 10 specify different method arguments on consecutive calls to the same method

I have a method that's called several times with different arguments as part of a larger method. $query->where("one", $id); $query->where("two", "LIKE %{$name}%"); $...
Andrei's user avatar
  • 3,444
0 votes
3 answers
77 views

How to validate a not updatable column with symfony/validator?

I have a column that it's a DateTimeImmutable that save when the user has joined the platform. I'm making the phpunit test and i would like to validate that the colum can't be updated. I would like to ...
Naico04's user avatar
  • 19
0 votes
0 answers
19 views

Compress dataprovider output when tests pass phpunit

I have a testcase for phpunit 10 that uses a dataprovider: #[DataProviderExternal(\Tests\DataProvider::class, 'invalidEmailAddresses')] public function test_validates_email_address(string $email): ...
213d4g's user avatar
  • 1
1 vote
0 answers
60 views

how to write phpunit test

we have function testLink. the method $this->authorize() is invoked twice inside. How to write unit test to test business logic of invoking of method $this->authorize()? public function testLink(...
Ilya Mironchikov's user avatar
0 votes
2 answers
85 views

Is there a simple way to invert a test or test group?

Assume you have written a failing test to exploit a bug. You want to push this to upstream and then create a story that is about fixing the code so that the test passes. However, this is prevented by ...
klutt's user avatar
  • 30.6k
0 votes
0 answers
34 views

PHP PHPUnit Test Case

Write a class 'Skill' that handles any function which starts with ‘has_’ keyword return function ‘exist’ and any other function that starts with any word that should return ‘not exist’ and checking a ...
Rizeen's user avatar
  • 1,332
0 votes
0 answers
34 views

How to properly mock partially class with params in Laravel?

I have a service called GenerateReportService in which I need to mock one method generatePdf. The problem is that I need to check the params which will be received in this method after others methods ...
Kin's user avatar
  • 4,486
1 vote
0 answers
241 views

Run PHPUnit rather than Pest

I have a project with a mixture of tests wrtten in Pest and regular PHPUnit Test Classes. There is a lot missing from Pest for package developers and its just simpler to use the PHPunit for areas ...
Zakalwe's user avatar
  • 1,474
0 votes
1 answer
39 views

phpunit test - validation for store boolean fields which fills by non-boolean and invalid value

sorry for my bad english :) . I want to test a boolean field validation error, when user entered a non-boolean value (from browser inspection,for example) . for example, if in browser inspect, I set '...
ERasekh's user avatar
  • 35

1
2 3 4 5
200