Browse Source

Added Platform utility and unit test for it.

Niels Keurentjes 9 years ago
parent
commit
f2a2b18367
2 changed files with 57 additions and 0 deletions
  1. 28 0
      src/Composer/Util/Platform.php
  2. 29 0
      tests/Composer/Test/Util/PlatformTest.php

+ 28 - 0
src/Composer/Util/Platform.php

@@ -0,0 +1,28 @@
+<?php
+/**
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Util;
+
+/**
+ * Platform helper for uniform platform-specific tests.
+ *
+ * @author Niels Keurentjes <niels.keurentjes@omines.com>
+ */
+class Platform
+{
+    /**
+     * @return bool Whether the host machine is running a Windows OS
+     */
+    public static function isWindows()
+    {
+        return defined('PHP_WINDOWS_VERSION_BUILD');
+    }
+}

+ 29 - 0
tests/Composer/Test/Util/PlatformTest.php

@@ -0,0 +1,29 @@
+<?php
+/**
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Composer\Test\Util;
+
+use Composer\Util\Platform;
+
+/**
+ * PlatformTest
+ *
+ * @author Niels Keurentjes <niels.keurentjes@omines.com>
+ */
+class PlatformTest extends \PHPUnit_Framework_TestCase
+{
+    public function testWindows()
+    {
+        // Compare 2 common tests for Windows to the built-in Windows test
+        $this->assertEquals(('\\' === DIRECTORY_SEPARATOR), Platform::isWindows());
+        $this->assertEquals(defined('PHP_WINDOWS_VERSION_MAJOR'), Platform::isWindows());
+    }
+}