Skip to content

Commit

Permalink
Fixes #17: Unable to determine Drupal core version.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Feb 22, 2019
1 parent 24e1c3c commit 14bcdcc
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/Composer/ComposerizeDrupalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ protected function determineDrupalCoreVersion()
{
if (file_exists($this->drupalRoot . "/core/lib/Drupal.php")) {
$bootstrap = file_get_contents($this->drupalRoot . "/core/lib/Drupal.php");
preg_match('|(const VERSION = \')(\d\.\d\.\d)\';|', $bootstrap, $matches);
/**
* Matches:
* const VERSION = '8.0.0';
* const VERSION = '8.0.0-beta1';
* const VERSION = '8.0.0-rc2';
* const VERSION = '8.5.11';
* const VERSION = '8.5.x-dev';
*/
preg_match('|(const VERSION = \')(\d\.\d\.((\d{1,}(-(beta|alpha|rc)[0-9])?)|(x-dev)))\';|', $bootstrap, $matches);
if (array_key_exists(2, $matches)) {
return $matches[2];
}
Expand Down
32 changes: 31 additions & 1 deletion tests/phpunit/ComposerizeDrupalCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,36 @@ public function setUp()

// @todo Test --drupal-root option.

/**
* @dataProvider providerTestDrupalCoreVersions
*/
public function testDrupalCoreVersions($drupal_core_version)
{
$this->sandboxManager->setDrupalVersion($drupal_core_version);
$this->sandbox = $this->sandboxManager->makeSandbox();
$this->sandbox = $this->sandbox . "/docroot";
$args = [];
$options = [ 'interactive' => false ];
$this->commandTester->execute($args, $options);
$this->assertCorrectFileGeneration('');
}

/**
* Provides values to testDrupalCoreVersions().
*
* @return array
* An array of values to test.
*/
public function providerTestDrupalCoreVersions()
{
return [
['8.6.0'],
['8.6.x-dev'],
// Invalid version.
['0.0.0'],
];
}

/**
* Tests that composer.json contents are valid.
*
Expand Down Expand Up @@ -133,7 +163,7 @@ protected function assertCorrectFileGeneration($relative_drupal_root)
$composer_json->require
);
$this->assertEquals(
"^" . $this->drupalVersion,
"^" . $this->sandboxManager->getDrupalVersion(),
$composer_json->require->{'drupal/core'}
);

Expand Down
23 changes: 18 additions & 5 deletions tests/phpunit/src/SandboxManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,32 @@ class SandboxManager
{
protected $tmp;

protected $drupalVersion;
protected $drupalVersion = "8.6.0";

/** @var string */
/**
* @param mixed $drupalVersion
*/
public function setDrupalVersion($drupalVersion) {
$this->drupalVersion = $drupalVersion;
}

/**
* @return mixed
*/
public function getDrupalVersion() {
return $this->drupalVersion;
}

/** @var string */
protected $composerizeDrupalPath;

/** @var Filesystem */
/** @var Filesystem */
protected $fs;

public function __construct($drupal_version)
public function __construct()
{
$this->fs = new Filesystem();
$this->composerizeDrupalPath = dirname(dirname(dirname(__DIR__)));
$this->drupalVersion = $drupal_version;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions tests/phpunit/src/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ abstract class TestBase extends \PHPUnit_Framework_TestCase
/** @var \Grasmash\ComposerConverter\Tests\SandboxManager */
protected $sandboxManager;

protected $drupalVersion;

/**
* {@inheritdoc}
*
Expand All @@ -32,9 +30,8 @@ abstract class TestBase extends \PHPUnit_Framework_TestCase
public function setUp()
{
parent::setUp();
$this->drupalVersion = '8.6.4';
$this->fs = new Filesystem();
$this->composerizeDrupalPath = dirname(dirname(dirname(__DIR__)));
$this->sandboxManager = new SandboxManager($this->drupalVersion);
$this->sandboxManager = new SandboxManager();
}
}

0 comments on commit 14bcdcc

Please sign in to comment.