Commit 7afeeebc authored by catch's avatar catch

Issue #2585165 by pwolanin, alexpott, tarekdj, geertvd, dawehner, greggles:...

Issue #2585165 by pwolanin, alexpott, tarekdj, geertvd, dawehner, greggles: Don't include vendor test code (especially mink) in the Drupal webroot
parent b0e82e58

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

......@@ -37,6 +37,8 @@
},
"scripts": {
"pre-autoload-dump": "Drupal\\Core\\Composer\\Composer::preAutoloadDump",
"post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess"
"post-autoload-dump": "Drupal\\Core\\Composer\\Composer::ensureHtaccess",
"post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup",
"post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup"
}
}
......@@ -9,6 +9,7 @@
use Drupal\Component\PhpStorage\FileStorage;
use Composer\Script\Event;
use Composer\Installer\PackageEvent;
/**
* Provides static functions for composer script events.
......@@ -17,6 +18,55 @@
*/
class Composer {
protected static $packageToCleanup = [
'behat/mink' => ['tests', 'driver-testsuite'],
'behat/mink-browserkit-driver' => ['tests'],
'behat/mink-goutte-driver' => ['tests'],
'doctrine/cache' => ['tests'],
'doctrine/collections' => ['tests'],
'doctrine/common' => ['tests'],
'doctrine/inflector' => ['tests'],
'doctrine/instantiator' => ['tests'],
'egulias/email-validator' => ['documentation', 'tests'],
'fabpot/goutte' => ['Goutte/Tests'],
'guzzlehttp/promises' => ['tests'],
'guzzlehttp/psr7' => ['tests'],
'masterminds/html5' => ['test'],
'mikey179/vfsStream' => ['src/test'],
'phpdocumentor/reflection-docblock' => ['tests'],
'phpunit/php-code-coverage' => ['tests'],
'phpunit/php-timer' => ['tests'],
'phpunit/php-token-stream' => ['tests'],
'phpunit/phpunit' => ['tests'],
'phpunit/php-mock-objects' => ['tests'],
'sebastian/comparator' => ['tests'],
'sebastian/diff' => ['tests'],
'sebastian/environment' => ['tests'],
'sebastian/exporter' => ['tests'],
'sebastian/global-state' => ['tests'],
'sebastian/recursion-context' => ['tests'],
'stack/builder' => ['tests'],
'symfony/browser-kit' => ['Tests'],
'symfony/class-loader' => ['Tests'],
'symfony/console' => ['Tests'],
'symfony/css-selector' => ['Tests'],
'symfony/debug' => ['Tests'],
'symfony/dependency-injection' => ['Tests'],
'symfony/dom-crawler' => ['Tests'],
'symfony/event-dispatcher' => ['Tests'],
'symfony/http-foundation' => ['Tests'],
'symfony/http-kernel' => ['Tests'],
'symfony/process' => ['Tests'],
'symfony/psr-http-message-bridge' => ['Tests'],
'symfony/routing' => ['Tests'],
'symfony/serializer' => ['Tests'],
'symfony/translation' => ['Tests'],
'symfony/validator' => ['Tests'],
'symfony/yaml' => ['Tests'],
'symfony-cmf/routing' => ['Test', 'Tests'],
'twig/twig' => ['doc', 'ext', 'test'],
];
/**
* Add vendor classes to composers static classmap.
*/
......@@ -70,4 +120,90 @@ public static function ensureHtaccess(Event $event) {
}
}
/**
* Remove possibly problematic test files from vendored projects.
*
* @param \Composer\Script\Event $event
*/
public static function vendorTestCodeCleanup(PackageEvent $event) {
$vendor_dir = $event->getComposer()->getConfig()->get('vendor-dir');
$op = $event->getOperation();
if ($op->getJobType() == 'update') {
$package = $op->getTargetPackage();
}
else {
$package = $op->getPackage();
}
$package_key = static::findPackageKey($package->getName());
if ($package_key) {
foreach (static::$packageToCleanup[$package_key] as $path) {
$dir_to_remove = $vendor_dir . '/' . $package_key . '/' . $path;
if (is_dir($dir_to_remove)) {
if (!static::deleteRecursive($dir_to_remove)) {
throw new \RuntimeException(sprintf("Failure removing directory '%s' in package '%s'.", $path, $package->getPrettyName()));
}
}
else {
throw new \RuntimeException(sprintf("The directory '%s' in package '%s' does not exist.", $path, $package->getPrettyName()));
}
}
}
}
/**
* Find the array key for a given package name with a case-insensitive search.
*
* @param string $package_name
* The package name from composer. This is always already lower case.
*
* @return NULL|string
* The string key, or NULL if none was found.
*/
protected static function findPackageKey($package_name) {
$package_key = NULL;
// In most cases the package name is already used as the array key.
if (isset(static::$packageToCleanup[$package_name])) {
$package_key = $package_name;
}
else {
// Handle any mismatch in case between the package name and array key.
// For example, the array key 'mikey179/vfsStream' needs to be found
// when composer returns a package name of 'mikey179/vfsstream'.
foreach (static::$packageToCleanup as $key => $dirs) {
if (strtolower($key) === $package_name) {
$package_key = $key;
break;
}
}
}
return $package_key;
}
/**
* Helper method to remove directories and the files they contain.
*
* @param string $path
* The directory or file to remove. It must exist.
*
* @return bool
* TRUE on success or FALSE on failure.
*/
protected static function deleteRecursive($path) {
if (is_file($path) || is_link($path)) {
return unlink($path);
}
$success = TRUE;
$dir = dir($path);
while (($entry = $dir->read()) !== FALSE) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entry_path = $path . '/' . $entry;
$success = static::deleteRecursive($entry_path) && $success;
}
$dir->close();
return rmdir($path) && $success;
}
}
File mode changed from 100755 to 100644
<?php
namespace Behat\Mink\Tests\Driver;
use Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\HttpKernel\Client;
class BrowserKitConfig extends AbstractConfig
{
public static function getInstance()
{
return new self();
}
/**
* {@inheritdoc}
*/
public function createDriver()
{
$client = new Client(require(__DIR__.'/app.php'));
return new BrowserKitDriver($client);
}
/**
* {@inheritdoc}
*/
public function getWebFixturesUrl()
{
return 'http://localhost';
}
protected function supportsJs()
{
return false;
}
}
<?php
namespace Behat\Mink\Tests\Driver\Custom;
use Behat\Mink\Driver\BrowserKitDriver;
use Behat\Mink\Session;
use Symfony\Component\HttpKernel\Client;
/**
* @group functional
*/
class BaseUrlTest extends \PHPUnit_Framework_TestCase
{
public function testBaseUrl()