Skip to main content

Questions tagged [phpunit]

PHPUnit is a unit testing framework that is written in php. It is based on the JUnit for Java framework

9 votes
4 answers
5k views

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 ...
luisandani's user avatar
8 votes
2 answers
7k views

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 ...
TravisCarden's user avatar
7 votes
1 answer
3k views

How can I unit test my Eloquent models when I'm using the ORM outside of Laravel? What I'm hoping to do it run tests on each model but somehow mock the database connection/query/builder(?) object. ...
Martyn's user avatar
  • 795
6 votes
2 answers
3k views

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 ...
GordonM's user avatar
  • 6,525
6 votes
2 answers
2k views

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 ...
Matt Foxx Duncan's user avatar
5 votes
3 answers
648 views

I am working on adding test coverage for an application that previously didn't have any. One additional requirement that emerged is that one of the background processes should be able to process 100,...
rsman's user avatar
  • 1,309
4 votes
1 answer
184 views

JsonLogic is a data format (built on top of JSON) for storing and sharing rules between front-end and back-end code. It's essential that the same rule returns the same result whether executed by the ...
Jeremy Wadhams's user avatar
4 votes
2 answers
282 views

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 ...
DFriend's user avatar
  • 149
4 votes
0 answers
195 views

I'm currently writing unit tests for my PHP code. I've read that unit tests should not interract with external elements such as network and filesystem. In my code i have a curl wrapper class to ...
ᴄʀᴏᴢᴇᴛ's user avatar
3 votes
1 answer
698 views

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 ...
Dimitrios Desyllas's user avatar
3 votes
2 answers
3k views

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 ...
mohsenJsh's user avatar
  • 1,365
2 votes
4 answers
2k views

I have some code that reads five numbers from a database: class Repository extends DatabaseRepository { function getCoefficients(string $model) { return $this->getDatabaseLink()-&...
Dennis's user avatar
  • 8,267
2 votes
3 answers
2k views

My team is trying to find out the best way to test one of our components; the main scope is to check if the user/actor has the right to complete the operation requested. The component is formed by ...
Jecnua's user avatar
  • 23
2 votes
2 answers
408 views

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 ...
user avatar
2 votes
1 answer
1k views

When writing unit tests, should I specify the query that will be performed for interacting with the database? I can see both sides of this. On one hand, I want to make sure that the query that I ...
Schleis's user avatar
  • 3,426

15 30 50 per page