Server IP : 127.0.0.2 / Your IP : 52.14.93.216 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/vendor/hamcrest/hamcrest-php/tests/Hamcrest/ |
Upload File : |
<?php namespace Hamcrest; class MatcherAssertTest extends \PhpUnit_Framework_TestCase { protected function setUp() { \Hamcrest\MatcherAssert::resetCount(); } public function testResetCount() { \Hamcrest\MatcherAssert::assertThat(true); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); \Hamcrest\MatcherAssert::resetCount(); self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithTrueArgPasses() { \Hamcrest\MatcherAssert::assertThat(true); \Hamcrest\MatcherAssert::assertThat('non-empty'); \Hamcrest\MatcherAssert::assertThat(1); \Hamcrest\MatcherAssert::assertThat(3.14159); \Hamcrest\MatcherAssert::assertThat(array(true)); self::assertEquals(5, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithFalseArgFails() { try { \Hamcrest\MatcherAssert::assertThat(false); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(null); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(''); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(0.0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat(array()); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('', $ex->getMessage()); } self::assertEquals(6, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithIdentifierAndTrueArgPasses() { \Hamcrest\MatcherAssert::assertThat('identifier', true); \Hamcrest\MatcherAssert::assertThat('identifier', 'non-empty'); \Hamcrest\MatcherAssert::assertThat('identifier', 1); \Hamcrest\MatcherAssert::assertThat('identifier', 3.14159); \Hamcrest\MatcherAssert::assertThat('identifier', array(true)); self::assertEquals(5, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithIdentifierAndFalseArgFails() { try { \Hamcrest\MatcherAssert::assertThat('identifier', false); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', null); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', ''); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', 0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', 0.0); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } try { \Hamcrest\MatcherAssert::assertThat('identifier', array()); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals('identifier', $ex->getMessage()); } self::assertEquals(6, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithActualValueAndMatcherArgsThatMatchPasses() { \Hamcrest\MatcherAssert::assertThat(true, is(true)); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithActualValueAndMatcherArgsThatDontMatchFails() { $expected = 'expected'; $actual = 'actual'; $expectedMessage = 'Expected: "expected"' . PHP_EOL . ' but: was "actual"'; try { \Hamcrest\MatcherAssert::assertThat($actual, equalTo($expected)); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals($expectedMessage, $ex->getMessage()); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } public function testAssertThatWithIdentifierAndActualValueAndMatcherArgsThatMatchPasses() { \Hamcrest\MatcherAssert::assertThat('identifier', true, is(true)); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } public function testAssertThatWithIdentifierAndActualValueAndMatcherArgsThatDontMatchFails() { $expected = 'expected'; $actual = 'actual'; $expectedMessage = 'identifier' . PHP_EOL . 'Expected: "expected"' . PHP_EOL . ' but: was "actual"'; try { \Hamcrest\MatcherAssert::assertThat('identifier', $actual, equalTo($expected)); self::fail('expected assertion failure'); } catch (\Hamcrest\AssertionError $ex) { self::assertEquals($expectedMessage, $ex->getMessage()); self::assertEquals(1, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } public function testAssertThatWithNoArgsThrowsErrorAndDoesntIncrementCount() { try { \Hamcrest\MatcherAssert::assertThat(); self::fail('expected invalid argument exception'); } catch (\InvalidArgumentException $ex) { self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } public function testAssertThatWithFourArgsThrowsErrorAndDoesntIncrementCount() { try { \Hamcrest\MatcherAssert::assertThat(1, 2, 3, 4); self::fail('expected invalid argument exception'); } catch (\InvalidArgumentException $ex) { self::assertEquals(0, \Hamcrest\MatcherAssert::getCount(), 'assertion count'); } } }