Skip to content

Commit 49b95d9

Browse files
committed
test: base test
1 parent d1e6a1d commit 49b95d9

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

tests/BaseTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Ahc\Underscore\Tests;
4+
5+
use Ahc\Underscore\UnderscoreBase as _;
6+
7+
class Stub
8+
{
9+
public function toArray()
10+
{
11+
return ['a', 'b', 'c'];
12+
}
13+
}
14+
15+
class Json implements \JsonSerializable
16+
{
17+
public function jsonSerialize()
18+
{
19+
return ['a' => 1, 'b' => 2, 'c' => 3];
20+
}
21+
}
22+
23+
class BaseTest extends \PHPUnit_Framework_TestCase
24+
{
25+
public function test_asArray()
26+
{
27+
$this->assertSame(['one'], (new _)->asArray('one'));
28+
$this->assertSame([1, 2], (new _)->asArray([1, 2]));
29+
$this->assertSame(['a', 'b', 'c'], (new _)->asArray(new Stub));
30+
$this->assertSame(['a', 1, 'c', 3], (new _)->asArray(new _(['a', 1, 'c', 3])));
31+
$this->assertSame(['a' => 1, 'b' => 2, 'c' => 3], (new _)->asArray(new Json));
32+
}
33+
34+
public function test_alias()
35+
{
36+
$this->assertTrue(class_exists('Ahc\Underscore'));
37+
38+
$this->assertEquals(new \Ahc\Underscore\Underscore, new \Ahc\Underscore);
39+
}
40+
41+
public function test_underscore()
42+
{
43+
$this->assertTrue(function_exists('underscore'));
44+
45+
$this->assertInstanceOf(_::class, underscore());
46+
}
47+
}

0 commit comments

Comments
 (0)