015-move-errors.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. --TEST--
  2. XMLReader: libxml2 XML Reader, Move cursor to a named attribute within a namespace, with invalid arguments
  3. --CREDITS--
  4. Mark Baker mark@lange.demon.co.uk at the PHPNW2017 Conference for PHP Testfest 2017
  5. --EXTENSIONS--
  6. xmlreader
  7. --FILE--
  8. <?php
  9. // Set up test data in a new file
  10. $xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
  11. <books xmlns:ns1="http://www.ns1.namespace.org/" xmlns:ns2="http://www.ns2.namespace.org/"><book ns1:num="1" ns2:idx="2" ns1:idx="3" ns2:isbn="4">book1</book></books>';
  12. $filename = __DIR__ . '/015-move-errors.xml';
  13. file_put_contents($filename, $xmlstring);
  14. // Load test data into a new XML Reader
  15. $reader = new XMLReader();
  16. if (!$reader->open($filename)) {
  17. exit('XML could not be read');
  18. }
  19. // Parse the data
  20. while ($reader->read()) {
  21. if ($reader->nodeType != XMLREADER::END_ELEMENT) {
  22. // Find the book node
  23. if ($reader->nodeType == XMLREADER::ELEMENT && $reader->name == 'book') {
  24. // Test for missing namespace argument
  25. try {
  26. $reader->moveToAttributeNs('idx', null);
  27. } catch (ValueError $exception) {
  28. echo $exception->getMessage() . "\n";
  29. }
  30. }
  31. }
  32. }
  33. // clean up
  34. $reader->close();
  35. ?>
  36. --CLEAN--
  37. <?php
  38. unlink(__DIR__.'/015-move-errors.xml');
  39. ?>
  40. --EXPECTF--
  41. Deprecated: XMLReader::moveToAttributeNs(): Passing null to parameter #2 ($namespace) of type string is deprecated in %s on line %d
  42. XMLReader::moveToAttributeNs(): Argument #2 ($namespace) cannot be empty