From bc060489926ef73199b12dd12de5d65d88432537 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Fri, 17 Nov 2017 22:59:07 +0100
Subject: [PATCH 01/13] FEATURE: Initialized basic functional test case

---
 phpunit.xml.dist                        |   3 +
 tests/Functional/FunctionalTestCase.php | 142 ++++++++++++++++++++++++
 2 files changed, 145 insertions(+)
 create mode 100644 tests/Functional/FunctionalTestCase.php

diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 4452416..aa8ea83 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -17,6 +17,9 @@
         <testsuite name="Integration Tests">
             <directory>./tests/Integration/</directory>
         </testsuite>
+        <testsuite name="Functional Tests">
+            <directory>./tests/Functional/</directory>
+        </testsuite>
     </testsuites>
 
     <filter>
diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php
new file mode 100644
index 0000000..465be14
--- /dev/null
+++ b/tests/Functional/FunctionalTestCase.php
@@ -0,0 +1,142 @@
+<?php
+
+namespace Higidi\ComposerPhpCSStandardsPlugin\Tests\Functional;
+
+use Composer\Console\Application;
+use Composer\Factory;
+use Composer\Json\JsonFile;
+use PHPUnit\Framework\TestCase;
+use Symfony\Component\Console\Tester\ApplicationTester;
+use Symfony\Component\Filesystem\Filesystem;
+
+/**
+ * Base functional test case.
+ */
+class FunctionalTestCase extends TestCase
+{
+    /**
+     * @var string
+     */
+    protected $oldHomeDirectory;
+
+    /**
+     * @var string
+     */
+    protected $oldWorkingDirectory;
+
+    /**
+     * @var string
+     */
+    protected $tempWorkingDir;
+
+    /**
+     * @var Application
+     */
+    protected $application;
+
+    /**
+     * @var ApplicationTester
+     */
+    protected $applicationTester;
+
+    /**
+     * @return void
+     */
+    protected function setUp()
+    {
+        parent::setUp();
+        $this->oldWorkingDirectory = getcwd();
+        $this->oldHomeDirectory = getenv('HOME');
+        $this->tempWorkingDir = $this->createUniqueTmpDirectory();
+        chdir($this->tempWorkingDir);
+        putenv(sprintf('HOME=%s', $this->tempWorkingDir));
+        putenv('COMPOSER_ROOT_VERSION=dev-master');
+        $this->application = new Application();
+        $this->applicationTester = new ApplicationTester($this->application);
+    }
+
+    /**
+     * @return void
+     */
+    protected function tearDown()
+    {
+        parent::tearDown();
+        if ($this->tempWorkingDir) {
+            $fs = new Filesystem();
+            $fs->remove($this->tempWorkingDir);
+        }
+        chdir($this->oldWorkingDirectory);
+        putenv(sprintf('HOME=%s', $this->oldHomeDirectory));
+        putenv('COMPOSER_ROOT_VERSION');
+        unset($this->oldWorkingDirectory, $this->workingDir);
+    }
+
+    /**
+     * @return bool|string
+     */
+    protected function createUniqueTmpDirectory()
+    {
+        $attempts = 5;
+        $root = sys_get_temp_dir();
+
+        do {
+            $unique = $root . DIRECTORY_SEPARATOR . uniqid('composer-test-' . rand(1000, 9000));
+
+            $fs = new Filesystem();
+            if (!file_exists($unique)) {
+                $fs->mkdir($unique);
+
+                return realpath($unique);
+            }
+        } while (--$attempts);
+
+        throw new \RuntimeException('Failed to create a unique temporary directory.');
+    }
+
+    /**
+     * @return string
+     */
+    protected function getComposerJsonFilePath()
+    {
+        return Factory::getComposerFile();
+    }
+
+    /**
+     * @return JsonFile
+     */
+    protected function getComposerJsonFile()
+    {
+        $jsonFile = new JsonFile($this->getComposerJsonFilePath());
+
+        return $jsonFile;
+    }
+
+    /**
+     * @return bool|string
+     */
+    protected function getLocalPackagePath()
+    {
+        return realpath(__DIR__ . '/../../');
+    }
+
+    /**
+     * @param array $data
+     *
+     * @return void
+     */
+    protected function writeComposerJson(array $data)
+    {
+        $defaultData = array(
+            'repositories' => array(
+                array(
+                    'type' => 'path',
+                    'url' => $this->getLocalPackagePath(),
+                )
+            ),
+        );
+        $data = array_merge_recursive($defaultData, $data);
+        $jsonFile = $this->getComposerJsonFile();
+
+        $jsonFile->write($data);
+    }
+}
-- 
GitLab


