1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
<?php
namespace Hamcrest\Type;
class IsScalarTest extends \Hamcrest\AbstractMatcherTestCase
{
protected function createMatcher()
{
return \Hamcrest\Type\IsScalar::scalarValue();
}
public function testEvaluatesToTrueIfArgumentMatchesType()
{
assertThat(true, scalarValue());
assertThat(5, scalarValue());
assertThat(5.3, scalarValue());
assertThat('5', scalarValue());
}
public function testEvaluatesToFalseIfArgumentDoesntMatchType()
{
assertThat(null, not(scalarValue()));
assertThat(array(), not(scalarValue()));
assertThat(array(5), not(scalarValue()));
assertThat(tmpfile(), not(scalarValue()));
assertThat(new \stdClass(), not(scalarValue()));
}
public function testHasAReadableDescription()
{
$this->assertDescription('a scalar', scalarValue());
}
public function testDecribesActualTypeInMismatchMessage()
{
$this->assertMismatchDescription('was null', scalarValue(), null);
$this->assertMismatchDescription('was an array ["foo"]', scalarValue(), array('foo'));
}
}
|