Exemplo n.º 1
0
 public function testWithQueryParams()
 {
     $url = new Uri('/hello?foo=30&bar=&baz');
     static::assertEquals('/hello?foo=30&bar=&baz', $url->__toString());
     static::assertEquals('/hello?foo=40&bar=&baz=', $url->withQueryParam('foo', 40)->__toString());
     static::assertEquals('/hello?foo=kkk+hhh&bar=&baz=', $url->withQueryParam('foo', 'kkk hhh')->__toString());
     static::assertEquals('/hello?bar=&baz=', $url->withQueryParam('foo', null)->__toString());
     static::assertEquals('/hello?bar=&baz=', $url->withoutQueryParam('foo')->__toString());
     static::assertEquals('/hello?foo=30&baz=', $url->withoutQueryParam('bar')->__toString());
     $url = new Uri('/hello?foo=30&bar=&baz');
     static::assertEquals('/hello?foo=30&bar=&baz', $url->__toString());
     static::assertEquals('/hello?foo=40&bar=&baz=', $url->withQueryParam('foo', 40)->__toString());
     static::assertEquals('/hello?bar=&baz=', $url->withQueryParam('foo', null)->__toString());
     static::assertEquals('/hello?foo=30&bar=&baz=&qux=40&quux=50', $url->withQueryParam('qux', 40)->withQueryParam('quux', 50)->__toString());
     static::assertEquals('/hello?bar=&baz=', $url->withoutQueryParam('foo')->__toString());
     static::assertEquals('/hello?foo=30&baz=', $url->withoutQueryParam('bar')->__toString());
 }
Exemplo n.º 2
0
 public function testToString()
 {
     $uri = new Uri('http://blog.wani.kr#fragment');
     $this->assertEquals('http://blog.wani.kr#fragment', $uri->__toString());
     $uri = new Uri('http://blog.wani.kr/path/name?hello=world#fragment');
     $this->assertEquals('http://blog.wani.kr/path/name?hello=world#fragment', $uri->__toString());
     $uri = (new Uri('http://blog.wani.kr/path/name?hello=world#fragment'))->withPath('hello/world');
     $this->assertEquals('http://blog.wani.kr/hello/world?hello=world#fragment', $uri->__toString());
     $uri = new Uri('nothing#frag');
     $this->assertEquals('nothing#frag', $uri->__toString());
 }