All Questions
243
questions
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 ...
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 ...
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 ...
-1
votes
2
answers
47
views
Would it still TDD if I would plan and list (as comment) all test ahead?
Would it still count Tdd when I some kind of start planning before even writing test down? I mean create test files with commented test case names. In that way I could for example anticipate and ...
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 ...
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 ...
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 ...
2
votes
1
answer
3k
views
How to mock/work with public readonly properties in unit tests
before PHP 8.1 we would have something like this:
<?php
declare(strict_types=1);
class Consumer
{
public function __construct(private DataTransferObject $dto)
{
}
public function ...
0
votes
1
answer
143
views
How should we write test for repository , logic and controller layer in laravel?
I am trying to write test for repository, logic and controller layer. Repository class injected inside logic and logic class injected to controller. I wrote the test for repository and mock repository ...
1
vote
1
answer
226
views
PHPunit - Testing class which uses class that has been tested in different test
I can't find good information about this topic so I'm summoning this question. We're writing tests for our application. Now there are nested classes which use other classes and so on. Each class has ...
0
votes
1
answer
80
views
Run phpunit with custom php path
I'm working on Redhat server, I'm going to add unit test (PHPUnit) to an existing application, PHP is installed on custom path /logi/php7211 (I shouldn't change any configuration), when I run the ...
2
votes
1
answer
2k
views
how to test laravel job on failure [closed]
i want test my laravel job on failure.
i use laravel 9 and latest phpunit version.
i think in job mocking exceptions will not be catching.
for example i have a job that in handle() functions it's ...
-1
votes
1
answer
948
views
PHPUnit giving me Too few arguments to function Tests\Unit\QuoteTest::test_count_of_quotes_equal_five()
Too few arguments to function Tests\Unit\QuoteTest::test_count_of_quotes_equal_five(), 0 passed in E:\laragon\www\torre-task1\vendor\phpunit\phpunit\src\Framework\TestCase.php on lin
e 1545 and ...
0
votes
1
answer
1k
views
Paratest, possible to test a specific function?
I run tests against a user Module using this command
./vendor/bin/paratest -pauto modules/User
That runs each test within the modules/User/Tests folder
I want to run a specific function in a specific ...
0
votes
0
answers
154
views
How to mock a method in another class using PHPUnit
I have the following code below
class Main
{
function foo()
{
$a = 1;
$b = 2;
$object = new CalculationObject($a, $b);
return $object->calculate();
}
}
class ...