<?php
-/**
- * @file
- * Contains \DrupalComposer\DrupalScaffold\Tests\PluginTest.
- */
-
namespace DrupalComposer\DrupalScaffold\Tests;
use Composer\Util\Filesystem;
+use PHPUnit\Framework\TestCase;
/**
* Tests composer plugin functionality.
*/
-class PluginTest extends \PHPUnit_Framework_TestCase {
+class PluginTest extends TestCase {
/**
* @var \Composer\Util\Filesystem
protected $tmpReleaseTag;
/**
- * SetUp test
+ * SetUp test.
*/
public function setUp() {
$this->rootDir = realpath(realpath(__DIR__ . '/..'));
}
/**
- * tearDown
+ * TearDown.
*
* @return void
*/
- public function tearDown()
- {
+ public function tearDown() {
$this->fs->removeDirectory($this->tmpDir);
$this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag));
}
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be automatically installed.');
$this->fs->remove($exampleScaffoldFile);
$this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.');
- $this->composer('drupal-scaffold');
- $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal-scaffold" command.');
+ $this->composer('drupal:scaffold');
+ $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal:scaffold" command.');
foreach (['8.0.1', '8.1.x-dev', '8.3.0', '8.5.x-dev'] as $version) {
// We touch a scaffold file, so we can check the file was modified after
// the scaffold update.
touch($exampleScaffoldFile);
$mtime_touched = filemtime($exampleScaffoldFile);
- // Requiring a newer version triggers "composer update"
- $this->composer('require --update-with-dependencies --prefer-dist --update-no-dev drupal/core:"' . $version .'"');
+ // Requiring a newer version triggers "composer update".
+ $this->composer('require --update-with-dependencies --prefer-dist --update-no-dev drupal/core:"' . $version . '"');
clearstatcache();
$mtime_after = filemtime($exampleScaffoldFile);
$this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')');
$this->assertFileNotExists($this->tmpDir . DIRECTORY_SEPARATOR . '.eslintrc.json');
$this->assertFileNotExists($this->tmpDir . DIRECTORY_SEPARATOR . '.ht.router.php');
break;
+
case '8.3.0':
// Note we don't clean up .eslintrc file.
$this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . '.eslintrc');
$this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . '.eslintrc.json');
$this->assertFileNotExists($this->tmpDir . DIRECTORY_SEPARATOR . '.ht.router.php');
break;
+
case '8.5.x-dev':
$this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . '.eslintrc');
$this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . '.eslintrc.json');
}
}
- // We touch a scaffold file, so we can check the file was modified after
- // the custom commandscaffold update.
- touch($exampleScaffoldFile);
- clearstatcache();
- $mtime_touched = filemtime($exampleScaffoldFile);
- $this->composer('drupal-scaffold');
- clearstatcache();
- $mtime_after = filemtime($exampleScaffoldFile);
- $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by custom command.');
+ // We touch a scaffold file, so we can check the file was modified by the
+ // custom command.
+ file_put_contents($exampleScaffoldFile, 1);
+ $this->composer('drupal:scaffold');
+ $this->assertNotEquals(file_get_contents($exampleScaffoldFile), 1, 'Scaffold file was modified by custom command.');
}
/**
array(
'type' => 'vcs',
'url' => $this->rootDir,
- )
+ ),
),
'require' => array(
'drupal-composer/drupal-scaffold' => $this->tmpReleaseTag,
'composer/installers' => '^1.0.20',
'drupal/core' => '8.0.0',
),
- 'scripts' => array(
- 'drupal-scaffold' => 'DrupalComposer\\DrupalScaffold\\Plugin::scaffold'
- ),
'minimum-stability' => 'dev',
);
}
* Wrapper for the composer command.
*
* @param string $command
- * Composer command name, arguments and/or options
+ * Composer command name, arguments and/or options.
*/
protected function composer($command) {
chdir($this->tmpDir);
if (is_dir($directory)) {
$this->fs->removeDirectory($directory);
}
- mkdir($directory, 0777, true);
+ mkdir($directory, 0777, TRUE);
}
+
}