ManifestSerializerTest.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace PharIo\Manifest;
  3. use PharIo\Version\Version;
  4. /**
  5. * @covers \PharIo\Manifest\ManifestSerializer
  6. *
  7. * @uses \PharIo\Manifest\ApplicationName
  8. * @uses \PharIo\Manifest\Author
  9. * @uses \PharIo\Manifest\AuthorCollection
  10. * @uses \PharIo\Manifest\AuthorCollectionIterator
  11. * @uses \PharIo\Manifest\AuthorElement
  12. * @uses \PharIo\Manifest\AuthorElementCollection
  13. * @uses \PharIo\Manifest\BundledComponent
  14. * @uses \PharIo\Manifest\BundledComponentCollection
  15. * @uses \PharIo\Manifest\BundledComponentCollectionIterator
  16. * @uses \PharIo\Manifest\BundlesElement
  17. * @uses \PharIo\Manifest\ComponentElement
  18. * @uses \PharIo\Manifest\ComponentElementCollection
  19. * @uses \PharIo\Manifest\ContainsElement
  20. * @uses \PharIo\Manifest\CopyrightElement
  21. * @uses \PharIo\Manifest\CopyrightInformation
  22. * @uses \PharIo\Manifest\ElementCollection
  23. * @uses \PharIo\Manifest\Email
  24. * @uses \PharIo\Manifest\ExtElement
  25. * @uses \PharIo\Manifest\ExtElementCollection
  26. * @uses \PharIo\Manifest\License
  27. * @uses \PharIo\Manifest\LicenseElement
  28. * @uses \PharIo\Manifest\Manifest
  29. * @uses \PharIo\Manifest\ManifestDocument
  30. * @uses \PharIo\Manifest\ManifestDocumentMapper
  31. * @uses \PharIo\Manifest\ManifestElement
  32. * @uses \PharIo\Manifest\ManifestLoader
  33. * @uses \PharIo\Manifest\PhpElement
  34. * @uses \PharIo\Manifest\PhpExtensionRequirement
  35. * @uses \PharIo\Manifest\PhpVersionRequirement
  36. * @uses \PharIo\Manifest\RequirementCollection
  37. * @uses \PharIo\Manifest\RequirementCollectionIterator
  38. * @uses \PharIo\Manifest\RequiresElement
  39. * @uses \PharIo\Manifest\Type
  40. * @uses \PharIo\Manifest\Url
  41. * @uses \PharIo\Version\Version
  42. * @uses \PharIo\Version\VersionConstraint
  43. */
  44. class ManifestSerializerTest extends \PHPUnit_Framework_TestCase {
  45. /**
  46. * @dataProvider dataProvider
  47. *
  48. * @param $expected
  49. *
  50. * @uses \PharIo\Manifest\Application
  51. * @uses \PharIo\Manifest\Library
  52. * @uses \PharIo\Manifest\Extension
  53. * @uses \PharIo\Manifest\ExtensionElement
  54. */
  55. public function testCanSerializeToString($expected) {
  56. $manifest = ManifestLoader::fromString($expected);
  57. $serializer = new ManifestSerializer();
  58. $this->assertXmlStringEqualsXmlString(
  59. $expected,
  60. $serializer->serializeToString($manifest)
  61. );
  62. }
  63. public function dataProvider() {
  64. return [
  65. 'application' => [file_get_contents(__DIR__ . '/_fixture/phpunit-5.6.5.xml')],
  66. 'library' => [file_get_contents(__DIR__ . '/_fixture/library.xml')],
  67. 'extension' => [file_get_contents(__DIR__ . '/_fixture/extension.xml')]
  68. ];
  69. }
  70. /**
  71. * @uses \PharIo\Manifest\Library
  72. * @uses \PharIo\Manifest\ApplicationName
  73. */
  74. public function testCanSerializeToFile() {
  75. $src = __DIR__ . '/_fixture/library.xml';
  76. $dest = '/tmp/' . uniqid('serializer', true);
  77. $manifest = ManifestLoader::fromFile($src);
  78. $serializer = new ManifestSerializer();
  79. $serializer->serializeToFile($manifest, $dest);
  80. $this->assertXmlFileEqualsXmlFile($src, $dest);
  81. unlink($dest);
  82. }
  83. /**
  84. * @uses \PharIo\Manifest\ApplicationName
  85. */
  86. public function testCanHandleUnknownType() {
  87. $type = $this->getMockForAbstractClass(Type::class);
  88. $manifest = new Manifest(
  89. new ApplicationName('testvendor/testname'),
  90. new Version('1.0.0'),
  91. $type,
  92. new CopyrightInformation(
  93. new AuthorCollection(),
  94. new License('bsd-3', new Url('https://some/uri'))
  95. ),
  96. new RequirementCollection(),
  97. new BundledComponentCollection()
  98. );
  99. $serializer = new ManifestSerializer();
  100. $this->assertXmlStringEqualsXmlFile(
  101. __DIR__ . '/_fixture/custom.xml',
  102. $serializer->serializeToString($manifest)
  103. );
  104. }
  105. }