/** * Get the record XML formatter. * * @param Communicator $communicator Communicator * @param array $settings Additional settings * * @return RecordXmlFormatter */ protected function getFormatter(Communicator $communicator, array $settings) { // Build the formatter: $formatter = new RecordXmlFormatter($settings); // Load set names if we're going to need them: if ($formatter->needsSetNames()) { $loader = $this->getSetLoader($communicator, $settings); if ($writer = $this->getConsoleWriter($settings)) { $loader->setOutputWriter($writer); } $formatter->setSetNames($loader->getNames()); } return $formatter; }
/** * Test set name injection. * * @return void */ public function testSetNameInjection() { $formatter = new RecordXmlFormatter(['injectSetName' => 'setName']); // Default behavior -- use set spec if no set name provided: $result = $formatter->format('foo', $this->getRecordFromFixture()); $xml = simplexml_load_string($result); $this->assertEquals(2, count($xml->setName)); $this->assertEquals('TESTING_DIGI_TEST', (string) $xml->setName[0]); $this->assertEquals('TESTING_DIGI', (string) $xml->setName[1]); // Check correct behavior when set names provided: $formatter->setSetNames(['TESTING_DIGI_TEST' => 'foo', 'TESTING_DIGI' => 'bar']); $result2 = $formatter->format('foo', $this->getRecordFromFixture()); $xml2 = simplexml_load_string($result2); $this->assertEquals(2, count($xml2->setName)); $this->assertEquals('foo', (string) $xml2->setName[0]); $this->assertEquals('bar', (string) $xml2->setName[1]); }