| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | if (!extension_loaded('syck')) |
|---|
| 4 | dl('syck.so'); |
|---|
| 5 | |
|---|
| 6 | date_default_timezone_set('GMT'); |
|---|
| 7 | |
|---|
| 8 | require_once "PHPUnit/Framework/TestCase.php"; |
|---|
| 9 | require 'helpers.php'; |
|---|
| 10 | |
|---|
| 11 | error_reporting(E_ALL | E_STRICT); |
|---|
| 12 | |
|---|
| 13 | class TestDump extends PHPUnit_Framework_TestCase |
|---|
| 14 | { |
|---|
| 15 | public function testNull() |
|---|
| 16 | { |
|---|
| 17 | $arr = array('qq' => null); |
|---|
| 18 | $this->assertEquals($arr, syck_load(syck_dump($arr))); |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | public function testArray() |
|---|
| 22 | { |
|---|
| 23 | $arr = array('a', 'b', 'c', 'd'); |
|---|
| 24 | $string = syck_dump($arr); |
|---|
| 25 | $arr2 = syck_load($string); |
|---|
| 26 | |
|---|
| 27 | $this->assertEquals($arr2, $arr); |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | public function testMovedArray() |
|---|
| 31 | { |
|---|
| 32 | $arr = array_flip(range(1, 1000)); |
|---|
| 33 | $string = syck_dump($arr); |
|---|
| 34 | $arr2 = syck_load($string); |
|---|
| 35 | |
|---|
| 36 | $this->assertEquals($arr2, $arr); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | public function testMixedArray() |
|---|
| 40 | { |
|---|
| 41 | $arr = array('test', 'a' => 'test2', 'test3'); |
|---|
| 42 | |
|---|
| 43 | $string = syck_dump($arr); |
|---|
| 44 | $arr2 = syck_load($string); |
|---|
| 45 | |
|---|
| 46 | $this->assertEquals($arr2, $arr); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public function testNegativeKeysArray() |
|---|
| 50 | { |
|---|
| 51 | $arr = array(-1 => 'test', -2 => 'test2', 0 => 'test3'); |
|---|
| 52 | |
|---|
| 53 | $string = syck_dump($arr); |
|---|
| 54 | $arr2 = syck_load($string); |
|---|
| 55 | |
|---|
| 56 | $this->assertEquals($arr2, $arr); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | public function testSerializable() |
|---|
| 60 | { |
|---|
| 61 | $obj = new MySerializable('some string'); |
|---|
| 62 | $this->assertEquals($obj, syck_load(syck_dump($obj))); |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | public function testDatetime() |
|---|
| 66 | { |
|---|
| 67 | $obj = new DateTime(); |
|---|
| 68 | $this->assertEquals($obj->format('U'), syck_load(syck_dump($obj))->format('U')); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public function testNumericStrings() |
|---|
| 72 | { |
|---|
| 73 | $obj = '73,123'; |
|---|
| 74 | $this->assertSame($obj, syck_load(syck_dump($obj))); |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | public function testLongStrings() |
|---|
| 78 | { |
|---|
| 79 | $obj = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\nUt enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; |
|---|
| 80 | $this->assertSame($obj, syck_load(syck_dump($obj))); |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | public function testLargeArrays() |
|---|
| 84 | { |
|---|
| 85 | $obj = range(1, 10000); |
|---|
| 86 | $this->assertSame($obj, syck_load(syck_dump($obj))); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|