Файл: gapps/vendor/hamcrest/hamcrest-php/tests/Hamcrest/MatcherAssertTest.php
Строк: 157
<?php
namespace Hamcrest;
class MatcherAssertTest extends PhpUnit_Framework_TestCase
{
protected function setUp()
{
HamcrestMatcherAssert::resetCount();
}
public function testResetCount()
{
HamcrestMatcherAssert::assertThat(true);
self::assertEquals(1, HamcrestMatcherAssert::getCount(), 'assertion count');
HamcrestMatcherAssert::resetCount();
self::assertEquals(0, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithTrueArgPasses()
{
HamcrestMatcherAssert::assertThat(true);
HamcrestMatcherAssert::assertThat('non-empty');
HamcrestMatcherAssert::assertThat(1);
HamcrestMatcherAssert::assertThat(3.14159);
HamcrestMatcherAssert::assertThat(array(true));
self::assertEquals(5, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithFalseArgFails()
{
try {
HamcrestMatcherAssert::assertThat(false);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat(null);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat('');
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat(0);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat(0.0);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat(array());
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('', $ex->getMessage());
}
self::assertEquals(6, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithIdentifierAndTrueArgPasses()
{
HamcrestMatcherAssert::assertThat('identifier', true);
HamcrestMatcherAssert::assertThat('identifier', 'non-empty');
HamcrestMatcherAssert::assertThat('identifier', 1);
HamcrestMatcherAssert::assertThat('identifier', 3.14159);
HamcrestMatcherAssert::assertThat('identifier', array(true));
self::assertEquals(5, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithIdentifierAndFalseArgFails()
{
try {
HamcrestMatcherAssert::assertThat('identifier', false);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('identifier', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat('identifier', null);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('identifier', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat('identifier', '');
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('identifier', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat('identifier', 0);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('identifier', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat('identifier', 0.0);
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('identifier', $ex->getMessage());
}
try {
HamcrestMatcherAssert::assertThat('identifier', array());
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals('identifier', $ex->getMessage());
}
self::assertEquals(6, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithActualValueAndMatcherArgsThatMatchPasses()
{
HamcrestMatcherAssert::assertThat(true, is(true));
self::assertEquals(1, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithActualValueAndMatcherArgsThatDontMatchFails()
{
$expected = 'expected';
$actual = 'actual';
$expectedMessage =
'Expected: "expected"' . PHP_EOL .
' but: was "actual"';
try {
HamcrestMatcherAssert::assertThat($actual, equalTo($expected));
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals($expectedMessage, $ex->getMessage());
self::assertEquals(1, HamcrestMatcherAssert::getCount(), 'assertion count');
}
}
public function testAssertThatWithIdentifierAndActualValueAndMatcherArgsThatMatchPasses()
{
HamcrestMatcherAssert::assertThat('identifier', true, is(true));
self::assertEquals(1, HamcrestMatcherAssert::getCount(), 'assertion count');
}
public function testAssertThatWithIdentifierAndActualValueAndMatcherArgsThatDontMatchFails()
{
$expected = 'expected';
$actual = 'actual';
$expectedMessage =
'identifier' . PHP_EOL .
'Expected: "expected"' . PHP_EOL .
' but: was "actual"';
try {
HamcrestMatcherAssert::assertThat('identifier', $actual, equalTo($expected));
self::fail('expected assertion failure');
} catch (HamcrestAssertionError $ex) {
self::assertEquals($expectedMessage, $ex->getMessage());
self::assertEquals(1, HamcrestMatcherAssert::getCount(), 'assertion count');
}
}
public function testAssertThatWithNoArgsThrowsErrorAndDoesntIncrementCount()
{
try {
HamcrestMatcherAssert::assertThat();
self::fail('expected invalid argument exception');
} catch (InvalidArgumentException $ex) {
self::assertEquals(0, HamcrestMatcherAssert::getCount(), 'assertion count');
}
}
public function testAssertThatWithFourArgsThrowsErrorAndDoesntIncrementCount()
{
try {
HamcrestMatcherAssert::assertThat(1, 2, 3, 4);
self::fail('expected invalid argument exception');
} catch (InvalidArgumentException $ex) {
self::assertEquals(0, HamcrestMatcherAssert::getCount(), 'assertion count');
}
}
}