1
0
mirror of https://github.com/danielstjules/Stringy.git synced 2025-09-01 09:03:03 +02:00

Merge Pull Request #18

This commit is contained in:
Daniel St. Jules
2013-12-15 00:15:34 -05:00
3 changed files with 111 additions and 61 deletions

View File

@@ -11,15 +11,45 @@ class StringyTestCase extends CommonTest
{
$stringy = new S('foo bar', 'UTF-8');
$this->assertInstanceOf('Stringy\Stringy', $stringy);
$this->assertEquals('foo bar', $stringy->str);
$this->assertEquals('foo bar', (string) $stringy);
$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));
$this->assertSame(' string ', (string) new S(' string '));
}
/**
* @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 resource as constructor argument');
}
public function testCreate()
{
$stringy = S::create('foo bar', 'UTF-8');
$this->assertInstanceOf('Stringy\Stringy', $stringy);
$this->assertEquals('foo bar', $stringy->str);
$this->assertEquals('foo bar', (string) $stringy);
$this->assertEquals('UTF-8', $stringy->encoding);
}