From 35e9c4c7bc107d63c6f9b08fb171056e76e7d93d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Sat, 18 Nov 2017 00:33:50 +0100
Subject: [PATCH 02/13] FEATURE: Initialized local test package repository &
 optimized base test case

---
 .../Fixtures/Composer/simple-standard/composer.json  |  9 +++++++++
 tests/Fixtures/Composer/simple-standard/ruleset.xml  |  4 ++++
 tests/Functional/FunctionalTestCase.php              | 12 ++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)
 create mode 100644 tests/Fixtures/Composer/simple-standard/composer.json
 create mode 100644 tests/Fixtures/Composer/simple-standard/ruleset.xml

diff --git a/tests/Fixtures/Composer/simple-standard/composer.json b/tests/Fixtures/Composer/simple-standard/composer.json
new file mode 100644
index 0000000..f982b13
--- /dev/null
+++ b/tests/Fixtures/Composer/simple-standard/composer.json
@@ -0,0 +1,9 @@
+{
+  "name": "higidi/testcase-simple-standard",
+  "description": "Testcase with simple standard.",
+  "type": "phpcodesniffer-standard",
+  "require": {
+    "higidi/composer-phpcodesniffer-standards-plugin": "dev-develop"
+  },
+  "version": "1.0.0"
+}
diff --git a/tests/Fixtures/Composer/simple-standard/ruleset.xml b/tests/Fixtures/Composer/simple-standard/ruleset.xml
new file mode 100644
index 0000000..c0ecd77
--- /dev/null
+++ b/tests/Fixtures/Composer/simple-standard/ruleset.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0"?>
+<ruleset name="Simple-Standard">
+    <description>Testcase with simple standard.</description>
+</ruleset>
diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php
index 465be14..09d26f6 100644
--- a/tests/Functional/FunctionalTestCase.php
+++ b/tests/Functional/FunctionalTestCase.php
@@ -50,8 +50,8 @@ class FunctionalTestCase extends TestCase
         $this->tempWorkingDir = $this->createUniqueTmpDirectory();
         chdir($this->tempWorkingDir);
         putenv(sprintf('HOME=%s', $this->tempWorkingDir));
-        putenv('COMPOSER_ROOT_VERSION=dev-master');
         $this->application = new Application();
+        $this->application->setAutoExit(false);
         $this->applicationTester = new ApplicationTester($this->application);
     }
 
@@ -131,8 +131,16 @@ class FunctionalTestCase extends TestCase
                 array(
                     'type' => 'path',
                     'url' => $this->getLocalPackagePath(),
-                )
+                ),
+                array(
+                    'type' => 'path',
+                    'url' => implode(
+                        DIRECTORY_SEPARATOR,
+                        array($this->getLocalPackagePath(), 'tests', 'Fixtures', 'Composer', '*')
+                    ),
+                ),
             ),
+            'minimum-stability' => 'dev',
         );
         $data = array_merge_recursive($defaultData, $data);
         $jsonFile = $this->getComposerJsonFile();
-- 
GitLab


From fb7a3ab046baac2892d03a02999679b7647eb506 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Sat, 18 Nov 2017 00:34:11 +0100
Subject: [PATCH 03/13] FEATURE: Initialized base test cases for install &
 remove

---
 tests/Functional/FunctionalTest.php | 87 +++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
 create mode 100644 tests/Functional/FunctionalTest.php

diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php
new file mode 100644
index 0000000..e20f10f
--- /dev/null
+++ b/tests/Functional/FunctionalTest.php
@@ -0,0 +1,87 @@
+<?php
+
+namespace Higidi\ComposerPhpCSStandardsPlugin\Tests\Functional;
+
+class FunctionalTest extends FunctionalTestCase
+{
+    /**
+     * @test
+     */
+    public function itInstallPhpCodeSnifferStandards()
+    {
+        $this->writeComposerJson(
+            array(
+                'require-dev' => array(
+                    'higidi/testcase-simple-standard' => '1.0.0',
+                )
+            )
+        );
+        $srcPath = implode(
+            DIRECTORY_SEPARATOR,
+            array($this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml')
+        );
+        $dstPath = implode(
+            DIRECTORY_SEPARATOR,
+            array(
+                $this->tempWorkingDir,
+                'vendor',
+                'squizlabs',
+                'php_codesniffer',
+                'CodeSniffer',
+                'Standards',
+                'Simple-Standard',
+                'ruleset.xml'
+            )
+        );
+
+        $exitCode = $this->applicationTester->run(array('install'));
+
+        $this->assertSame(0, $exitCode);
+        $this->assertFileExists($dstPath);
+        $this->assertFileEquals($srcPath, $dstPath);
+    }
+
+    /**
+     * @test
+     */
+    public function itUninstallPhpCodeSnifferStandards()
+    {
+        $this->writeComposerJson(
+            array(
+                'require-dev' => array(
+                    'higidi/testcase-simple-standard' => '1.0.0',
+                )
+            )
+        );
+        $srcPath = implode(
+            DIRECTORY_SEPARATOR,
+            array($this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml')
+        );
+        $dstPath = implode(
+            DIRECTORY_SEPARATOR,
+            array(
+                $this->tempWorkingDir,
+                'vendor',
+                'squizlabs',
+                'php_codesniffer',
+                'CodeSniffer',
+                'Standards',
+                'Simple-Standard',
+                'ruleset.xml'
+            )
+        );
+
+        $exitCode = $this->applicationTester->run(array('install'));
+
+        $this->assertSame(0, $exitCode);
+        $this->assertFileExists($dstPath);
+        $this->assertFileEquals($srcPath, $dstPath);
+
+        $exitCode = $this->applicationTester->run(
+            array('command' => 'remove', 'packages' => array('higidi/testcase-simple-standard'))
+        );
+
+        $this->assertSame(0, $exitCode);
+        $this->assertFileNotExists($dstPath);
+    }
+}
-- 
GitLab


From 4ba7933e84210f802c649206c31e06b999b6958d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Sat, 18 Nov 2017 00:43:58 +0100
Subject: [PATCH 04/13] FIX: Set phpunit memory limit

---
 phpunit.xml.dist | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index aa8ea83..37fc7dc 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -10,6 +10,10 @@
          syntaxCheck="false"
          bootstrap="tests/bootstrap.php">
 
+    <php>
+        <ini name="memory_limit" value="-1"/>
+    </php>
+
     <testsuites>
         <testsuite name="Unit Tests">
             <directory>./tests/Unit/</directory>
-- 
GitLab


From fae5f3ace4f3071819d29e7a47e196f1906c4ef8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Tue, 5 Dec 2017 21:54:12 +0100
Subject: [PATCH 05/13] FIX: Adjust test cases for install & remove to work as
 excepted

---
 .../Composer/simple-standard/composer.json    |   2 +-
 tests/Functional/FunctionalTest.php           |  43 ++++----
 tests/Functional/FunctionalTestCase.php       | 103 ++++++++++++------
 3 files changed, 91 insertions(+), 57 deletions(-)

diff --git a/tests/Fixtures/Composer/simple-standard/composer.json b/tests/Fixtures/Composer/simple-standard/composer.json
index f982b13..17fc11a 100644
--- a/tests/Fixtures/Composer/simple-standard/composer.json
+++ b/tests/Fixtures/Composer/simple-standard/composer.json
@@ -3,7 +3,7 @@
   "description": "Testcase with simple standard.",
   "type": "phpcodesniffer-standard",
   "require": {
-    "higidi/composer-phpcodesniffer-standards-plugin": "dev-develop"
+    "higidi/composer-phpcodesniffer-standards-plugin": "dev-workingDir"
   },
   "version": "1.0.0"
 }
diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php
index e20f10f..86dfb05 100644
--- a/tests/Functional/FunctionalTest.php
+++ b/tests/Functional/FunctionalTest.php
@@ -10,31 +10,30 @@ class FunctionalTest extends FunctionalTestCase
     public function itInstallPhpCodeSnifferStandards()
     {
         $this->writeComposerJson(
-            array(
-                'require-dev' => array(
-                    'higidi/testcase-simple-standard' => '1.0.0',
-                )
-            )
+            [
+                'higidi/testcase-simple-standard' => '1.0.0',
+            ]
         );
         $srcPath = implode(
             DIRECTORY_SEPARATOR,
-            array($this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml')
+            [$this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml']
         );
         $dstPath = implode(
             DIRECTORY_SEPARATOR,
-            array(
-                $this->tempWorkingDir,
+            [
+                $this->testWorkingDir,
                 'vendor',
                 'squizlabs',
                 'php_codesniffer',
                 'CodeSniffer',
                 'Standards',
                 'Simple-Standard',
-                'ruleset.xml'
-            )
+                'ruleset.xml',
+            ]
         );
 
-        $exitCode = $this->applicationTester->run(array('install'));
+        $exitCode = $this->applicationTester->run(['install']);
+        $test = $this->applicationTester->getDisplay();
 
         $this->assertSame(0, $exitCode);
         $this->assertFileExists($dstPath);
@@ -47,38 +46,36 @@ class FunctionalTest extends FunctionalTestCase
     public function itUninstallPhpCodeSnifferStandards()
     {
         $this->writeComposerJson(
-            array(
-                'require-dev' => array(
-                    'higidi/testcase-simple-standard' => '1.0.0',
-                )
-            )
+            [
+                'higidi/testcase-simple-standard' => '1.0.0',
+            ]
         );
         $srcPath = implode(
             DIRECTORY_SEPARATOR,
-            array($this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml')
+            [$this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml']
         );
         $dstPath = implode(
             DIRECTORY_SEPARATOR,
-            array(
-                $this->tempWorkingDir,
+            [
+                $this->testWorkingDir,
                 'vendor',
                 'squizlabs',
                 'php_codesniffer',
                 'CodeSniffer',
                 'Standards',
                 'Simple-Standard',
-                'ruleset.xml'
-            )
+                'ruleset.xml',
+            ]
         );
 
-        $exitCode = $this->applicationTester->run(array('install'));
+        $exitCode = $this->applicationTester->run(['install']);
 
         $this->assertSame(0, $exitCode);
         $this->assertFileExists($dstPath);
         $this->assertFileEquals($srcPath, $dstPath);
 
         $exitCode = $this->applicationTester->run(
-            array('command' => 'remove', 'packages' => array('higidi/testcase-simple-standard'))
+            ['command' => 'remove', 'packages' => ['higidi/testcase-simple-standard']]
         );
 
         $this->assertSame(0, $exitCode);
diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php
index 09d26f6..8a48590 100644
--- a/tests/Functional/FunctionalTestCase.php
+++ b/tests/Functional/FunctionalTestCase.php
@@ -14,11 +14,6 @@ use Symfony\Component\Filesystem\Filesystem;
  */
 class FunctionalTestCase extends TestCase
 {
-    /**
-     * @var string
-     */
-    protected $oldHomeDirectory;
-
     /**
      * @var string
      */
@@ -27,7 +22,7 @@ class FunctionalTestCase extends TestCase
     /**
      * @var string
      */
-    protected $tempWorkingDir;
+    protected $testWorkingDir;
 
     /**
      * @var Application
@@ -46,10 +41,8 @@ class FunctionalTestCase extends TestCase
     {
         parent::setUp();
         $this->oldWorkingDirectory = getcwd();
-        $this->oldHomeDirectory = getenv('HOME');
-        $this->tempWorkingDir = $this->createUniqueTmpDirectory();
-        chdir($this->tempWorkingDir);
-        putenv(sprintf('HOME=%s', $this->tempWorkingDir));
+        $this->testWorkingDir = $this->createUniqueTmpDirectory();
+        chdir($this->testWorkingDir);
         $this->application = new Application();
         $this->application->setAutoExit(false);
         $this->applicationTester = new ApplicationTester($this->application);
@@ -61,18 +54,16 @@ class FunctionalTestCase extends TestCase
     protected function tearDown()
     {
         parent::tearDown();
-        if ($this->tempWorkingDir) {
+        chdir($this->oldWorkingDirectory);
+        if ($this->testWorkingDir) {
             $fs = new Filesystem();
-            $fs->remove($this->tempWorkingDir);
+            $fs->remove($this->testWorkingDir);
         }
-        chdir($this->oldWorkingDirectory);
-        putenv(sprintf('HOME=%s', $this->oldHomeDirectory));
-        putenv('COMPOSER_ROOT_VERSION');
-        unset($this->oldWorkingDirectory, $this->workingDir);
+        unset($this->oldWorkingDirectory, $this->testWorkingDir);
     }
 
     /**
-     * @return bool|string
+     * @return string
      */
     protected function createUniqueTmpDirectory()
     {
@@ -83,7 +74,7 @@ class FunctionalTestCase extends TestCase
             $unique = $root . DIRECTORY_SEPARATOR . uniqid('composer-test-' . rand(1000, 9000));
 
             $fs = new Filesystem();
-            if (!file_exists($unique)) {
+            if (! file_exists($unique)) {
                 $fs->mkdir($unique);
 
                 return realpath($unique);
@@ -120,31 +111,77 @@ class FunctionalTestCase extends TestCase
     }
 
     /**
-     * @param array $data
+     * @return string
+     */
+    protected function getLocalPackageComposerPath()
+    {
+        return $this->getLocalPackagePath() . DIRECTORY_SEPARATOR . 'composer.json';
+    }
+
+    /**
+     * @return mixed
+     */
+    protected function getLocalPackageComposerPackage()
+    {
+        $jsonFile = new JsonFile($this->getLocalPackageComposerPath());
+
+        $json = $jsonFile->read();
+        if (! is_array($json)) {
+            throw new \RuntimeException();
+        }
+        $json['version'] = 'dev-workingDir';
+        $json['dist'] = [
+            'type' => 'path',
+            'url' => $this->getLocalPackagePath(),
+        ];
+
+        return $json;
+    }
+
+    /**
+     * @param array $requireDev
+     * @param array $require
+     * @param array $additionalJson
      *
      * @return void
      */
-    protected function writeComposerJson(array $data)
+    protected function writeComposerJson(array $requireDev, array $require = [], array $additionalJson = [])
     {
-        $defaultData = array(
-            'repositories' => array(
-                array(
-                    'type' => 'path',
-                    'url' => $this->getLocalPackagePath(),
-                ),
-                array(
+        $defaultJson = [
+            'repositories' => [
+                [
+                    'type' => 'package',
+                    'package' => $this->getLocalPackageComposerPackage(),
+                ],
+                [
                     'type' => 'path',
                     'url' => implode(
                         DIRECTORY_SEPARATOR,
-                        array($this->getLocalPackagePath(), 'tests', 'Fixtures', 'Composer', '*')
+                        [$this->getLocalPackagePath(), 'tests', 'Fixtures', 'Composer', '*']
                     ),
-                ),
-            ),
+                ],
+            ],
             'minimum-stability' => 'dev',
-        );
-        $data = array_merge_recursive($defaultData, $data);
+            'config' => [
+                'bin-dir' => 'bin',
+                'vendor-dir' => 'vendor',
+            ],
+            'require-dev' => [
+                'squizlabs/php_codesniffer' => '*',
+            ],
+        ];
+        $json = [
+            'require-dev' => $requireDev,
+        ];
+        if (count($require) > 0) {
+            $json['require'] = $require;
+        }
+        $json = array_replace_recursive($defaultJson, $json);
+        if (count($additionalJson) > 0) {
+            $json = array_replace_recursive($json, $additionalJson);
+        }
         $jsonFile = $this->getComposerJsonFile();
 
-        $jsonFile->write($data);
+        $jsonFile->write($json);
     }
 }
-- 
GitLab


From 6761b8171aabc3fe635f2cfb0745394308fff323 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Tue, 5 Dec 2017 22:27:59 +0100
Subject: [PATCH 06/13] TASK: Remove test variable

---
 tests/Functional/FunctionalTest.php | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php
index 86dfb05..45d8cf5 100644
--- a/tests/Functional/FunctionalTest.php
+++ b/tests/Functional/FunctionalTest.php
@@ -33,7 +33,6 @@ class FunctionalTest extends FunctionalTestCase
         );
 
         $exitCode = $this->applicationTester->run(['install']);
-        $test = $this->applicationTester->getDisplay();
 
         $this->assertSame(0, $exitCode);
         $this->assertFileExists($dstPath);
-- 
GitLab


From cd52b2da302ce33863f969f0dd6f9d4fc933b106 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 20:00:49 +0100
Subject: [PATCH 07/13] FEATURE: Safe build folder as artifact if fails

---
 .gitlab-ci.yml                          |  4 ++++
 tests/Functional/FunctionalTestCase.php | 11 +++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index bd3302f..29e4e0d 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -46,6 +46,10 @@ lint:php-mass-detection:
     - composer install --optimize-autoloader --no-interaction --no-ansi --prefer-dist
   script:
     - ./vendor/bin/phpunit --coverage-text --colors=never
+  artifacts:
+    when: on_failure
+    paths:
+      - /tmp/composer-test
 
 test:5.4:
   <<: *test
diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php
index 8a48590..71d362e 100644
--- a/tests/Functional/FunctionalTestCase.php
+++ b/tests/Functional/FunctionalTestCase.php
@@ -68,10 +68,16 @@ class FunctionalTestCase extends TestCase
     protected function createUniqueTmpDirectory()
     {
         $attempts = 5;
-        $root = sys_get_temp_dir();
+        $randomize = false;
+        $root = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'composer-test';
+        $name = $this->getName();
+        $folderName = preg_replace('/[^a-zA-Z0-9\-\._]/', '', $name);
 
         do {
-            $unique = $root . DIRECTORY_SEPARATOR . uniqid('composer-test-' . rand(1000, 9000));
+            $unique = $root . DIRECTORY_SEPARATOR . $folderName;
+            if ($randomize) {
+                $unique .= '-' . uniqid(rand(1000, 9000));
+            }
 
             $fs = new Filesystem();
             if (! file_exists($unique)) {
@@ -79,6 +85,7 @@ class FunctionalTestCase extends TestCase
 
                 return realpath($unique);
             }
+            $randomize = true;
         } while (--$attempts);
 
         throw new \RuntimeException('Failed to create a unique temporary directory.');
-- 
GitLab


From 0425a2d7ce2ae4f451593e87dfe1401f04c85857 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 21:48:21 +0100
Subject: [PATCH 08/13] TASK. Renamed base ComposerTestCase

---
 .../Functional/{FunctionalTestCase.php => ComposerTestCase.php} | 2 +-
 tests/Functional/FunctionalTest.php                             | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
 rename tests/Functional/{FunctionalTestCase.php => ComposerTestCase.php} (99%)

diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/ComposerTestCase.php
similarity index 99%
rename from tests/Functional/FunctionalTestCase.php
rename to tests/Functional/ComposerTestCase.php
index 71d362e..aa0c8eb 100644
--- a/tests/Functional/FunctionalTestCase.php
+++ b/tests/Functional/ComposerTestCase.php
@@ -12,7 +12,7 @@ use Symfony\Component\Filesystem\Filesystem;
 /**
  * Base functional test case.
  */
-class FunctionalTestCase extends TestCase
+class ComposerTestCase extends TestCase
 {
     /**
      * @var string
diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php
index 45d8cf5..5f84035 100644
--- a/tests/Functional/FunctionalTest.php
+++ b/tests/Functional/FunctionalTest.php
@@ -2,7 +2,7 @@
 
 namespace Higidi\ComposerPhpCSStandardsPlugin\Tests\Functional;
 
-class FunctionalTest extends FunctionalTestCase
+class FunctionalTest extends ComposerTestCase
 {
     /**
      * @test
-- 
GitLab


From 807e03ab1b1526addd0b10e8f646bfd3c2acba29 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 21:50:04 +0100
Subject: [PATCH 09/13] FEATURE: Create test classes for installation &
 uninstallation of standards

---
 tests/Functional/InstallTest.php              | 41 +++++++++++++++++++
 .../{FunctionalTest.php => UninstallTest.php} | 37 +----------------
 2 files changed, 42 insertions(+), 36 deletions(-)
 create mode 100644 tests/Functional/InstallTest.php
 rename tests/Functional/{FunctionalTest.php => UninstallTest.php} (55%)

diff --git a/tests/Functional/InstallTest.php b/tests/Functional/InstallTest.php
new file mode 100644
index 0000000..5ca601b
--- /dev/null
+++ b/tests/Functional/InstallTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Higidi\ComposerPhpCSStandardsPlugin\Tests\Functional;
+
+class InstallTest extends ComposerTestCase
+{
+    /**
+     * @test
+     */
+    public function itInstallPhpCodeSnifferStandards()
+    {
+        $this->writeComposerJson(
+            [
+                'higidi/testcase-simple-standard' => '1.0.0',
+            ]
+        );
+        $srcPath = implode(
+            DIRECTORY_SEPARATOR,
+            [$this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml']
+        );
+        $dstPath = implode(
+            DIRECTORY_SEPARATOR,
+            [
+                $this->testWorkingDir,
+                'vendor',
+                'squizlabs',
+                'php_codesniffer',
+                'CodeSniffer',
+                'Standards',
+                'Simple-Standard',
+                'ruleset.xml',
+            ]
+        );
+
+        $exitCode = $this->applicationTester->run(['install']);
+
+        $this->assertSame(0, $exitCode);
+        $this->assertFileExists($dstPath);
+        $this->assertFileEquals($srcPath, $dstPath);
+    }
+}
diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/UninstallTest.php
similarity index 55%
rename from tests/Functional/FunctionalTest.php
rename to tests/Functional/UninstallTest.php
index 5f84035..68f8d43 100644
--- a/tests/Functional/FunctionalTest.php
+++ b/tests/Functional/UninstallTest.php
@@ -2,43 +2,8 @@
 
 namespace Higidi\ComposerPhpCSStandardsPlugin\Tests\Functional;
 
-class FunctionalTest extends ComposerTestCase
+class UninstallTest extends ComposerTestCase
 {
-    /**
-     * @test
-     */
-    public function itInstallPhpCodeSnifferStandards()
-    {
-        $this->writeComposerJson(
-            [
-                'higidi/testcase-simple-standard' => '1.0.0',
-            ]
-        );
-        $srcPath = implode(
-            DIRECTORY_SEPARATOR,
-            [$this->getLocalPackagePath(), 'tests', 'fixtures', 'Composer', 'simple-standard', 'ruleset.xml']
-        );
-        $dstPath = implode(
-            DIRECTORY_SEPARATOR,
-            [
-                $this->testWorkingDir,
-                'vendor',
-                'squizlabs',
-                'php_codesniffer',
-                'CodeSniffer',
-                'Standards',
-                'Simple-Standard',
-                'ruleset.xml',
-            ]
-        );
-
-        $exitCode = $this->applicationTester->run(['install']);
-
-        $this->assertSame(0, $exitCode);
-        $this->assertFileExists($dstPath);
-        $this->assertFileEquals($srcPath, $dstPath);
-    }
-
     /**
      * @test
      */
-- 
GitLab


From de70858c0b1797b481f8772523b067324cb7d8ca Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 22:00:16 +0100
Subject: [PATCH 10/13] TASK: Only remove test working dir, if test succeed

---
 tests/Functional/ComposerTestCase.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/Functional/ComposerTestCase.php b/tests/Functional/ComposerTestCase.php
index aa0c8eb..f12406d 100644
--- a/tests/Functional/ComposerTestCase.php
+++ b/tests/Functional/ComposerTestCase.php
@@ -55,7 +55,7 @@ class ComposerTestCase extends TestCase
     {
         parent::tearDown();
         chdir($this->oldWorkingDirectory);
-        if ($this->testWorkingDir) {
+        if ($this->testWorkingDir && !$this->hasFailed()) {
             $fs = new Filesystem();
             $fs->remove($this->testWorkingDir);
         }
-- 
GitLab


From 10dee8e45570c83bad9145aea157e4e293e49389 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 22:03:08 +0100
Subject: [PATCH 11/13] FEATURE: Print current php & composer version (run
 composer self-update before)

---
 .gitlab-ci.yml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 29e4e0d..71e75c0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -43,7 +43,10 @@ lint:php-mass-detection:
     WITH_XDEBUG: "true"
   before_script:
     - apt-get update; apt-get install -y unzip
-    - composer install --optimize-autoloader --no-interaction --no-ansi --prefer-dist
+    - php -v
+    - composer --no-ansi self-update
+    - composer --no-ansi --version
+    - composer install --optimize-autoloader --classmap-authoritative --no-interaction --prefer-dist --no-ansi
   script:
     - ./vendor/bin/phpunit --coverage-text --colors=never
   artifacts:
-- 
GitLab


From c16e8bfead1ad1d018deec2241e334a0ad95dc74 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 22:25:43 +0100
Subject: [PATCH 12/13] TASK: Optimize artifact building on failures

---
 .gitlab-ci.yml | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 71e75c0..d06104f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -44,15 +44,18 @@ lint:php-mass-detection:
   before_script:
     - apt-get update; apt-get install -y unzip
     - php -v
+    - php -r 'echo sys_get_temp_dir() . PHP_EOL;'
     - composer --no-ansi self-update
     - composer --no-ansi --version
     - composer install --optimize-autoloader --classmap-authoritative --no-interaction --prefer-dist --no-ansi
   script:
     - ./vendor/bin/phpunit --coverage-text --colors=never
+  after_script:
+    - mv -f `php -r 'echo sys_get_temp_dir();'`/composer-test .build
   artifacts:
     when: on_failure
     paths:
-      - /tmp/composer-test
+      - .build/
 
 test:5.4:
   <<: *test
-- 
GitLab


From 13927573c97b184634eeb5bb6eb934d4455083da Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= <daniel@higidi.de>
Date: Thu, 7 Dec 2017 23:11:08 +0100
Subject: [PATCH 13/13] TASK: Optimize recognizing last test pass status

---
 tests/Functional/ComposerTestCase.php | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/Functional/ComposerTestCase.php b/tests/Functional/ComposerTestCase.php
index f12406d..392a154 100644
--- a/tests/Functional/ComposerTestCase.php
+++ b/tests/Functional/ComposerTestCase.php
@@ -55,13 +55,21 @@ class ComposerTestCase extends TestCase
     {
         parent::tearDown();
         chdir($this->oldWorkingDirectory);
-        if ($this->testWorkingDir && !$this->hasFailed()) {
+        if ($this->testWorkingDir && $this->hasPassed()) {
             $fs = new Filesystem();
             $fs->remove($this->testWorkingDir);
         }
         unset($this->oldWorkingDirectory, $this->testWorkingDir);
     }
 
+    /**
+     * @return bool
+     */
+    protected function hasPassed()
+    {
+        return $this->getStatus() === \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
+    }
+
     /**
      * @return string
      */
-- 
GitLab