3
* This file is part of the Exporter package.
5
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
11
namespace SebastianBergmann\Exporter;
14
* @covers SebastianBergmann\Exporter\Exporter
16
class ExporterTest extends \PHPUnit_Framework_TestCase
23
protected function setUp()
25
$this->exporter = new Exporter;
28
public function exportProvider()
30
$obj2 = new \stdClass;
33
$obj3 = (object)array(1,2,"Test\r\n",4,5,6,7,8);
36
//@codingStandardsIgnoreStart
38
//@codingStandardsIgnoreEnd
43
$obj->text = "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext";
45
$obj->objectagain = $obj2;
46
$obj->array = array('foo' => 'bar');
49
$storage = new \SplObjectStorage;
50
$storage->attach($obj2);
51
$storage->foo = $obj2;
56
array(false, 'false'),
60
array(fopen('php://memory', 'r'), 'resource(%d) of type (stream)'),
62
array(array(array(1,2,3), array(3,4,5)),
78
// \n\r and \r is converted to \n
79
array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
94
array(new \stdClass, 'stdClass Object &%x ()'),
114
'object' => stdClass Object &%x (
117
'objectagain' => stdClass Object &%x
118
'array' => Array &%d (
121
'self' => stdClass Object &%x
125
array(array(), 'Array &%d ()'),
128
SplObjectStorage Object &%x (
129
'foo' => stdClass Object &%x (
133
'obj' => stdClass Object &%x
141
stdClass Object &%x (
154
chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5),
155
'Binary String: 0x000102030405'
158
implode('', array_map('chr', range(0x0e, 0x1f))),
159
'Binary String: 0x0e0f101112131415161718191a1b1c1d1e1f'
162
chr(0x00) . chr(0x09),
163
'Binary String: 0x0009'
173
* @dataProvider exportProvider
175
public function testExport($value, $expected)
177
$this->assertStringMatchesFormat(
179
$this->trimNewline($this->exporter->export($value))
183
public function testExport2()
185
if (PHP_VERSION === '5.3.3') {
186
$this->markTestSkipped('Skipped due to "Nesting level too deep - recursive dependency?" fatal error');
189
$obj = new \stdClass;
199
'text' => "this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext",
201
'objectagain' => $obj,
202
'array' => array('foo' => 'bar'),
205
$array['self'] = &$array;
226
'object' => stdClass Object &%x (
229
'objectagain' => stdClass Object &%x
230
'array' => Array &%d (
233
'self' => Array &%d (
251
'object' => stdClass Object &%x
252
'objectagain' => stdClass Object &%x
253
'array' => Array &%d (
261
$this->assertStringMatchesFormat(
263
$this->trimNewline($this->exporter->export($array))
267
public function shortenedExportProvider()
269
$obj = new \stdClass;
283
// \n\r and \r is converted to \n
284
array("this\nis\na\nvery\nvery\nvery\nvery\nvery\nvery\rlong\n\rtext", "'this\\nis\\na\\nvery\\nvery\\nvery\\nvery...g\\ntext'"),
285
array(new \stdClass, 'stdClass Object ()'),
286
array($obj, 'stdClass Object (...)'),
287
array(array(), 'Array ()'),
288
array($array, 'Array (...)'),
293
* @dataProvider shortenedExportProvider
295
public function testShortenedExport($value, $expected)
299
$this->trimNewline($this->exporter->shortenedExport($value))
303
public function provideNonBinaryMultibyteStrings()
306
array(implode('', array_map('chr', range(0x09, 0x0d))), 5),
307
array(implode('', array_map('chr', range(0x20, 0x7f))), 96),
308
array(implode('', array_map('chr', range(0x80, 0xff))), 128),
314
* @dataProvider provideNonBinaryMultibyteStrings
316
public function testNonBinaryStringExport($value, $expectedLength)
319
"~'.{{$expectedLength}}'\$~s",
320
$this->exporter->export($value)
324
public function testNonObjectCanBeReturnedAsArray()
326
$this->assertEquals(array(true), $this->exporter->toArray(true));
329
private function trimNewline($string)
331
return preg_replace('/[ ]*\n/', "\n", $string);