No Description

ManifestDocumentMapperTest.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace PharIo\Manifest;
  3. /**
  4. * @covers \PharIo\Manifest\ManifestDocumentMapper
  5. *
  6. * @uses \PharIo\Manifest\ApplicationName
  7. * @uses \PharIo\Manifest\Author
  8. * @uses \PharIo\Manifest\AuthorCollection
  9. * @uses \PharIo\Manifest\AuthorCollectionIterator
  10. * @uses \PharIo\Manifest\AuthorElement
  11. * @uses \PharIo\Manifest\AuthorElementCollection
  12. * @uses \PharIo\Manifest\BundledComponent
  13. * @uses \PharIo\Manifest\BundledComponentCollection
  14. * @uses \PharIo\Manifest\BundledComponentCollectionIterator
  15. * @uses \PharIo\Manifest\BundlesElement
  16. * @uses \PharIo\Manifest\ComponentElement
  17. * @uses \PharIo\Manifest\ComponentElementCollection
  18. * @uses \PharIo\Manifest\ContainsElement
  19. * @uses \PharIo\Manifest\CopyrightElement
  20. * @uses \PharIo\Manifest\CopyrightInformation
  21. * @uses \PharIo\Manifest\ElementCollection
  22. * @uses \PharIo\Manifest\Email
  23. * @uses \PharIo\Manifest\ExtElement
  24. * @uses \PharIo\Manifest\ExtElementCollection
  25. * @uses \PharIo\Manifest\License
  26. * @uses \PharIo\Manifest\LicenseElement
  27. * @uses \PharIo\Manifest\Manifest
  28. * @uses \PharIo\Manifest\ManifestDocument
  29. * @uses \PharIo\Manifest\ManifestDocumentMapper
  30. * @uses \PharIo\Manifest\ManifestElement
  31. * @uses \PharIo\Manifest\ManifestLoader
  32. * @uses \PharIo\Manifest\PhpElement
  33. * @uses \PharIo\Manifest\PhpExtensionRequirement
  34. * @uses \PharIo\Manifest\PhpVersionRequirement
  35. * @uses \PharIo\Manifest\RequirementCollection
  36. * @uses \PharIo\Manifest\RequirementCollectionIterator
  37. * @uses \PharIo\Manifest\RequiresElement
  38. * @uses \PharIo\Manifest\Type
  39. * @uses \PharIo\Manifest\Url
  40. * @uses \PharIo\Version\Version
  41. * @uses \PharIo\Version\VersionConstraint
  42. */
  43. class ManifestDocumentMapperTest extends \PHPUnit\Framework\TestCase {
  44. /**
  45. * @dataProvider dataProvider
  46. *
  47. * @param $expected
  48. *
  49. * @uses \PharIo\Manifest\Application
  50. * @uses \PharIo\Manifest\ApplicationName
  51. * @uses \PharIo\Manifest\Library
  52. * @uses \PharIo\Manifest\Extension
  53. * @uses \PharIo\Manifest\ExtensionElement
  54. */
  55. public function testCanSerializeToString($expected) {
  56. $manifestDocument = ManifestDocument::fromFile($expected);
  57. $mapper = new ManifestDocumentMapper();
  58. $this->assertInstanceOf(
  59. Manifest::class,
  60. $mapper->map($manifestDocument)
  61. );
  62. }
  63. public function dataProvider() {
  64. return [
  65. 'application' => [__DIR__ . '/_fixture/phpunit-5.6.5.xml'],
  66. 'library' => [__DIR__ . '/_fixture/library.xml'],
  67. 'extension' => [__DIR__ . '/_fixture/extension.xml']
  68. ];
  69. }
  70. public function testThrowsExceptionOnUnsupportedType() {
  71. $manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/custom.xml');
  72. $mapper = new ManifestDocumentMapper();
  73. $this->expectException(ManifestDocumentMapperException::class);
  74. $mapper->map($manifestDocument);
  75. }
  76. public function testInvalidVersionInformationThrowsException() {
  77. $manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/invalidversion.xml');
  78. $mapper = new ManifestDocumentMapper();
  79. $this->expectException(ManifestDocumentMapperException::class);
  80. $mapper->map($manifestDocument);
  81. }
  82. public function testInvalidVersionConstraintThrowsException() {
  83. $manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/invalidversionconstraint.xml');
  84. $mapper = new ManifestDocumentMapper();
  85. $this->expectException(ManifestDocumentMapperException::class);
  86. $mapper->map($manifestDocument);
  87. }
  88. /**
  89. * @uses \PharIo\Manifest\ExtensionElement
  90. */
  91. public function testInvalidCompatibleConstraintThrowsException() {
  92. $manifestDocument = ManifestDocument::fromFile(__DIR__ . '/_fixture/extension-invalidcompatible.xml');
  93. $mapper = new ManifestDocumentMapper();
  94. $this->expectException(ManifestDocumentMapperException::class);
  95. $mapper->map($manifestDocument);
  96. }
  97. }