public function testLoad() { $loader = new XmlFileReader(new FileLocator(__DIR__ . '/../Fixtures/')); $array = $loader->load('foo.xml'); $this->assertTrue(is_array($array)); $this->assertTrue(count($array['example']) == 2); $this->assertEquals($array['example'][0], "Example 1"); try { $array = $loader->load('foo2.xml'); $this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist'); } catch (\Exception $e) { $this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist'); $this->assertStringStartsWith('The file "foo2.xml" does not exist (in:', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist'); } }
/** * Obtiene el arreglo de excepciones configuradas in el fichero primero yml y si no está xml * * @param $direccionFile * @return array * @throws \InvalidArgumentException En caso de no encontrar el fichero o no estar bien estructurado. */ public function getArrayExcepcionesInFile($direccionFile) { $locator = new FileLocator($direccionFile); try { $loader = new YamlFileReader($locator); $locator->locate("excepciones.yml"); $excepciones = $loader->load('excepciones.yml'); return $excepciones['excepciones']; } catch (\InvalidArgumentException $exc) { try { $loader = new XmlFileReader($locator); $locator->locate("excepciones.xml"); $excepciones = $loader->load('excepciones.xml'); return $excepciones; } catch (\InvalidArgumentException $exc) { throw $exc; } } }