/** * Parses a MySQL dump XML file. * * @param $source * @return Fixture * @throws \TheIconic\Fixtures\Exception\InvalidParserException */ public function parse($source) { $fixtureArray = []; $z = new \XMLReader(); $z->open($source); $doc = new \DOMDocument(); while ($z->read() && $z->name !== 'table_data') { } $tableName = $z->getAttribute('name'); $rowNum = 0; while ($z->read() && $z->name !== 'row') { } while ($z->name === 'row') { $node = simplexml_import_dom($doc->importNode($z->expand(), true)); $totalAttributes = $node->count(); for ($i = 0; $i < $totalAttributes; $i++) { foreach ($node->field[$i]->attributes() as $attribute) { $attribute = (string) $attribute; $value = (string) $node->field[$i]; $namespaces = $node->field[$i]->getNamespaces(true); if (empty($namespaces)) { $fixtureArray[$tableName][$rowNum][$attribute] = $value; } } } $rowNum++; $z->next('row'); } if (empty($fixtureArray)) { throw new InvalidParserException("It was not possible to parse the XML file: {$source}"); } return Fixture::create($fixtureArray); }
/** * Parses a MySQL dump XML file. * * @param $source * @return Fixture */ public function parse($source) { try { return parent::parse($source); } catch (InvalidParserException $e) { $z = new \XMLReader(); $z->open($source); while ($z->read() && $z->name !== 'table_data') { } $tableName = $z->getAttribute('name'); $fixtureArray[$tableName] = []; return Fixture::create($fixtureArray); } }
/** * Parses a Yaml file. * * @param $source * @return Fixture */ public function parse($source) { $fixtureArray = Yaml::parse(file_get_contents($source)); return Fixture::create($fixtureArray); }
public function setUp() { $this->testFixture = Fixture::create($this->testParsedData); }
/** * @expectedException \TheIconic\Fixtures\Exception\PersisterException */ public function testInvalidPersist() { $persister = new TheIconic\Fixtures\Persister\PDO\MysqlPersister($_ENV['pdo_host'], $_ENV['pdo_database'], $_ENV['pdo_username'], $_ENV['pdo_password']); $persister->persist(Fixture::create($this->testParsedBadData)); }