Example #1
0
         \assert($actual === $expected, __($actual, $expected));
     });
     it('should store a fragment of the XML document in a file', function () {
         $xml = new FluidXml();
         $xml->appendChild('parent', true)->appendChild('child', 'content');
         $file = "{$this->out_dir}.test_save2.xml";
         $xml->query('//child')->save($file);
         $actual = \trim(\file_get_contents($file));
         $expected = "<child>content</child>";
         \unlink($file);
         \assert($actual === $expected, __($actual, $expected));
     });
     it('should throw for not writable file', function () {
         $xml = new FluidXml();
         try {
             $xml->save('/.impossible/tmp/out.xml');
         } catch (\Exception $e) {
             $actual = $e;
         }
         assert_is_a($actual, \Exception::class);
     });
 });
 describe('.add', function () {
     it('should be fluid', function () {
         assert_is_fluid('add', 'a');
     });
     it('should behave like .appendChild', function () {
         $xml = new FluidXml();
         $xml->appendChild('parent', true)->appendChild(['child1', 'child2'], ['class' => 'child']);
         $alias = new FluidXml();
         $alias->add('parent', true)->add(['child1', 'child2'], ['class' => 'child']);