Linked Questions
13 questions linked to/from PHPUnit assert that an exception was thrown?
4
votes
1
answer
13k
views
Assert exception with PHPUnit [duplicate]
I have a function to calculate the value of one square and i want to make the test of this.
The function squaring is this:
public function squaring($number)
{
if ($number == 0) {
...
0
votes
1
answer
246
views
PHPUnit: testing parameter types [duplicate]
I want to test a method that can take, as a parameter, either an instance of class Foo or a string. If anything else is passed it throws an Exception.
How do I test that if I don't pass one of the ...
3
votes
6
answers
12k
views
How to check the exception thrown correctly by PHPUnit?
I have div() in Cal class in my CalTest class has following methods to test the div().
public fucnction div($a,$b){
if($b == 0){
throw new Exception("Divided by zero");
}
return $a/$b
}
...
6
votes
2
answers
2k
views
Select impossible value in select inputs with Symfony DomCrawler
I would like to test the behaviour of my application if I send wrong values in a select input in form.
This is my form in HTML :
<form (...)>
(...)
<select name="select_input">
&...
2
votes
1
answer
2k
views
Can't make assertions because exceptions are crashing my test in Laravel
I want to test the response when I try to send invalid data to the API.
/** @test */
public function request_schedule_with_invalid_bdate()
{
$response = $this->json('GET', '/api/schedule', [
...
1
vote
1
answer
3k
views
testing exceptions with phpunit
i am trying to test a function when i know error i going to be thrown. the function looks like this:
function testSetAdsData_dataIsNull(){
$dataArr = null;
$fixture = new AdGroup();
...
1
vote
1
answer
2k
views
PHPUnit not catching exception
Looking for some help to write better code /tests, but seemed to have stumbled across a problem straight away - any help would be greatly appreciated.
Script:
$feed = 'App\Http\Services\Supplier\...
0
votes
1
answer
440
views
Zend PHPUnit testing a model, asserting a Zend_Exception indeed occurs as expected
Consider the following code in a model. the function deleteUser(NULL) will trigger an exception.
class Model_UserModel extends Zend_Db_Table_Abstract{
protected $_name = 'users';
protected $...
1
vote
1
answer
372
views
How can I use a string instead of an integer as the code of a custom exception in PHP?
I've been searching for a way to use a string instead of an integer for the code of a custom exception, but much to my surprise this seems impossible to do!
I'd like to be able to throw such an ...
0
votes
1
answer
301
views
How to ignore PHPUnit errors, which do not affect tests, in console?
When I run PHPUnit tests, there are some errors displayed in my console, even though these errors do not affect my tests (they all pass). And it is very annoying to see all these errors
displayed ...
0
votes
0
answers
153
views
How to test an exception in PHPUnit WITHOUT testing the exception message?
I want to test my thrown exception, but test the exception class only, and not have to test the exception message. I saw this thread which was helpful, but didn't specifically address this: PHPUnit ...
1
vote
1
answer
109
views
Asserting exceptions using PHPUnit
I am testing this function using PHPUnit:
public function testSetAdsData_dataIsNull()
{
$dataArr = null;
$fixture = new AdGroup();
try {
$fixture->setAdsData($dataArr);
} ...
0
votes
0
answers
69
views
PHPUNIT Exceptions
I've already test this method before, but only the try block, I don't know so about PHP Exceptions, My goal is to do a test unit inside catch block body and all its logic.
public function send(User $...