|
| 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