Skip to content

Commit

Permalink
Allow exact versions with 3 or 4 digits (#3)
Browse files Browse the repository at this point in the history
* Allow exact versions with 3 or 4 digits

ACF PRO are sometimes released as 4 digit version numbers (e.g.
5.3.8.1). The validateVersion regex needs to be updated to account for
that scenario as well.

Fixes #2

* Update README to reflect new valid versions
  • Loading branch information
PhilippBaschke committed May 19, 2016
1 parent 98662f8 commit 045980f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ It reads your :key: ACF PRO key from the **environment** or a **.env file**.
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",
"version": "*.*.*",
"version": "*.*.*(.*)",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
Expand All @@ -35,7 +35,7 @@ It reads your :key: ACF PRO key from the **environment** or a **.env file**.
}
}
```
Replace `"version": "*.*.*"` with your desired version.
Replace `"version": "*.*.*(.*)"` with your desired version.

**2. Make your ACF PRO key available**

Expand Down
10 changes: 5 additions & 5 deletions src/ACFProInstaller/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ protected function getPackageFromOperation(OperationInterface $operation)
}

/**
* Validate that the version is an exact major.minor.patch version
* Validate that the version is an exact major.minor.patch.optional version
*
* The url to download the code for the package only works with exact
* version numbers with 3 digits: e.g. 1.2.3
* version numbers with 3 or 4 digits: e.g. 1.2.3 or 1.2.3.4
*
* @access protected
* @param string $version The version that should be validated
Expand All @@ -184,12 +184,12 @@ protected function validateVersion($version)
{
// \A = start of string, \Z = end of string
// See: http://stackoverflow.com/a/34994075
$major_minor_patch = '/\A\d\.\d\.\d\Z/';
$major_minor_patch_optional = '/\A\d\.\d\.\d(?:\.\d)?\Z/';

if (!preg_match($major_minor_patch, $version)) {
if (!preg_match($major_minor_patch_optional, $version)) {

This comment has been minimized.

Copy link
@jamiechong

jamiechong Jul 19, 2016

Your regex is making version 5.3.10 fail. Needs to be able to handle more than single digits. See issue #4

throw new \UnexpectedValueException(
'The version constraint of ' . self::ACF_PRO_PACKAGE_NAME .
' should be exact (with 3 digits). ' .
' should be exact (with 3 or 4 digits). ' .
'Invalid version string "' . $version . '"'
);
}
Expand Down
21 changes: 13 additions & 8 deletions tests/ACFProInstaller/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function testDontAddVersionOnOtherPackages()
$plugin->addVersion($packageEvent);
}

public function testExactVersionPassesValidation()
protected function versionPassesValidationHelper($version)
{
// Make key available in the ENVIRONMENT
putenv(self::KEY_ENV_VARIABLE . '=KEY');
Expand All @@ -322,7 +322,7 @@ public function testExactVersionPassesValidation()
$package
->expects($this->once())
->method('getPrettyVersion')
->willReturn('1.2.3');
->willReturn($version);

$package
->expects($this->once())
Expand Down Expand Up @@ -369,13 +369,23 @@ public function testExactVersionPassesValidation()
$plugin->addVersion($packageEvent);
}

public function testExactVersionWith3DigitsPassesValidation()
{
$this->versionPassesValidationHelper('1.2.3');
}

public function testExactVersionWith4DigitsPassesValidation()
{
$this->versionPassesValidationHelper('1.2.3.4');
}

protected function versionFailsValidationHelper($version)
{
// Expect an Exception
$this->setExpectedException(
'UnexpectedValueException',
'The version constraint of ' . self::REPO_NAME .
' should be exact (with 3 digits). ' .
' should be exact (with 3 or 4 digits). ' .
'Invalid version string "' . $version . '"'
);

Expand Down Expand Up @@ -444,11 +454,6 @@ public function testExactVersionWith1DigitsFailsValidation()
$this->versionFailsValidationHelper('1');
}

public function testExactVersionWith4DigitsFailsValidation()
{
$this->versionFailsValidationHelper('1.2.3.4');
}

public function testDontAddVersionTwice()
{
// The version that should be required
Expand Down

0 comments on commit 045980f

Please sign in to comment.