1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-08-13 00:34:11 +02:00

Stringy must correctly handle non-string arguments and implicitly cast to string to avoid problems in __toString() method

This commit is contained in:
gotterdemarung
2013-12-10 22:15:28 +02:00
parent bc96cdad0c
commit 75404a0338

View File

@@ -15,6 +15,35 @@ class StringyTestCase extends CommonTest
$this->assertEquals('UTF-8', $stringy->encoding); $this->assertEquals('UTF-8', $stringy->encoding);
} }
public function testToString()
{
// Correct work for primitives
$this->assertSame('', (string) new S(null));
$this->assertSame('', (string) new S(false));
$this->assertSame('1', (string) new S(true));
$this->assertSame('-9', (string) new S(-9));
$this->assertSame('1.18', (string) new S(1.18));
}
/**
* @expectedException InvalidArgumentException
*/
public function testToStringArray()
{
(string) new S(array());
$this->fail('Expecting exception on receiving array as constructor argument');
}
/**
* @expectedException InvalidArgumentException
*/
public function testToStringResource()
{
(string) new S(fopen('php://stdout', 'w'));
$this->fail('Expecting exception on receiving array as constructor argument');
}
public function testCreate() public function testCreate()
{ {
$stringy = S::create('foo bar', 'UTF-8'); $stringy = S::create('foo bar', 'UTF-8');