Questions tagged [phpunit]
PHPUnit is a unit testing framework that is written in php. It is based on the JUnit for Java framework
28 questions
2
votes
2
answers
408
views
Unit testing for non-stateless units - how?
Firstly let me say I have never written a unit test in my life. I am trying to get the hang of PHPUnit, and so far it's working pretty well for me so far as "stateless" functions (that ...
3
votes
1
answer
698
views
Testing Queries Themselves with Test data is a Unit test or an Integration test?
In a php project that I maintain I have a database structure without migrations, hence no way to reproduce it or make on the fly a test database.
And the queries used to be performed on them are ...
9
votes
4
answers
5k
views
Is it a bad practice to separate the unit tests for a class? [closed]
My Classes normally have about 5-20 methods maximum, that implies that the class that has the unit tests has about the double of methods (counting dataProviders, setUp, ...)
I have thought to ...
-6
votes
1
answer
231
views
Why is automatically generating automated tests frowned upon?
First, the most obvious grouse someone has against this I can think of is the intricacies of an actual method. It's not enough to merely ensure no errors are thrown. Functions usually contain ...
-2
votes
2
answers
1k
views
Writing unit test cases are taking time, any advice?
I am new to unit testing. Started working on unit test using PHPUnit. But it seems to be taking too much time. If consider I take 3 hours to write a Class, its taking my 7 hours to write test case for ...
2
votes
4
answers
2k
views
How to write a unit test for a repository method that returns some data, where data can change over time?
I have some code that reads five numbers from a database:
class Repository extends DatabaseRepository
{
function getCoefficients(string $model)
{
return $this->getDatabaseLink()-&...
6
votes
2
answers
3k
views
Unit Testing: Method per test versus data provider
I'm having a bit of a philosophical argument with one of my colleagues regarding the "right" way to do unit tests (in this case with PHPUnit). I'm of the opinion that you should write one test method ...
4
votes
2
answers
282
views
Bad Practice - having a SUT use a different execution path when in test mode?
I recently ran across some code in a public repo that I'd thought... just plain wrong. The first thing I noticed was
/**
* Sets a test mode status.
*
* @param boolean $mode Mode to set
*/
public ...
2
votes
1
answer
761
views
Is bad idea to utilize helper functions on integration tests?
In my job I have a small disagreement on whether we should utilize helper functions for making datasets especially in laravel framework. A sample for the test is:
namespace Tests\MyAppTests;
use ...
1
vote
1
answer
1k
views
How to unit test database queries based on current date?
Is there a feasible way of testing SQL queries that contain things like CURRENT_DATE and NOW() in a unit test?
For example:
public function deletePastEntries(): bool {
$sql = "DELETE FROM queue ...
2
votes
2
answers
4k
views
Initialising variable within setUp() method or actual test method when changes are necessary?
I'm starting to wrap my head around PHPunit.
My questions is the following.
Whenever I use variables that do not change within my range of test methods I can initialize them within my setUp() ...
0
votes
1
answer
685
views
Unit tests involving library functions and objects
I am making a project using the Laravel framework.
I plan to create unit tests for my project. But I feel I don't really have an idea what to test because I mostly use library or framework functions. ...
8
votes
2
answers
7k
views
Is it possible to mock and inject traits in PHPUnit?
I need to extend a third party class I cannot modify. The class's dependencies are for the most part injected through the constructor, making them easy to mock. However the class also uses methods ...
6
votes
2
answers
2k
views
How well am I writing my tests?
I've been coding as a career for about 2 years now but am just now writing my first "real" tests for a non-trivial application. I've been trying to follow best practices I've picked up from the ...
3
votes
2
answers
3k
views
How unit test service method that use repository method
For service methods that call repository methods to interact with database how could I unit test these service methods?
For example,
public function updateSlideshow($data){
// do some logic and ...