ソースを参照

added version class, in order to check dependencies

Gediminas Morkevicius 14 年 前
コミット
4a7db03c32

+ 19 - 0
lib/Gedmo/Exception/DependentComponentNotFoundException.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Gedmo\Exception;
+
+use Gedmo\Exception;
+
+/**
+ * DependentComponentNotFoundException
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Exception
+ * @subpackage DependentComponentNotFoundException
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class DependentComponentNotFoundException
+    extends \RuntimeException
+    implements Exception
+{}

+ 19 - 0
lib/Gedmo/Exception/IncompatibleComponentVersionException.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace Gedmo\Exception;
+
+use Gedmo\Exception;
+
+/**
+ * IncompatibleComponentVersionException
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @package Gedmo.Exception
+ * @subpackage IncompatibleComponentVersionException
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+class IncompatibleComponentVersionException
+    extends \RuntimeException
+    implements Exception
+{}

+ 89 - 0
lib/Gedmo/Version.php

@@ -0,0 +1,89 @@
+<?php
+
+namespace Gedmo;
+
+use Gedmo\Exception\DependentComponentNotFoundException;
+use Gedmo\Exception\IncompatibleComponentVersionException;
+
+/**
+ * Version class allows to checking the dependencies required
+ * and the current version of doctrine extensions
+ *
+ * @author Gediminas Morkevicius <gediminas.morkevicius@gmail.com>
+ * @subpackage Version
+ * @package Gedmo
+ * @link http://www.gediminasm.org
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
+ */
+final class Version
+{
+    /**
+     * Current version of extensions
+     */
+    const VERSION = '2.1.0-DEV';
+
+    /**
+     * Checks the dependent ORM library components
+     * for compatibility
+     *
+     * @throws DependentComponentNotFoundException
+     * @throws IncompatibleComponentVersionException
+     */
+    public static function checkORMDependencies()
+    {
+        // doctrine common library
+        if (!class_exists('Doctrine\\Common\\Version')) {
+            throw new DependentComponentNotFoundException("Doctrine\\Common library is either not registered by autoloader or not installed");
+        }
+        if (\Doctrine\Common\Version::compare(self::VERSION) > 0) {
+            throw new IncompatibleComponentVersionException("Doctrine\\Common library is older than expected for these extensions");
+        }
+
+        // doctrine dbal library
+        if (!class_exists('Doctrine\\DBAL\\Version')) {
+            throw new DependentComponentNotFoundException("Doctrine\\DBAL library is either not registered by autoloader or not installed");
+        }
+        if (\Doctrine\DBAL\Version::compare(self::VERSION) > 0) {
+            throw new IncompatibleComponentVersionException("Doctrine\\DBAL library is older than expected for these extensions");
+        }
+
+        // doctrine ORM library
+        if (!class_exists('Doctrine\\ORM\\Version')) {
+            throw new DependentComponentNotFoundException("Doctrine\\ORM library is either not registered by autoloader or not installed");
+        }
+        if (\Doctrine\ORM\Version::compare(self::VERSION) > 0) {
+            throw new IncompatibleComponentVersionException("Doctrine\\ORM library is older than expected for these extensions");
+        }
+    }
+
+    /**
+     * Checks the dependent ODM MongoDB library components
+     * for compatibility
+     *
+     * @throws DependentComponentNotFoundException
+     * @throws IncompatibleComponentVersionException
+     */
+    public static function checkODMMongoDBDependencies()
+    {
+        // doctrine common library
+        if (!class_exists('Doctrine\\Common\\Version')) {
+            throw new DependentComponentNotFoundException("Doctrine\\Common library is either not registered by autoloader or not installed");
+        }
+        if (\Doctrine\Common\Version::compare(self::VERSION) > 0) {
+            throw new IncompatibleComponentVersionException("Doctrine\\Common library is older than expected for these extensions");
+        }
+
+        // doctrine mongodb library
+        if (!class_exists('Doctrine\\MongoDB\\Database')) {
+            throw new DependentComponentNotFoundException("Doctrine\\MongoDB library is either not registered by autoloader or not installed");
+        }
+
+        // doctrine ODM MongoDB library
+        if (!class_exists('Doctrine\\ODM\\MongoDB\\Version')) {
+            throw new DependentComponentNotFoundException("Doctrine\\ODM\\MongoDB library is either not registered by autoloader or not installed");
+        }
+        if (\Doctrine\ODM\MongoDB\Version::compare('1.0.0RC1-DEV') > 0) {
+            throw new IncompatibleComponentVersionException("Doctrine\\ODM\\MongoDB library is older than expected for these extensions");
+        }
+    }
+}

+ 12 - 0
tests/bootstrap.php

@@ -9,6 +9,16 @@
  * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
  */
 
+if (!class_exists('PHPUnit_Framework_TestCase') ||
+    version_compare(PHPUnit_Runner_Version::id(), '3.5') < 0
+) {
+    die('PHPUnit framework is required, at least 3.5 version');
+}
+
+if (!class_exists('PHPUnit_Framework_MockObject_MockBuilder')) {
+    die('PHPUnit MockObject plugin is required, at least 1.0.8 version');
+}
+
 define('TESTS_PATH', __DIR__);
 define('TESTS_TEMP_DIR', __DIR__.'/temp');
 define('VENDOR_PATH', realpath(__DIR__ . '/../vendor'));
@@ -37,3 +47,5 @@ $loader->registerNamespaces(array(
 ));
 $loader->register();
 
+Gedmo\Version::checkODMMongoDBDependencies();
+Gedmo\Version::checkORMDependencies();