I am trying to validate that a php7 function accept only integers.
This is the class:
<?php
declare(strict_types=1);
class Post
{
private $id;
public function setId(int $id)
{
$this->id = $id;
}
}
And this is the test:
<?php
declare(strict_types=1);
class PostTest extends \PHPUnit_Framework_TestCase
{
private function getPostEntity()
{
return new Post();
}
public function testSetId()
{
$valuesExpected = [123, '123a'];
foreach ($valuesExpected as $input) {
$this->getPostEntity()->setId($input);
}
}
}
The error I get is:
TypeError: Argument 1 passed to Post::setId() must be of the type integer, string given, called in /path/test/PostTest.php on line 35
Is it possible to validate such error? also, does it make any sense to run such a check?