I would like to be able test that a result is an integer (1,2,3...) where the function could return any number, e.g.:
$new_id = generate_id();
I had thought it would be something like:
$this->assertInstanceOf('int', $new_id);
But I get this error:
Argument #1 of PHPUnit_Framework_Assert::assertInstanceOf() must be a class or interface name
The assertEquals() function is a builtin function in PHPUnit and is used to assert whether the actual obtained value is equals to expected value or not. This assertion will return true in the case if the expected value is the same as the actual value else returns false.
phpunit Assertions Assert an Exception is ThrownexpectException($exception) expectExceptionMessage($message) expectExceptionCode($code)
How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.
Likewise, PHPUnit mock object is a simulated object that performs the behavior of a part of the application that is required in the unit test. The developers control the mock object by defining the pre-computed results on the actions.
$this->assertInternalType("int", $id);
Edit: As of PHPUnit 8, the answer is:
$this->assertIsInt($id);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With