/** * @dataProvider data_provider * @param array $questionsAndAnswers * @param string $xpath * @param int $expectedCount */ public function test_factory_question(array $questionsAndAnswers, $xpath, $expectedCount) { foreach ($questionsAndAnswers as $question => $answer) { $this->mock_question_helper($question, $answer); } $xml = $this->call_create_on_sut(); $fluidXml = FluidXml::load($xml); $results = $fluidXml->query($xpath); self::assertCount($expectedCount, $results); }
$nodes = $dom->documentElement->childNodes; $fxml = FluidXml::load($nodes); $xml = new FluidXml(); $xml->appendChild($fxml); $expected = $doc; assert_equal_xml($xml, $expected); }); it('should add a FluidContext', function () use($doc, $dom) { $fxml = FluidXml::load($dom)->query('/doc/parent'); $xml = new FluidXml(); $xml->appendChild($fxml); $expected = $doc; assert_equal_xml($xml, $expected); }); it('should add many instances', function () use($doc, $dom) { $fxml = FluidXml::load($dom)->query('/doc/parent'); $xml = new FluidXml(); $xml->appendChild([$fxml, 'imported' => $fxml]); $expected = "<doc>\n" . " <parent>content</parent>\n" . " <imported>\n" . " <parent>content</parent>\n" . " </imported>\n" . "</doc>"; assert_equal_xml($xml, $expected); }); it('should throw for not supported input', function () { $xml = new FluidXml(); try { $xml->appendChild(0); } catch (\Exception $e) { $actual = $e; } assert_is_a($actual, \Exception::class); }); });
public function test_adds_testsuites() { $xml = FluidXml::load($this->sut->addTestSuite('foo', 'path/to/foo')->addTestSuite('bar', 'path/to/bar')->__toString()); $testsuites = $xml->query('/phpunit/testsuites/testsuite'); self::assertCount(2, $testsuites); self::assertEquals('foo', $testsuites[0]->getAttribute('name')); self::assertEquals('bar', $testsuites[1]->getAttribute('name')); $directories = $testsuites->query('//directory'); self::assertCount(2, $directories); self::assertEquals('path/to/foo', $directories[0]->nodeValue); self::assertEquals('path/to/bar', $directories[1]->nodeValue); }
function fluidify(...$arguments) { return \FluidXml\FluidXml::load(...$arguments); }
}); describe(':load()', function () { it('should import an XML file', function () { $file = "{$this->out_dir}.test_load.xml"; $doc = "<root>\n" . " <parent>content</parent>\n" . "</root>"; \file_put_contents($file, $doc); $xml = FluidXml::load($file); \unlink($file); $expected = $doc; assert_equal_xml($xml, $expected); }); it('should throw for not existing file', function () { $err_handler = \set_error_handler(function () { }); try { $xml = FluidXml::load('.impossible.xml'); } catch (\Exception $e) { $actual = $e; } \set_error_handler($err_handler); assert_is_a($actual, \Exception::class); }); }); if (\version_compare(\phpversion(), '7', '>=')) { describe(':new()', function () { it('should behave like FluidXml::__construct()', function () { $xml = new FluidXml(); eval('$alias = \\FluidXml\\FluidXml::new();'); $actual = $alias->xml(); $expected = $xml->xml(); \assert($actual === $expected, __($actual, $expected));