function testSerializeDefaultNamespace() { $service = new Service(); $service->elementMap['{urn:test}root'] = function ($reader) { return enum($reader, 'urn:test'); }; $xml = <<<XML <?xml version="1.0"?> <root xmlns="urn:test"> <foo1/> <foo2/> </root> XML; $result = $service->parse($xml); $expected = ['foo1', 'foo2']; $this->assertEquals($expected, $result); }
function testRead() { $service = new Service(); $service->elementMap['{urn:test}collection'] = function ($reader) { return repeatingElements($reader, '{urn:test}item'); }; $xml = <<<XML <?xml version="1.0"?> <collection xmlns="urn:test"> <item>foo</item> <item>bar</item> </collection> XML; $result = $service->parse($xml); $expected = ['foo', 'bar']; $this->assertEquals($expected, $result); }
/** * Parse sapphp.xml file. * * @return bool|string Boolean if not found/no data * File path if found. */ private static function parseXmlFile() { $path = realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', ''])) . DIRECTORY_SEPARATOR . 'sapphp.xml'; if (!file_exists($path)) { return $path; } $xml = file_get_contents($path); $service = new Service(); $service->elementMap = ['{}sapphp' => function ($reader) { return \Sabre\Xml\Deserializer\keyValue($reader, ''); }, '{}box' => function ($reader) { return \Sabre\Xml\Deserializer\keyValue($reader, ''); }]; $repository = collect($service->parse($xml)['boxes'])->pluck('value'); if ($repository->count() === 0) { return $path; } self::$repository = $repository; return true; }