Server IP : 127.0.0.2 / Your IP : 3.129.250.3 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/guzzlehttp/streams/tests/ |
Upload File : |
<?php namespace GuzzleHttp\Tests\Stream; use GuzzleHttp\Stream\StreamInterface; use GuzzleHttp\Stream\Stream; use GuzzleHttp\Stream\StreamDecoratorTrait; class Str implements StreamInterface { use StreamDecoratorTrait; } /** * @covers GuzzleHttp\Stream\StreamDecoratorTrait */ class StreamDecoratorTraitTest extends \PHPUnit_Framework_TestCase { private $a; private $b; private $c; public function setUp() { $this->c = fopen('php://temp', 'r+'); fwrite($this->c, 'foo'); fseek($this->c, 0); $this->a = Stream::factory($this->c); $this->b = new Str($this->a); } public function testCatchesExceptionsWhenCastingToString() { $s = $this->getMockBuilder('GuzzleHttp\Stream\StreamInterface') ->setMethods(['read']) ->getMockForAbstractClass(); $s->expects($this->once()) ->method('read') ->will($this->throwException(new \Exception('foo'))); $msg = ''; set_error_handler(function ($errNo, $str) use (&$msg) { $msg = $str; }); echo new Str($s); restore_error_handler(); $this->assertContains('foo', $msg); } public function testToString() { $this->assertEquals('foo', (string) $this->b); } public function testHasSize() { $this->assertEquals(3, $this->b->getSize()); $this->assertSame($this->b, $this->b->setSize(2)); $this->assertEquals(2, $this->b->getSize()); } public function testReads() { $this->assertEquals('foo', $this->b->read(10)); } public function testCheckMethods() { $this->assertEquals($this->a->isReadable(), $this->b->isReadable()); $this->assertEquals($this->a->isWritable(), $this->b->isWritable()); $this->assertEquals($this->a->isSeekable(), $this->b->isSeekable()); } public function testSeeksAndTells() { $this->assertTrue($this->b->seek(1)); $this->assertEquals(1, $this->a->tell()); $this->assertEquals(1, $this->b->tell()); $this->assertTrue($this->b->seek(0)); $this->assertEquals(0, $this->a->tell()); $this->assertEquals(0, $this->b->tell()); $this->assertTrue($this->b->seek(0, SEEK_END)); $this->assertEquals(3, $this->a->tell()); $this->assertEquals(3, $this->b->tell()); } public function testGetsContents() { $this->assertEquals('foo', $this->b->getContents()); $this->assertEquals('', $this->b->getContents()); $this->b->seek(1); $this->assertEquals('oo', $this->b->getContents(1)); } public function testCloses() { $this->b->close(); $this->assertFalse(is_resource($this->c)); } public function testDetaches() { $this->b->detach(); $this->assertFalse($this->b->isReadable()); } /** * @expectedException \GuzzleHttp\Stream\Exception\CannotAttachException */ public function testCannotAttachByDefault() { $this->b->attach('a'); } public function testWrapsMetadata() { $this->assertSame($this->b->getMetadata(), $this->a->getMetadata()); $this->assertSame($this->b->getMetadata('uri'), $this->a->getMetadata('uri')); } public function testWrapsWrites() { $this->b->seek(0, SEEK_END); $this->b->write('foo'); $this->assertEquals('foofoo', (string) $this->a); } /** * @expectedException \UnexpectedValueException */ public function testThrowsWithInvalidGetter() { $this->b->foo; } /** * @expectedException \BadMethodCallException */ public function testThrowsWhenGetterNotImplemented() { $s = new BadStream(); $s->stream; } } class BadStream { use StreamDecoratorTrait; public function __construct() {} }