diff --git a/manifest.xml b/manifest.xml
index fd731fb..f497780 100644
--- a/manifest.xml
+++ b/manifest.xml
@@ -8,6 +8,7 @@
+
diff --git a/tests/Integration/ManifestTest.php b/tests/Integration/ManifestTest.php
index 46c0830..de9c762 100644
--- a/tests/Integration/ManifestTest.php
+++ b/tests/Integration/ManifestTest.php
@@ -5,24 +5,103 @@
namespace Churn\Tests\Integration;
use Churn\Tests\BaseTestCase;
+use PharIo\Manifest\Manifest;
use PharIo\Manifest\ManifestLoader;
+use PharIo\Manifest\PhpExtensionRequirement;
+use RuntimeException;
class ManifestTest extends BaseTestCase
{
- /** @test */
- public function manifest_is_valid(): void
+ /** @var Manifest */
+ private $manifest;
+
+ /** @return void */
+ public function setUp()
{
+ parent::setUp();
+
$path = __DIR__ . '/../../manifest.xml';
self::assertTrue(is_file($path), 'manifest.xml not found');
- $manifest = ManifestLoader::fromFile($path);
+ $this->manifest = ManifestLoader::fromFile($path);
+ }
- /**
- * @psalm-suppress InvalidCast
- * @phpstan-ignore-next-line
- */
- $name = method_exists($manifest->getName(), 'asString') ? $manifest->getName()->asString() : (string) $manifest->getName();
+ /** @test */
+ public function manifest_is_valid(): void
+ {
+ $name = $this->getStringRepresentation($this->manifest->getName());
self::assertSame('bmitch/churn-php', $name);
- self::assertGreaterThan(0, $manifest->getRequirements()->count());
+ self::assertGreaterThan(0, $this->manifest->getRequirements()->count());
+ }
+
+ /** @test */
+ public function manifest_requires_same_extensions_than_composer(): void
+ {
+ self::assertEqualsCanonicalizing(
+ $this->getComposerExtensionRequirements(),
+ $this->getManifestExtensionRequirements()
+ );
+ }
+
+ /**
+ * @return array
+ */
+ private function getManifestExtensionRequirements(): array
+ {
+ $requirements = [];
+ foreach ($this->manifest->getRequirements() as $requirement) {
+ if (!$requirement instanceof PhpExtensionRequirement) {
+ continue;
+ }
+
+ $requirements[] = $this->getStringRepresentation($requirement);
+ }
+
+ return $requirements;
+ }
+
+ /**
+ * @return array
+ */
+ private function getComposerExtensionRequirements(): array
+ {
+ $path = __DIR__ . '/../../composer.json';
+ self::assertNotFalse($contents = file_get_contents($path));
+ /** @var mixed $json */
+ $json = json_decode($contents, true);
+ self::assertIsArray($json);
+ self::assertArrayHasKey('require', $json);
+ self::assertIsArray($json['require']);
+
+ $requirements = [];
+ foreach (array_keys($json['require']) as $requirement) {
+ if (!is_string($requirement) || strpos($requirement, 'ext-') !== 0) {
+ continue;
+ }
+
+ $requirements[] = substr($requirement, 4);
+ }
+
+ return $requirements;
+ }
+
+ /**
+ * @param object $object
+ */
+ private function getStringRepresentation($object): string
+ {
+ $result = null;
+ if (method_exists($object, 'asString')) {
+ /** @var mixed $result */
+ $result = $object->asString();
+ } elseif (method_exists($object, '__toString')) {
+ /** @var mixed $result */
+ $result = $object->__toString();
+ }
+ if (!is_string($result)) {
+ throw new RuntimeException('String representation not found');
+ }
+
+ return $result;
}
}