Skip to main content

All Questions

Tagged with
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
0 votes
0 answers
27 views

Why does livewire test assertReturned fail?

I have a simple function called sumEquation: /** * Sums an equation * * @param string $equation * @return float|int */ private function sumEquation(string $equation): float|int { $...
movac's user avatar
  • 1,883
0 votes
0 answers
14 views

Unit testing when mocking file upload in php

I am just stuck at this point. I am mocking a Filesystem class, which has the method dumpFile, which uses file_put_contents under the hood. Since it's mocked, the file will never be uploaded. That's ...
seref's user avatar
  • 561
1 vote
1 answer
32 views

Does Mockery clone __get method? [duplicate]

I am using Laravel 9 together with mockery/mockery version 1.6.6 I have some strange behavior when I mock an Eloquent model. The eloquent Model has a __get() method defined as : public function ...
Adam's user avatar
  • 28k
0 votes
1 answer
546 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
1 vote
0 answers
49 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
0 votes
0 answers
98 views

PHP - Mockery accessing to static property when overload a class

I'm trying to write a Test for a esential part of the App, but I don't want to refactor the whole app. I have "hard" dependency between classes. I know, I know, Don't ask me, It's already ...
nicolasst22's user avatar
0 votes
1 answer
382 views

How to correctly make a Unit test for a method that is downloading a file from FTP Server using Laravel 10

I'm attempting to write a unit test, preferably in PEST PHP, to verify the following method: Data is retrieved from the 'producers' table in the database and fed into the configuration. This ...
Greg Ostry's user avatar
  • 1,201
-1 votes
1 answer
1k views

How to test Laravel Api (only) Controllers with PEST Php testing?

I've setup a backend only Laravel app from the boilerplate. I want to test the API controllers using Pest, however, I keep getting Unresolvable dependency resolving [Parameter #0 [ <required> $...
wanna_coder101's user avatar
1 vote
0 answers
100 views

How to implement Uncle Bob's ideia of zero parameters in this case?

I am trying to apply a principle I read on Uncle Bob's book "Clean Code", which states that the optimal amount of parameters for a method is zero. I found this is very hard to accomplish, ...
Bernardo Benini Fantin's user avatar
1 vote
1 answer
268 views

How to not display certain errors for Laravel 7 feature test

I have 2 methods in my feature test LoginTest.php that check for incorrect password or username. When I run vendor/bin/phpunit I don't get any errors reported: OK (40 tests, 154 assertions) However, I ...
Maxime Barber's user avatar
-1 votes
1 answer
209 views

Which class should i mock service class or third party api of service class?

PostController's store method which calls the service class and service class calls the third party api i.e. line. while storing a post. i want to write testcase if the notify field is true then it ...
Sau Rai's user avatar
1 vote
0 answers
423 views

How can test a resource collection structure?

Sometimes we need to write a unit test for collections, There are some methods for testing JSON structure in feature test, but in the unit test there is no way to test structures! of course, some ...
Nothehi's user avatar
  • 703
1 vote
1 answer
256 views

How to write a unit test that classes implementing a contract should pass

I am not sure if this is a valid question. It is difficult when you have a question but do not know related terms to type into search. So my searches are not yielding any meaningful result. I just ...
Chika's user avatar
  • 25
2 votes
1 answer
3k views

How do I mock a GuzzleHttp client that makes a request to a third-party API in a Laravel feature test?

In a Laravel project (Laravel 8 on PHP 8.0) I have a feature test in which I test an internal endpoint. The endpoint has a Controller calls a method on a Service. The Service then tries to call a ...
Drikus Roor's user avatar

15 30 50 per page
1
2 3 4 5
21