for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace TraderInteractive\Filter;
use PHPUnit\Framework\TestCase;
/**
* @coversDefaultClass \TraderInteractive\Filter\Url
*/
final class UrlTest extends TestCase
{
* @test
* @covers ::filter
public function filter()
$url = 'http://www.example.com';
$this->assertSame($url, Url::filter($url));
}
* @expectedException \TraderInteractive\Filter\Exception
* @expectedExceptionMessage Value '1' is not a string
public function filterNonstring()
Url::filter(1);
* @expectedExceptionMessage Value 'www.example.com' is not a valid url
public function filterNotValid()
Url::filter('www.example.com');
public function filterNullPass()
$this->assertSame(null, Url::filter(null, true));
* @expectedException Exception
* @expectedExceptionMessage Value 'NULL' is not a string
public function filterNullFail()
Url::filter(null);
* @expectedException InvalidArgumentException
* @expectedExceptionMessage $allowNull was not a boolean value
public function filterAllowNullNotBoolean()
Url::filter('a', 5);
5
integer
boolean
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: