Browse Source

Updated to remove vfsStreams (no longer needed by tests)
Updated Perforce to cleanup, modified VcsRepository to call cleanup on Driver class
Updated tests, perforce constructor to make tests cleaner/easier

matt-whittom 11 years ago
parent
commit
dd81449998

+ 1 - 2
composer.json

@@ -30,8 +30,7 @@
         "symfony/process": "~2.1"
     },
     "require-dev": {
-        "phpunit/phpunit": "~3.7.10",
-        "mikey179/vfsStream" : "1.2.*"
+        "phpunit/phpunit": "~3.7.10"
     },
     "suggest": {
         "ext-zip": "Enabling the zip extension allows you to unzip archives, and allows gzip compression of all internet traffic",

+ 48 - 49
composer.lock

@@ -3,7 +3,7 @@
         "This file locks the dependencies of your project to a known state",
         "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
     ],
-    "hash": "6203fdb419c10ffd84f85611fc9eec61",
+    "hash": "370b764a9317165e8ea7a2e1623e031b",
     "packages": [
         {
             "name": "justinrainbow/json-schema",
@@ -15,7 +15,7 @@
             },
             "dist": {
                 "type": "zip",
-                "url": "https://github.com/justinrainbow/json-schema/zipball/v1.1.0",
+                "url": "https://github.com/justinrainbow/json-schema/archive/v1.1.0.zip",
                 "reference": "v1.1.0",
                 "shasum": ""
             },
@@ -28,7 +28,37 @@
                     "JsonSchema": "src/"
                 }
             },
-            "time": "2012-01-02 21:33:17"
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "NewBSD"
+            ],
+            "authors": [
+                {
+                    "name": "Igor Wiedler",
+                    "email": "igor@wiedler.ch",
+                    "homepage": "http://wiedler.ch/igor/"
+                },
+                {
+                    "name": "Bruno Prieto Reis",
+                    "email": "bruno.p.reis@gmail.com"
+                },
+                {
+                    "name": "Justin Rainbow",
+                    "email": "justin.rainbow@gmail.com"
+                },
+                {
+                    "name": "Robert Schönthal",
+                    "email": "seroscho@googlemail.com",
+                    "homepage": "http://digitalkaoz.net"
+                }
+            ],
+            "description": "A library to validate a json schema.",
+            "homepage": "https://github.com/justinrainbow/json-schema",
+            "keywords": [
+                "json",
+                "schema"
+            ],
+            "time": "2012-01-03 00:33:17"
         },
         {
             "name": "seld/jsonlint",
@@ -79,17 +109,17 @@
         },
         {
             "name": "symfony/console",
-            "version": "dev-master",
+            "version": "v2.3.3",
             "target-dir": "Symfony/Component/Console",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Console.git",
-                "reference": "872a494b88fba2f62be85e0bc8441e7946bb6ba6"
+                "reference": "v2.3.3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Console/zipball/872a494b88fba2f62be85e0bc8441e7946bb6ba6",
-                "reference": "872a494b88fba2f62be85e0bc8441e7946bb6ba6",
+                "url": "https://api.github.com/repos/symfony/Console/zipball/v2.3.3",
+                "reference": "v2.3.3",
                 "shasum": ""
             },
             "require": {
@@ -104,7 +134,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "2.4-dev"
+                    "dev-master": "2.3-dev"
                 }
             },
             "autoload": {
@@ -128,7 +158,7 @@
             ],
             "description": "Symfony Console Component",
             "homepage": "http://symfony.com",
-            "time": "2013-08-09 06:00:31"
+            "time": "2013-07-21 12:12:18"
         },
         {
             "name": "symfony/finder",
@@ -179,17 +209,17 @@
         },
         {
             "name": "symfony/process",
-            "version": "dev-master",
+            "version": "v2.3.3",
             "target-dir": "Symfony/Component/Process",
             "source": {
                 "type": "git",
                 "url": "https://github.com/symfony/Process.git",
-                "reference": "723fe405fcc878ae75469babcb9507d292797ece"
+                "reference": "v2.3.3"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/symfony/Process/zipball/723fe405fcc878ae75469babcb9507d292797ece",
-                "reference": "723fe405fcc878ae75469babcb9507d292797ece",
+                "url": "https://api.github.com/repos/symfony/Process/zipball/v2.3.3",
+                "reference": "v2.3.3",
                 "shasum": ""
             },
             "require": {
@@ -198,7 +228,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-master": "2.4-dev"
+                    "dev-master": "2.3-dev"
                 }
             },
             "autoload": {
@@ -222,40 +252,10 @@
             ],
             "description": "Symfony Process Component",
             "homepage": "http://symfony.com",
-            "time": "2013-08-09 07:03:52"
+            "time": "2013-08-02 21:51:01"
         }
     ],
     "packages-dev": [
-        {
-            "name": "mikey179/vfsStream",
-            "version": "v1.2.0",
-            "source": {
-                "type": "git",
-                "url": "https://github.com/mikey179/vfsStream.git",
-                "reference": "v1.2.0"
-            },
-            "dist": {
-                "type": "zip",
-                "url": "https://api.github.com/repos/mikey179/vfsStream/zipball/v1.2.0",
-                "reference": "v1.2.0",
-                "shasum": ""
-            },
-            "require": {
-                "php": ">=5.3.0"
-            },
-            "type": "library",
-            "autoload": {
-                "psr-0": {
-                    "org\\bovigo\\vfs\\": "src/main/php"
-                }
-            },
-            "notification-url": "https://packagist.org/downloads/",
-            "license": [
-                "BSD"
-            ],
-            "homepage": "http://vfs.bovigo.org/",
-            "time": "2013-04-01 10:41:02"
-        },
         {
             "name": "phpunit/php-code-coverage",
             "version": "1.2.12",
@@ -675,10 +675,9 @@
 
     ],
     "minimum-stability": "stable",
-    "stability-flags": {
-        "symfony/console": 20,
-        "symfony/process": 20
-    },
+    "stability-flags": [
+
+    ],
     "platform": {
         "php": ">=5.3.2"
     },

+ 8 - 4
src/Composer/Downloader/PerforceDownloader.php

@@ -6,10 +6,14 @@
  * (c) Nils Adermann <naderman@naderman.de>
  *     Jordi Boggiano <j.boggiano@seld.be>
  *
+ *  Contributor: Matt Whittom <Matt.Whittom@veteransunited.com>
+ *  Date: 7/17/13
+ *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
 
+
 namespace Composer\Downloader;
 
 use Composer\Package\PackageInterface;
@@ -17,7 +21,7 @@ use Composer\Repository\VcsRepository;
 use Composer\Util\Perforce;
 
 /**
- * @author Jordi Boggiano <j.boggiano@seld.be>
+ * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  */
 class PerforceDownloader extends VcsDownloader
 {
@@ -39,6 +43,7 @@ class PerforceDownloader extends VcsDownloader
         $this->perforce->writeP4ClientSpec();
         $this->perforce->connectClient();
         $this->perforce->syncCodeBase($label);
+        $this->perforce->cleanupClientSpec();
     }
 
     private function initPerforce($package, $path){
@@ -47,7 +52,7 @@ class PerforceDownloader extends VcsDownloader
         }
         $repository = $package->getRepository();
         $repoConfig = $this->getRepoConfig($repository);
-        $this->perforce = new Perforce($repoConfig, $package->getSourceUrl(), $path);
+        $this->perforce = Perforce::createPerforce($repoConfig, $package->getSourceUrl(), $path);
     }
 
     public function injectPerforce($perforce){
@@ -64,14 +69,13 @@ class PerforceDownloader extends VcsDownloader
      */
     public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
     {
-        print("PerforceDownloader:doUpdate\n");
         $this->doDownload($target, $path);
     }
 
     /**
      * {@inheritDoc}
      */
-    public function getLocalChanges($path)
+    public function getLocalChanges(PackageInterface $package, $path)
     {
         print ("Perforce driver does not check for local changes before overriding\n");
         return;

+ 34 - 6
src/Composer/Repository/Vcs/PerforceDriver.php

@@ -6,13 +6,14 @@
  * (c) Nils Adermann <naderman@naderman.de>
  *     Jordi Boggiano <j.boggiano@seld.be>
  *
- *  Contributor: matt-whittom
+ *  Contributor: Matt Whittom <Matt.Whittom@veteransunited.com>
  *  Date: 7/17/13
  *
  * For the full copyright and license information, please view the LICENSE
  * file that was distributed with this source code.
  */
 
+
 namespace Composer\Repository\Vcs;
 
 use Composer\IO\IOInterface;
@@ -21,12 +22,14 @@ use Composer\Util\Filesystem;
 use Composer\Util\Perforce;
 
 /**
- * @author matt-whittom <>
+ * @author Matt Whittom <Matt.Whittom@veteransunited.com>
  */
 class PerforceDriver extends VcsDriver {
     protected $depot;
     protected $branch;
     protected $perforce;
+    protected $composer_info;
+    protected $composer_info_identifier;
 
     /**
      * {@inheritDoc}
@@ -54,7 +57,7 @@ class PerforceDriver extends VcsDriver {
         }
 
         $repoDir = $this->config->get('cache-vcs-dir') . "/$this->depot";
-        $this->perforce = new Perforce($this->repoConfig, $this->getUrl(), $repoDir, $this->process);
+        $this->perforce = Perforce::createPerforce($this->repoConfig, $this->getUrl(), $repoDir, $this->process);
     }
 
     public function injectPerforce(Perforce $perforce) {
@@ -66,6 +69,12 @@ class PerforceDriver extends VcsDriver {
      * {@inheritDoc}
      */
     public function getComposerInformation($identifier) {
+        if (isset($this->composer_info_identifier)){
+            if (strcmp($identifier, $this->composer_info_identifier) === 0 )
+            {
+                return $this->composer_info;
+            }
+        }
         $composer_info = $this->perforce->getComposerInformation($identifier);
 
         return $composer_info;
@@ -127,9 +136,12 @@ class PerforceDriver extends VcsDriver {
      * {@inheritDoc}
      */
     public function hasComposerFile($identifier) {
-        $composer_info = $this->perforce->getComposerInformation("//$this->depot/$identifier");
-        $result = strlen(trim($composer_info)) > 0;
-
+        $this->composer_info = $this->perforce->getComposerInformation("//$this->depot/$identifier");
+        $this->composer_info_identifier = $identifier;
+        $result = false;
+        if (isset($this->composer_info)){
+            $result = count($this->composer_info) > 0;
+        }
         return $result;
     }
 
@@ -146,4 +158,20 @@ class PerforceDriver extends VcsDriver {
     public static function supports(IOInterface $io, $url, $deep = FALSE) {
         return Perforce::checkServerExists($url, new ProcessExecutor);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function cleanup(){
+        $this->perforce->cleanupClientSpec();
+        $this->perforce = null;
+    }
+
+    public function getDepot(){
+        return $this->depot;
+    }
+
+    public function getBranch(){
+        return $this->branch;
+    }
 }

+ 8 - 0
src/Composer/Repository/Vcs/VcsDriver.php

@@ -105,4 +105,12 @@ abstract class VcsDriver implements VcsDriverInterface
     {
         return (bool) preg_match('{^(file://|/|[a-z]:[\\\\/])}i', $url);
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public function cleanup()
+    {
+        return;
+    }
 }

+ 6 - 0
src/Composer/Repository/Vcs/VcsDriverInterface.php

@@ -81,6 +81,12 @@ interface VcsDriverInterface
      */
     public function hasComposerFile($identifier);
 
+    /**
+     * Performs any cleanup necessary as the driver is not longer needed
+     *
+     */
+    public function cleanup();
+
     /**
      * Checks if this driver can handle a given url
      *

+ 1 - 0
src/Composer/Repository/VcsRepository.php

@@ -253,6 +253,7 @@ class VcsRepository extends ArrayRepository
                 continue;
             }
         }
+        $driver->cleanup();
 
         if (!$verbose) {
             $this->io->overwrite('', false);

+ 105 - 78
src/Composer/Util/Perforce.php

@@ -1,60 +1,91 @@
 <?php
-/**
- * Created by JetBrains PhpStorm.
- * User: matt.whittom
- * Date: 7/23/13
- * Time: 3:22 PM
- * To change this template use File | Settings | File Templates.
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ *  Contributor: Matt Whittom <Matt.Whittom@veteransunited.com>
+ *  Date: 7/17/13
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
  */
 
+
 namespace Composer\Util;
 
 use Composer\IO\IOInterface;
 
-
+/**
+ * @author Matt Whittom <Matt.Whittom@veteransunited.com>
+ */
 class Perforce {
 
     protected $path;
-    protected $p4client;
-    protected $p4user;
-    protected $p4password;
-    protected $p4port;
-    protected $p4stream;
-    protected $p4clientSpec;
-    protected $p4depotType;
-    protected $p4branch;
+    protected $p4Depot;
+    protected $p4Client;
+    protected $p4User;
+    protected $p4Password;
+    protected $p4Port;
+    protected $p4Stream;
+    protected $p4ClientSpec;
+    protected $p4DepotType;
+    protected $p4Branch;
     protected $process;
+    protected $unique_perforce_client_name;
+    protected $windowsFlag;
+
+
+    public static function createPerforce($repoConfig, $port, $path, ProcessExecutor $process = NULL) {
+        if (!isset($process)){
+            $process = new ProcessExecutor;
+        }
+        $isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
+        if (isset($repoConfig['unique_perforce_client_name'])){
+            $unique_perforce_client_name = $repoConfig['unique_perforce_client_name'];
+        } else {
+            $unique_perforce_client_name = gethostname() . "_" . time();
+            $repoConfig['unique_perforce_client_name'] = $unique_perforce_client_name;
+        }
+
+        $perforce = new Perforce($repoConfig, $port, $path, $process, $isWindows, $unique_perforce_client_name);
+        return $perforce;
+    }
 
-    public function __construct($repoConfig, $port, $path, ProcessExecutor $process = NULL) {
-        $this->p4port = $port;
+    public function __construct($repoConfig, $port, $path, ProcessExecutor $process, $isWindows, $unique_perforce_client_name) {
+        $this->windowsFlag = $isWindows;
+        $this->unique_perforce_client_name = $unique_perforce_client_name;
+        $this->p4Port = $port;
         $this->path = $path;
-        $this->process = $process ? : new ProcessExecutor;
         $fs = new Filesystem();
         $fs->ensureDirectoryExists($path);
+        $this->process = $process;
 
         if (isset($repoConfig['depot'])) {
-            $this->p4depot = $repoConfig['depot'];
+            $this->p4Depot = $repoConfig['depot'];
         }
         if (isset($repoConfig['branch'])) {
-            $this->p4branch = $repoConfig['branch'];
+            $this->p4Branch = $repoConfig['branch'];
         }
         if (isset($repoConfig['p4user'])) {
-            $this->p4user = $repoConfig['p4user'];
+            $this->p4User = $repoConfig['p4user'];
         }
         else {
-            $this->p4user = $this->getP4variable("P4USER");
+            $this->p4User = $this->getP4variable("P4USER");
         }
         if (isset($repoConfig['p4password'])) {
-            $this->p4password = $repoConfig['p4password'];
+            $this->p4Password = $repoConfig['p4password'];
         }
     }
 
-    protected function getRandomValue() {
-        return mt_rand(1000, 9999);
-    }
-
-    protected function isWindows(){
-        return defined('PHP_WINDOWS_VERSION_BUILD');
+    public function cleanupClientSpec(){
+        $client = $this->getClient();
+        $command = "p4 client -d $client";
+        $this->executeCommand($command);
+        $clientSpec = $this->getP4ClientSpec();
+        $fileSystem = new FileSystem($this->process);
+        $fileSystem->remove($clientSpec);
     }
 
     protected function executeCommand($command) {
@@ -64,14 +95,13 @@ class Perforce {
         return $result;
     }
 
-    protected function getClient() {
-        if (!isset($this->p4client)) {
-            $random_value = $this->getRandomValue();
+    public function getClient() {
+        if (!isset($this->p4Client)) {
             $clean_stream_name = str_replace("@", "", str_replace("/", "_", str_replace("//", "", $this->getStream())));
-            $this->p4client = "composer_perforce_" . $random_value . "_" . $clean_stream_name;
+            $this->p4Client = "composer_perforce_" . $this->unique_perforce_client_name . "_" . $clean_stream_name;
         }
 
-        return $this->p4client;
+        return $this->p4Client;
     }
 
     protected function getPath() {
@@ -79,28 +109,31 @@ class Perforce {
     }
 
     protected function getPort() {
-        return $this->p4port;
+        return $this->p4Port;
+    }
+
+    public function setStream($stream) {
+        $this->p4Stream = $stream;
+        $this->p4DepotType = "stream";
     }
 
-    protected function isStream() {
-        return (strcmp($this->p4depotType, "stream") === 0);
+    public function isStream() {
+        return (strcmp($this->p4DepotType, "stream") === 0);
     }
 
-    protected function getStream() {
-        if (!isset($this->p4stream)) {
+    public function getStream() {
+        if (!isset($this->p4Stream)) {
             if ($this->isStream()) {
-                $this->p4stream = "//$this->p4depot/$this->p4branch";
+                $this->p4Stream = "//$this->p4Depot/$this->p4Branch";
             }
             else {
-                $this->p4stream = "//$this->p4depot";
+                $this->p4Stream = "//$this->p4Depot";
             }
         }
-
-        return $this->p4stream;
+        return $this->p4Stream;
     }
 
-    protected function getStreamWithoutLabel() {
-        $stream = $this->getStream();
+    public function getStreamWithoutLabel($stream) {
         $index = strpos($stream, "@");
         if ($index === FALSE) {
             return $stream;
@@ -109,37 +142,37 @@ class Perforce {
         return substr($stream, 0, $index);
     }
 
-    protected function getP4ClientSpec() {
+    public function getP4ClientSpec() {
         $p4clientSpec = $this->path . "/" . $this->getClient() . ".p4.spec";
 
         return $p4clientSpec;
     }
 
     public function getUser() {
-        return $this->p4user;
+        return $this->p4User;
     }
 
     public function queryP4User(IOInterface $io) {
         $this->getUser();
-        if (strlen($this->p4user) > 0) {
+        if (strlen($this->p4User) > 0) {
             return;
         }
-        $this->p4user = $this->getP4variable("P4USER");
-        if (strlen($this->p4user) > 0) {
+        $this->p4User = $this->getP4variable("P4USER");
+        if (strlen($this->p4User) > 0) {
             return;
         }
-        $this->p4user = $io->ask("Enter P4 User:");
-        if ($this->isWindows()) {
-            $command = "p4 set P4USER=$this->p4user";
+        $this->p4User = $io->ask("Enter P4 User:");
+        if ($this->windowsFlag) {
+            $command = "p4 set P4USER=$this->p4User";
         }
         else {
-            $command = "export P4USER=$this->p4user";
+            $command = "export P4USER=$this->p4User";
         }
         $result = $this->executeCommand($command);
     }
 
     protected function getP4variable($name) {
-        if ($this->isWindows()) {
+        if ($this->windowsFlag) {
             $command = "p4 set";
             $result = $this->executeCommand($command);
             $resArray = explode("\n", $result);
@@ -167,20 +200,20 @@ class Perforce {
         }
     }
 
-    protected function queryP4Password(IOInterface $io) {
-        if (isset($this->p4password)) {
-            return $this->p4password;
+    public function queryP4Password(IOInterface $io) {
+        if (isset($this->p4Password)) {
+            return $this->p4Password;
         }
         $password = $this->getP4variable("P4PASSWD");
         if (strlen($password) <= 0) {
             $password = $io->askAndHideAnswer("Enter password for Perforce user " . $this->getUser() . ": ");
         }
-        $this->p4password = $password;
+        $this->p4Password = $password;
 
         return $password;
     }
 
-    protected function generateP4Command($command, $useClient = TRUE) {
+    public function generateP4Command($command, $useClient = TRUE) {
         $p4Command = "p4 ";
         $p4Command = $p4Command . "-u " . $this->getUser() . " ";
         if ($useClient) {
@@ -192,22 +225,16 @@ class Perforce {
         return $p4Command;
     }
 
-    protected function isLoggedIn() {
+    public function isLoggedIn() {
         $command = $this->generateP4Command("login -s", FALSE);
         $result = trim($this->executeCommand($command));
         $index = strpos($result, $this->getUser());
         if ($index === FALSE) {
             return FALSE;
         }
-
         return TRUE;
     }
 
-    public function setStream($stream) {
-        $this->p4stream = $stream;
-        $this->p4depotType = "stream";
-    }
-
     public function connectClient() {
         $p4CreateClientCommand = $this->generateP4Command("client -i < " . $this->getP4ClientSpec());
         $this->executeCommand($p4CreateClientCommand);
@@ -230,7 +257,7 @@ class Perforce {
         chdir($prevDir);
     }
 
-    protected function writeClientSpecToFile($spec) {
+    public function writeClientSpecToFile($spec) {
         fwrite($spec, "Client: " . $this->getClient() . "\n\n");
         fwrite($spec, "Update: " . date("Y/m/d H:i:s") . "\n\n");
         fwrite($spec, "Access: " . date("Y/m/d H:i:s") . "\n");
@@ -243,7 +270,7 @@ class Perforce {
         fwrite($spec, "LineEnd:  local\n\n");
         if ($this->isStream()) {
             fwrite($spec, "Stream:\n");
-            fwrite($spec, "  " . $this->getStreamWithoutLabel() . "\n");
+            fwrite($spec, "  " . $this->getStreamWithoutLabel($this->p4Stream) . "\n");
         }
         else {
             fwrite(
@@ -255,7 +282,8 @@ class Perforce {
     }
 
     public function writeP4ClientSpec() {
-        $spec = fopen($this->getP4ClientSpec(), 'w');
+        $clientSpec = $this->getP4ClientSpec();
+        $spec = fopen($clientSpec, 'w');
         try {
             $this->writeClientSpecToFile($spec);
         } catch (Exception $e) {
@@ -308,7 +336,7 @@ class Perforce {
         $this->queryP4User($io);
         if (!$this->isLoggedIn()) {
             $password = $this->queryP4Password($io);
-            if ($this->isWindows()) {
+            if ($this->windowsFlag) {
                 $this->windowsLogin($password);
             }
             else {
@@ -382,12 +410,11 @@ class Perforce {
     public function getBranches() {
         $possible_branches = array();
         if (!$this->isStream()) {
-            $possible_branches[$this->p4branch] = $this->getStream();
+            $possible_branches[$this->p4Branch] = $this->getStream();
         }
         else {
-            $command = $this->generateP4Command("streams //$this->p4depot/...");
-            $result = "";
-            $this->process->execute($command, $result);
+            $command = $this->generateP4Command("streams //$this->p4Depot/...");
+            $result = $this->executeCommand($command);
             $resArray = explode("\n", $result);
             foreach ($resArray as $line) {
                 $resBits = explode(" ", $line);
@@ -398,7 +425,7 @@ class Perforce {
             }
         }
         $branches = array();
-        $branches['master'] = $possible_branches[$this->p4branch];
+        $branches['master'] = $possible_branches[$this->p4Branch];
 
         return $branches;
     }
@@ -427,8 +454,8 @@ class Perforce {
             $index = strpos($line, "Depot");
             if (!($index === FALSE)) {
                 $fields = explode(" ", $line);
-                if (strcmp($this->p4depot, $fields[1]) === 0) {
-                    $this->p4depotType = $fields[3];
+                if (strcmp($this->p4Depot, $fields[1]) === 0) {
+                    $this->p4DepotType = $fields[3];
 
                     return $this->isStream();
                 }

+ 2 - 1
tests/Composer/Test/Downloader/PerforceDownloaderTest.php

@@ -60,7 +60,8 @@ class PerforceDownloaderTest extends \PHPUnit_Framework_TestCase {
         $repoConfig = array("depot"=>"TEST_DEPOT", "branch"=>"TEST_BRANCH", "p4user"=>"TEST_USER");
         $port = "TEST_PORT";
         $path = "TEST_PATH";
-        $perforce = $this->getMock('Composer\Util\Perforce', array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'), array($repoConfig, $port, $path));
+        $process = $this->getmock('Composer\Util\ProcessExecutor');
+        $perforce = $this->getMock('Composer\Util\Perforce', array('setStream', 'queryP4User', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase'), array($repoConfig, $port, $path, $process, true, "TEST"));
         $ref = "SOURCE_REF";
         $label = "LABEL";
         $perforce->expects($this->at(0))

+ 7 - 8
tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php

@@ -48,9 +48,6 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase {
         $fs->removeDirectory($this->testPath);
     }
 
-    //Test:
-    //hasComposerFile
-
     public function testInitializeCapturesVariablesFromRepoConfig() {
         $this->setUp();
         $repo_config = array(
@@ -58,8 +55,9 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase {
             'depot' => 'TEST_DEPOT_CONFIG',
             'branch' => 'TEST_BRANCH_CONFIG'
         );
-        $driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
-        $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath);
+        $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
+        $process = $this->getMock('Composer\Util\ProcessExecutor');
+        $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath, $process, true, "TEST");
         $perforce = $this->getMock('Composer\Util\Perforce', null, $arguments);
         $driver->injectPerforce($perforce);
         $driver->initialize();
@@ -75,7 +73,7 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase {
             'depot' => 'TEST_DEPOT_CONFIG',
             'branch' => 'TEST_BRANCH_CONFIG'
         );
-        $driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
+        $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
         $perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
         $perforce->expects($this->at(0))
             ->method('p4Login')
@@ -99,8 +97,9 @@ class PerforceDriverTest extends \PHPUnit_Framework_TestCase {
             'depot' => 'TEST_DEPOT_CONFIG',
             'branch' => 'TEST_BRANCH_CONFIG'
         );
-        $driver = new TestingPerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
-        $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath);
+        $driver = new PerforceDriver($repo_config, $this->io, $this->config, $this->process, $this->remoteFileSystem);
+        $process = $this->getMock('Composer\Util\ProcessExecutor');
+        $arguments = array(array('depot'=>'TEST_DEPOT', 'branch'=>'TEST_BRANCH'), 'port'=>'TEST_PORT', 'path'=>$this->testPath, $process, true, "TEST");
         $perforce = $this->getMock('Composer\Util\Perforce', array('getComposerInformation'), $arguments);
         $perforce->expects($this->at(0))
             ->method('getComposerInformation')

+ 0 - 26
tests/Composer/Test/Repository/Vcs/TestingPerforceDriver.php

@@ -1,26 +0,0 @@
-<?php
-/**
- * Created by JetBrains PhpStorm.
- * User: matt.whittom
- * Date: 8/9/13
- * Time: 10:42 AM
- * To change this template use File | Settings | File Templates.
- */
-
-namespace Composer\Test\Repository\Vcs;
-
-use Composer\Repository\Vcs\PerforceDriver;
-
-class TestingPerforceDriver extends PerforceDriver {
-
-    /*
-     * Test Helper functions
-    */
-    public function getDepot(){
-        return $this->depot;
-    }
-    public function getBranch(){
-        return $this->branch;
-    }
-
-}

+ 113 - 119
tests/Composer/Test/Util/PerforceTest.php

@@ -1,21 +1,26 @@
 <?php
-/**
- * Created by JetBrains PhpStorm.
- * User: matt.whittom
- * Date: 7/31/13
- * Time: 2:13 PM
- * To change this template use File | Settings | File Templates.
+/*
+ * This file is part of Composer.
+ *
+ * (c) Nils Adermann <naderman@naderman.de>
+ *     Jordi Boggiano <j.boggiano@seld.be>
+ *
+ *  Contributor: Matt Whittom <Matt.Whittom@veteransunited.com>
+ *  Date: 7/17/13
+ *
+ * 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\Test\Util\TestingPerforce;
+use Composer\Util\Perforce;
 use Composer\Util\ProcessExecutor;
-use org\bovigo\vfs\vfsStreamWrapper;
-use org\bovigo\vfs\vfsStreamDirectory;
-use org\bovigo\vfs\vfsStream;
-
 
+/**
+ * @author Matt Whittom <Matt.Whittom@veteransunited.com>
+ */
 class PerforceTest extends \PHPUnit_Framework_TestCase {
 
     protected $perforce;
@@ -24,54 +29,59 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     public function setUp() {
         $this->processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
         $repoConfig = array("depot"=>"depot", "branch"=>"branch", "p4user"=>"user");
-        $this->perforce = new TestingPerforce($repoConfig, "port", "path", $this->processExecutor);
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
     }
 
     public function testGetClientWithoutStream() {
-        $client = $this->perforce->testGetClient();
+        $client = $this->perforce->getClient();
+        $hostname = gethostname();
+        $timestamp = time();
+
         $expected = "composer_perforce_TEST_depot";
         $this->assertEquals($expected, $client);
     }
 
     public function testGetClientFromStream() {
-        $this->perforce->setDepotType("stream");
-        $client = $this->perforce->testGetClient();
+        $this->setPerforceToStream();
+
+        $client = $this->perforce->getClient();
 
         $expected = "composer_perforce_TEST_depot_branch";
         $this->assertEquals($expected, $client);
     }
 
     public function testGetStreamWithoutStream() {
-        $stream = $this->perforce->testGetStream();
+        $stream = $this->perforce->getStream();
         $this->assertEquals("//depot", $stream);
     }
 
     public function testGetStreamWithStream() {
-        $this->perforce->setDepotType("stream");
-        $stream = $this->perforce->testGetStream();
+        $this->setPerforceToStream();
+
+        $stream = $this->perforce->getStream();
         $this->assertEquals("//depot/branch", $stream);
     }
 
-    public function testGetStreamWithoutLabel() {
-        $stream = $this->perforce->testGetStreamWithoutLabel();
-        $this->assertEquals("//depot", $stream);
-        $this->perforce->setDepotType("stream");
-        $stream = $this->perforce->testGetStreamWithoutLabel();
+
+    public function testGetStreamWithoutLabelWithStreamWithoutLabel(){
+        $stream = $this->perforce->getStreamWithoutLabel("//depot/branch");
         $this->assertEquals("//depot/branch", $stream);
-        $this->perforce->setStream("//depot/branching@label");
-        $stream = $this->perforce->testGetStreamWithoutLabel();
+    }
+
+    public function testGetStreamWithoutLabelWithStreamWithLabel(){
+        $stream = $this->perforce->getStreamWithoutLabel("//depot/branching@label");
         $this->assertEquals("//depot/branching", $stream);
     }
 
     public function testGetClientSpec() {
-        $clientSpec = $this->perforce->testGetClientSpec();
+        $clientSpec = $this->perforce->getP4ClientSpec();
         $expected = "path/composer_perforce_TEST_depot.p4.spec";
         $this->assertEquals($expected, $clientSpec);
     }
 
     public function testGenerateP4Command() {
         $command = "do something";
-        $p4Command = $this->perforce->testGenerateP4Command($command);
+        $p4Command = $this->perforce->generateP4Command($command);
         $expected = "p4 -u user -c composer_perforce_TEST_depot -p port do something";
         $this->assertEquals($expected, $p4Command);
     }
@@ -79,13 +89,16 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     public function testQueryP4UserWithUserAlreadySet(){
         $io = $this->getMock('Composer\IO\IOInterface');
 
-        $this->perforce->setP4User("TEST_USER");
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch", "p4user"=>"TEST_USER");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
+
         $this->perforce->queryP4user($io);
         $this->assertEquals("TEST_USER", $this->perforce->getUser());
     }
 
     public function testQueryP4UserWithUserSetInP4VariablesWithWindowsOS(){
-        $this->perforce->windows_flag = true;
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
 
         $io = $this->getMock('Composer\IO\IOInterface');
         $expectedCommand = "p4 set";
@@ -94,13 +107,13 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
             ->with($this->equalTo($expectedCommand))
             ->will($this->returnCallback(function($command, &$output) {$output =  "P4USER=TEST_P4VARIABLE_USER\n"; return true;}));
 
-        $this->perforce->setP4User(null);
         $this->perforce->queryP4user($io);
         $this->assertEquals("TEST_P4VARIABLE_USER", $this->perforce->getUser());
     }
 
     public function testQueryP4UserWithUserSetInP4VariablesNotWindowsOS(){
-        $this->perforce->windows_flag = false;
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
 
         $io = $this->getMock('Composer\IO\IOInterface');
         $expectedCommand = 'echo $P4USER';
@@ -109,12 +122,13 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  "TEST_P4VARIABLE_USER\n"; return true;}));
 
-        $this->perforce->setP4User(null);
         $this->perforce->queryP4user($io);
         $this->assertEquals("TEST_P4VARIABLE_USER", $this->perforce->getUser());
     }
 
     public function testQueryP4UserQueriesForUser(){
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
         $io = $this->getMock('Composer\IO\IOInterface');
         $expectedQuestion = "Enter P4 User:";
         $io->expects($this->at(0))
@@ -122,13 +136,13 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
             ->with($this->equalTo($expectedQuestion))
             ->will($this->returnValue("TEST_QUERY_USER"));
 
-        $this->perforce->setP4User(null);
         $this->perforce->queryP4user($io);
         $this->assertEquals("TEST_QUERY_USER", $this->perforce->getUser());
     }
 
     public function testQueryP4UserStoresResponseToQueryForUserWithWindows(){
-        $this->perforce->windows_flag = true;
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, true, "TEST");
 
         $io = $this->getMock('Composer\IO\IOInterface');
         $expectedQuestion = "Enter P4 User:";
@@ -142,12 +156,12 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
             ->with($this->equalTo($expectedCommand))
             ->will($this->returnValue(0));
 
-        $this->perforce->setP4User(null);
         $this->perforce->queryP4user($io);
     }
 
     public function testQueryP4UserStoresResponseToQueryForUserWithoutWindows(){
-        $this->perforce->windows_flag = false;
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
 
         $io = $this->getMock('Composer\IO\IOInterface');
         $expectedQuestion = "Enter P4 User:";
@@ -161,35 +175,34 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnValue(0));
 
-        $this->perforce->setP4User(null);
         $this->perforce->queryP4user($io);
     }
 
     public function testQueryP4PasswordWithPasswordAlreadySet(){
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch", "p4user"=>"user", "p4password"=>"TEST_PASSWORD");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
         $io = $this->getMock('Composer\IO\IOInterface');
 
-        $this->perforce->setP4Password("TEST_PASSWORD");
-        $password = $this->perforce->testQueryP4Password($io);
+        $password = $this->perforce->queryP4Password($io);
         $this->assertEquals("TEST_PASSWORD", $password);
     }
 
     public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS(){
-        $this->perforce->windows_flag = true;
-
         $io = $this->getMock('Composer\IO\IOInterface');
+
         $expectedCommand = "p4 set";
         $this->processExecutor->expects($this->at(0))
             ->method('execute')
             ->with($this->equalTo($expectedCommand))
             ->will($this->returnCallback(function($command, &$output) {$output =  "P4PASSWD=TEST_P4VARIABLE_PASSWORD\n"; return true;}));
 
-        $this->perforce->setP4Password(null);
-        $password = $this->perforce->testQueryP4Password($io);
+        $password = $this->perforce->queryP4Password($io);
         $this->assertEquals("TEST_P4VARIABLE_PASSWORD", $password);
     }
 
     public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS(){
-        $this->perforce->windows_flag = false;
+        $repoConfig = array("depot"=>"depot", "branch"=>"branch", "p4user"=>"user");
+        $this->perforce = new Perforce($repoConfig, "port", "path", $this->processExecutor, false, "TEST");
 
         $io = $this->getMock('Composer\IO\IOInterface');
         $expectedCommand = 'echo $P4PASSWD';
@@ -198,8 +211,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  "TEST_P4VARIABLE_PASSWORD\n"; return true;}));
 
-        $this->perforce->setP4Password(null);
-        $password = $this->perforce->testQueryP4Password($io);
+        $password = $this->perforce->queryP4Password($io);
         $this->assertEquals("TEST_P4VARIABLE_PASSWORD", $password);
     }
 
@@ -211,62 +223,60 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
             ->with($this->equalTo($expectedQuestion))
             ->will($this->returnValue("TEST_QUERY_PASSWORD"));
 
-        $this->perforce->setP4Password(null);
-        $password = $this->perforce->testQueryP4Password($io);
+        $password = $this->perforce->queryP4Password($io);
         $this->assertEquals("TEST_QUERY_PASSWORD", $password);
     }
 
     public function testWriteP4ClientSpecWithoutStream() {
-        vfsStreamWrapper::register();
-        VfsStreamWrapper::setRoot(new vfsStreamDirectory("path"));
-        $clientSpec = $this->perforce->testGetClientSpec();
-        $this->perforce->writeP4ClientSpec();
-        $spec = fopen(vfsStream::url($clientSpec), 'r');
+        $stream = fopen("php://memory", 'w+');
+        $this->perforce->writeClientSpecToFile($stream);
+
+        rewind($stream);
         $expectedArray = $this->getExpectedClientSpec(FALSE);
         try {
             foreach ($expectedArray as $expected) {
-                $this->assertStringStartsWith($expected, fgets($spec));
+                $this->assertStringStartsWith($expected, fgets($stream));
             }
-            $this->assertFalse(fgets($spec));
+            $this->assertFalse(fgets($stream));
         } catch (Exception $e) {
-            fclose($spec);
+            fclose($stream);
             throw $e;
         }
-        fclose($spec);
+        fclose($stream);
     }
 
     public function testWriteP4ClientSpecWithStream() {
-        vfsStreamWrapper::register();
-        VfsStreamWrapper::setRoot(new vfsStreamDirectory("path"));
-        $this->perforce->setStream("//depot/branching@label");
-        $clientSpec = $this->perforce->testGetClientSpec();
-        $this->perforce->writeP4ClientSpec();
-        $spec = fopen(vfsStream::url($clientSpec), 'r');
+        $this->setPerforceToStream();
+        $stream = fopen("php://memory", 'w+');
+
+        $this->perforce->writeClientSpecToFile($stream);
+        rewind($stream);
+
         $expectedArray = $this->getExpectedClientSpec(TRUE);
         try {
             foreach ($expectedArray as $expected) {
-                $this->assertStringStartsWith($expected, fgets($spec));
+                $this->assertStringStartsWith($expected, fgets($stream));
             }
-            $this->assertFalse(fgets($spec));
+            $this->assertFalse(fgets($stream));
         } catch (Exception $e) {
-            fclose($spec);
+            fclose($stream);
             throw $e;
         }
-        fclose($spec);
+        fclose($stream);
     }
 
     public function testIsLoggedIn() {
-        $expectedCommand = $this->winCompat("p4 -u user -p port login -s");
+        $expectedCommand = "p4 -u user -p port login -s";
         $this->processExecutor->expects($this->at(0))
             ->method('execute')
             ->with($this->equalTo($expectedCommand), $this->equalTo(null))
             ->will($this->returnValue(0));
 
-        $this->perforce->testIsLoggedIn();
+        $this->perforce->isLoggedIn();
     }
 
     public function testConnectClient() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec");
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand), $this->equalTo(null))
@@ -276,33 +286,25 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testGetBranchesWithStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot_branchlabel -p port streams //depot/...");
+        $this->setPerforceToStream();
+
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port streams //depot/...";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  "Stream //depot/branch mainline none 'branch'\n"; return true;}));
 
-        $this->perforce->setStream("//depot/branch@label");
         $branches = $this->perforce->getBranches();
         $this->assertEquals("//depot/branch", $branches['master']);
     }
 
     public function testGetBranchesWithoutStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -p port depots");
-        $this->processExecutor->expects($this->at(0))
-        ->method('execute')
-        ->with($this->equalTo($expectedCommand))
-        ->will($this->returnCallback(function($command, &$output) {$output =  "Depot depot 2013/01/28 local /path/to/depots/depot/... 'depot project'\n"; return true;}));
-
-        $result = $this->perforce->checkStream("depot");
-        $this->assertFalse($result);
-
         $branches = $this->perforce->getBranches();
         $this->assertEquals("//depot", $branches['master']);
     }
 
     public function testGetTagsWithoutStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot -p port labels");
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port labels";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
@@ -314,36 +316,35 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testGetTagsWithStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot_branch -p port labels");
+        $this->setPerforceToStream();
+
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port labels";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  "Label 0.0.1 2013/07/31 'First Label!'\nLabel 0.0.2 2013/08/01 'Second Label!'\n"; return true;}));
 
-        $this->perforce->setStream("//depot/branch");
         $tags = $this->perforce->getTags();
         $this->assertEquals("//depot/branch@0.0.1", $tags['0.0.1']);
         $this->assertEquals("//depot/branch@0.0.2", $tags['0.0.2']);
     }
 
     public function testCheckStreamWithoutStream() {
-        $this->perforce->commandReturnValue = "Depot depot 2013/01/28 local /path/to/depots/depot/... 'depot project'";
         $result = $this->perforce->checkStream("depot");
         $this->assertFalse($result);
-        $this->assertFalse($this->perforce->testIsStream());
+        $this->assertFalse($this->perforce->isStream());
     }
 
     public function testCheckStreamWithStream() {
-        $line1 = "Depot depot 2013/01/28 branch /path/to/depots/depot/... 'depot project'\n";
-        $line2 = "Depot depot 2013/01/28 development /path/to/depots/depot/... 'depot project'\n";
-        $this->perforce->commandReturnValue = $line1 . $line2;
+        $this->processExecutor->expects($this->any())->method('execute')
+        ->will($this->returnCallback(function($command, &$output) {$output =  "Depot depot 2013/06/25 stream /p4/1/depots/depot/... 'Created by Me'"; return true;}));
         $result = $this->perforce->checkStream("depot");
-        $this->assertFalse($result);
-        $this->assertFalse($this->perforce->testIsStream());
+        $this->assertTrue($result);
+        $this->assertTrue($this->perforce->isStream());
     }
 
     public function testGetComposerInformationWithoutLabelWithoutStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot -p port  print //depot/composer.json");
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port  print //depot/composer.json";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
@@ -360,13 +361,13 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testGetComposerInformationWithLabelWithoutStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -p port  files //depot/composer.json@0.0.1");
+        $expectedCommand = "p4 -u user -p port  files //depot/composer.json@0.0.1";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  "//depot/composer.json#1 - branch change 10001 (text)"; return true;}));
 
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot -p port  print //depot/composer.json@10001");
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port  print //depot/composer.json@10001";
         $this->processExecutor->expects($this->at(1))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
@@ -384,13 +385,14 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testGetComposerInformationWithoutLabelWithStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot_branch -p port  print //depot/branch/composer.json");
+        $this->setPerforceToStream();
+
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port  print //depot/branch/composer.json";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  PerforceTest::getComposerJson(); return true;}));
 
-        $this->perforce->setStream("//depot/branch");
         $result = $this->perforce->getComposerInformation("//depot/branch");
 
         $expected = array(
@@ -403,19 +405,19 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testGetComposerInformationWithLabelWithStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -p port  files //depot/branch/composer.json@0.0.1");
+        $this->setPerforceToStream();
+        $expectedCommand = "p4 -u user -p port  files //depot/branch/composer.json@0.0.1";
         $this->processExecutor->expects($this->at(0))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  "//depot/composer.json#1 - branch change 10001 (text)"; return true;}));
 
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot_branch -p port  print //depot/branch/composer.json@10001");
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port  print //depot/branch/composer.json@10001";
         $this->processExecutor->expects($this->at(1))
         ->method('execute')
         ->with($this->equalTo($expectedCommand))
         ->will($this->returnCallback(function($command, &$output) {$output =  PerforceTest::getComposerJson(); return true;}));
 
-        $this->perforce->setStream("//depot/branch");
         $result = $this->perforce->getComposerInformation("//depot/branch@0.0.1");
 
         $expected = array(
@@ -428,7 +430,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testSyncCodeBaseWithoutStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label");
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label";
         $this->processExecutor->expects($this->at(1))
         ->method('execute')
         ->with($this->equalTo($expectedCommand), $this->equalTo(null))
@@ -438,20 +440,20 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     }
 
     public function testSyncCodeBaseWithStream() {
-        $expectedCommand = $this->winCompat("p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label");
-        $this->processExecutor->expects($this->at(1))
-        ->method('execute')
-        ->with($this->equalTo($expectedCommand), $this->equalTo(null))
-        ->will($this->returnValue(0));
+        $this->setPerforceToStream();
+        $expectedCommand = "p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label";
+            $this->processExecutor->expects($this->at(1))
+            ->method('execute')
+            ->with($this->equalTo($expectedCommand))
+            ->will($this->returnValue(0));
 
-        $this->perforce->setStream("//depot/branch");
         $this->perforce->syncCodeBase("label");
     }
 
     public function testCheckServerExists() {
         $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
 
-        $expectedCommand = $this->winCompat("p4 -p perforce.does.exist:port info -s");
+        $expectedCommand = "p4 -p perforce.does.exist:port info -s";
         $processExecutor->expects($this->at(0))
             ->method('execute')
             ->with($this->equalTo($expectedCommand), $this->equalTo(null))
@@ -464,7 +466,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
     public function testCheckServerExistsWithFailure() {
         $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
 
-        $expectedCommand = $this->winCompat("p4 -p perforce.does.not.exist:port info -s");
+        $expectedCommand = "p4 -p perforce.does.not.exist:port info -s";
         $processExecutor->expects($this->at(0))
             ->method('execute')
             ->with($this->equalTo($expectedCommand), $this->equalTo(null))
@@ -513,7 +515,7 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
         );
         if ($withStream) {
             $expectedArray[] = "Stream:";
-            $expectedArray[] = "  //depot/branching";
+            $expectedArray[] = "  //depot/branch";
         }
         else {
             $expectedArray[] = "View:  //depot/...  //composer_perforce_TEST_depot/depot/...";
@@ -522,16 +524,8 @@ class PerforceTest extends \PHPUnit_Framework_TestCase {
         return $expectedArray;
     }
 
-    private function winCompat($cmd) {
-        if (defined('PHP_WINDOWS_VERSION_BUILD')) {
-            $cmd = str_replace('cd ', 'cd /D ', $cmd);
-            $cmd = str_replace('composerPath', getcwd() . '/composerPath', $cmd);
-
-            return strtr($cmd, "'", '"');
-        }
-
-        return $cmd;
+    private function setPerforceToStream(){
+        $this->perforce->setStream("//depot/branch");
     }
-
 }
 

+ 0 - 106
tests/Composer/Test/Util/TestingPerforce.php

@@ -1,106 +0,0 @@
-<?php
-/**
- * Created by JetBrains PhpStorm.
- * User: matt.whittom
- * Date: 7/31/13
- * Time: 2:37 PM
- * To change this template use File | Settings | File Templates.
- */
-
-namespace Composer\Test\Util;
-
-
-use Composer\Util\Perforce;
-use org\bovigo\vfs\vfsStream;
-
-
-class TestingPerforce extends Perforce {
-    public $windows_flag;
-
-    public function __construct($repoConfig, $port, $path, $process=null){
-        parent::__construct($repoConfig, $port, $path, $process);
-        $this->windows_flag = false;
-    }
-    /*
-     * Override functions
-     */
-    protected function getRandomValue() {
-        return "TEST";
-    }
-    protected function isWindows(){
-        return $this->windows_flag;
-    }
-
-//    protected function executeCommand($command) {
-//        $this->previousCommand = $this->lastCommand;
-//        $this->lastCommand = $command;
-//        $result = $this->commandReturnValue;
-//        $this->commandReturnValue = $this->nextCommandReturnValue;
-//        $this->nextCommandReturnValue = null;
-//        return $result;
-//    }
-
-    public function writeP4ClientSpec() {
-        $spec = fopen(vfsStream::url($this->getP4ClientSpec()), 'w');
-        $this->writeClientSpecToFile($spec);
-        fclose($spec);
-    }
-
-    /*
-     * Test Helper functions
-     */
-    public function setDepotType($depotType) {
-        $this->p4depotType = $depotType;
-        $this->p4stream    = NULL;
-    }
-
-    /*
-     * Functions to expose protected methods for testing:
-     */
-    public function setP4User($p4user){
-        $this->p4user = $p4user;
-    }
-    public function setP4Password($password){
-        $this->p4password = $password;
-    }
-
-    public function testGetClient() {
-        return $this->getClient();
-    }
-
-    public function testGetStream() {
-        return $this->getStream();
-    }
-
-    public function testGetStreamWithoutLabel() {
-        return $this->getStreamWithoutLabel();
-    }
-
-    public function testGetClientSpec() {
-        return $this->getP4ClientSpec();
-    }
-
-    public function testGenerateP4Command($command, $useClient = TRUE) {
-        return $this->generateP4Command($command, $useClient);
-    }
-
-    public function testIsLoggedIn()
-    {
-        return $this->isLoggedIn();
-    }
-
-    public function testIsStream()
-    {
-        return $this->isStream();
-    }
-
-    public function testGetP4Variable($name)
-    {
-        return $this->testGetP4Variable($name);
-    }
-
-    public function testQueryP4Password($io)
-    {
-        return $this->queryP4Password($io);
-    }
-}