From 8f40b3495d9f5c7abcb51d0e424930af5b5b495c Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Wed, 2 Sep 2015 23:35:32 -0700 Subject: [PATCH] String is now optional in Stringy constructor --- src/Stringy.php | 2 +- tests/StringyTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Stringy.php b/src/Stringy.php index 73b3f2f..63dcbd8 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -31,7 +31,7 @@ class Stringy implements \Countable, \IteratorAggregate, \ArrayAccess * @throws \InvalidArgumentException if an array or object without a * __toString method is passed as the first argument */ - public function __construct($str, $encoding = null) + public function __construct($str = '', $encoding = null) { if (is_array($str)) { throw new \InvalidArgumentException( diff --git a/tests/StringyTest.php b/tests/StringyTest.php index 47b825d..03ef5fb 100644 --- a/tests/StringyTest.php +++ b/tests/StringyTest.php @@ -24,6 +24,13 @@ class StringyTestCase extends PHPUnit_Framework_TestCase $this->assertEquals('UTF-8', $stringy->getEncoding()); } + public function testEmptyConstruct() + { + $stringy = new S(); + $this->assertStringy($stringy); + $this->assertEquals('', (string) $stringy); + } + /** * @expectedException InvalidArgumentException */