Added Laravel project

This commit is contained in:
2017-09-17 00:35:10 +02:00
parent a3c19304d5
commit ecf605b8f5
6246 changed files with 682270 additions and 2 deletions

View File

@@ -0,0 +1,7 @@
/.idea
/.php_cs.cache
/composer.lock
/src/autoload.php
/tools
/vendor

67
Laravel/vendor/phar-io/version/.php_cs vendored Normal file
View File

@@ -0,0 +1,67 @@
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->files()
->in('src')
->in('tests')
->name('*.php');
return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->level(\Symfony\CS\FixerInterface::NONE_LEVEL)
->fixers(
array(
'align_double_arrow',
'align_equals',
'concat_with_spaces',
'duplicate_semicolon',
'elseif',
'empty_return',
'encoding',
'eof_ending',
'extra_empty_lines',
'function_call_space',
'function_declaration',
'indentation',
'join_function',
'line_after_namespace',
'linefeed',
'list_commas',
'lowercase_constants',
'lowercase_keywords',
'method_argument_space',
'multiple_use',
'namespace_no_leading_whitespace',
'no_blank_lines_after_class_opening',
'no_empty_lines_after_phpdocs',
'parenthesis',
'php_closing_tag',
'phpdoc_indent',
'phpdoc_no_access',
'phpdoc_no_empty_return',
'phpdoc_no_package',
'phpdoc_params',
'phpdoc_scalar',
'phpdoc_separation',
'phpdoc_to_comment',
'phpdoc_trim',
'phpdoc_types',
'phpdoc_var_without_name',
'remove_lines_between_uses',
'return',
'self_accessor',
'short_array_syntax',
'short_tag',
'single_line_after_imports',
'single_quote',
'spaces_before_semicolon',
'spaces_cast',
'ternary_spaces',
'trailing_spaces',
'trim_array_spaces',
'unused_use',
'visibility',
'whitespacy_lines'
)
)
->finder($finder);

View File

@@ -0,0 +1,33 @@
os:
- linux
language: php
before_install:
- wget https://phar.io/releases/phive.phar
- wget https://phar.io/releases/phive.phar.asc
- gpg --keyserver hkps.pool.sks-keyservers.net --recv-keys 0x9B2D5D79
- gpg --verify phive.phar.asc phive.phar
- chmod +x phive.phar
- sudo mv phive.phar /usr/bin/phive
install:
- ant setup
script: ./tools/phpunit
php:
- 5.6
- 7.0
- 7.1
- 7.0snapshot
- 7.1snapshot
- master
matrix:
allow_failures:
- php: master
fast_finish: true
notifications:
email: false

31
Laravel/vendor/phar-io/version/LICENSE vendored Normal file
View File

@@ -0,0 +1,31 @@
phar-io/version
Copyright (c) 2016-2017 Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de> and contributors
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Arne Blankerts nor the names of contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

View File

@@ -0,0 +1,16 @@
# Version
Library for handling version information and constraints
[![Build Status](https://travis-ci.org/phar-io/version.svg?branch=master)](https://travis-ci.org/phar-io/version)
## Installation
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
composer require phar-io/version
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev phar-io/version

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="version" default="setup">
<target name="setup" depends="clean,install-tools,generate-autoloader"/>
<target name="clean" unless="clean.done" description="Cleanup build artifacts">
<delete dir="${basedir}/tools"/>
<delete dir="${basedir}/vendor"/>
<delete file="${basedir}/src/autoload.php"/>
<property name="clean.done" value="true"/>
</target>
<target name="prepare" unless="prepare.done" depends="clean" description="Prepare for build">
<property name="prepare.done" value="true"/>
</target>
<target name="-tools-installed">
<available file="${basedir}/tools" property="tools-installed" type="dir"/>
</target>
<target name="install-tools" unless="tools-installed" depends="-tools-installed" description="Install tools with Phive">
<exec executable="phive" taskname="phive">
<arg value="install"/>
<arg value="--trust-gpg-keys" />
<arg value="4AA394086372C20A,2A8299CE842DD38C" />
</exec>
</target>
<target name="generate-autoloader" depends="install-tools" description="Generate autoloader using PHPAB">
<exec executable="${basedir}/tools/phpab" taskname="phpab">
<arg value="--output"/>
<arg path="${basedir}/src/autoload.php"/>
<arg path="${basedir}/src"/>
</exec>
</target>
<target name="test" depends="generate-autoloader" description="Run tests">
<exec executable="${basedir}/tools/phpunit" taskname="phpunit"/>
</target>
</project>

View File

@@ -0,0 +1,34 @@
{
"name": "phar-io/version",
"description": "Library for handling version information and constraints",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Arne Blankerts",
"email": "arne@blankerts.de",
"role": "Developer"
},
{
"name": "Sebastian Heuer",
"email": "sebastian@phpeople.de",
"role": "Developer"
},
{
"name": "Sebastian Bergmann",
"email": "sebastian@phpunit.de",
"role": "Developer"
}
],
"support": {
"issues": "https://github.com/phar-io/version/issues"
},
"require": {
"php": "^5.6 || ^7.0"
},
"autoload": {
"classmap": [
"src/"
]
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="^5.7.5" installed="5.7.5" location="./tools/phpunit"/>
<phar name="phpab" version="^1.23.0" installed="1.23.0" location="./tools/phpab"/>
</phive>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.7/phpunit.xsd"
bootstrap="src/autoload.php"
backupGlobals="false"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite>
<directory suffix="Test.php">tests</directory>
</testsuite>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>

View File

@@ -0,0 +1,32 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
abstract class AbstractVersionConstraint implements VersionConstraint {
/**
* @var string
*/
private $originalValue = '';
/**
* @param string $originalValue
*/
public function __construct($originalValue) {
$this->originalValue = $originalValue;
}
/**
* @return string
*/
public function asString() {
return $this->originalValue;
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class AndVersionConstraintGroup extends AbstractVersionConstraint {
/**
* @var VersionConstraint[]
*/
private $constraints = [];
/**
* @param string $originalValue
* @param VersionConstraint[] $constraints
*/
public function __construct($originalValue, array $constraints) {
parent::__construct($originalValue);
$this->constraints = $constraints;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
foreach ($this->constraints as $constraint) {
if (!$constraint->complies($version)) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class AnyVersionConstraint implements VersionConstraint {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return true;
}
/**
* @return string
*/
public function asString() {
return '*';
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class ExactVersionConstraint extends AbstractVersionConstraint {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $this->asString() == $version->getVersionString();
}
}

View File

@@ -0,0 +1,14 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
interface Exception {
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class GreaterThanOrEqualToVersionConstraint extends AbstractVersionConstraint {
/**
* @var Version
*/
private $minimalVersion;
/**
* @param string $originalValue
* @param Version $minimalVersion
*/
public function __construct($originalValue, Version $minimalVersion) {
parent::__construct($originalValue);
$this->minimalVersion = $minimalVersion;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $version->getVersionString() == $this->minimalVersion->getVersionString() ||
$version->isGreaterThan($this->minimalVersion);
}
}

View File

@@ -0,0 +1,5 @@
<?php
namespace PharIo\Version;
class InvalidVersionException extends \InvalidArgumentException implements Exception {
}

View File

@@ -0,0 +1,43 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class OrVersionConstraintGroup extends AbstractVersionConstraint {
/**
* @var VersionConstraint[]
*/
private $constraints = [];
/**
* @param string $originalValue
* @param VersionConstraint[] $constraints
*/
public function __construct($originalValue, array $constraints) {
parent::__construct($originalValue);
$this->constraints = $constraints;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
foreach ($this->constraints as $constraint) {
if ($constraint->complies($version)) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace PharIo\Version;
class PreReleaseSuffix
{
/**
* @var string
*/
private $value;
/**
* @var int
*/
private $number;
/**
* @param string $value
* @param int|null $number
*/
public function __construct($value, $number = null)
{
$this->value = $value;
$this->number = $number;
}
/**
* @return string
*/
public function getValue()
{
return $this->value;
}
/**
* @return int|null
*/
public function getNumber()
{
return $this->number;
}
}

View File

@@ -0,0 +1,48 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class SpecificMajorAndMinorVersionConstraint extends AbstractVersionConstraint {
/**
* @var int
*/
private $major = 0;
/**
* @var int
*/
private $minor = 0;
/**
* @param string $originalValue
* @param int $major
* @param int $minor
*/
public function __construct($originalValue, $major, $minor) {
parent::__construct($originalValue);
$this->major = $major;
$this->minor = $minor;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
if ($version->getMajor()->getValue() != $this->major) {
return false;
}
return $version->getMinor()->getValue() == $this->minor;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class SpecificMajorVersionConstraint extends AbstractVersionConstraint {
/**
* @var int
*/
private $major = 0;
/**
* @param string $originalValue
* @param int $major
*/
public function __construct($originalValue, $major) {
parent::__construct($originalValue);
$this->major = $major;
}
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version) {
return $version->getMajor()->getValue() == $this->major;
}
}

View File

@@ -0,0 +1,14 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
final class UnsupportedVersionConstraintException extends \RuntimeException implements Exception {
}

View File

@@ -0,0 +1,162 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class Version {
/**
* @var VersionNumber
*/
private $major;
/**
* @var VersionNumber
*/
private $minor;
/**
* @var VersionNumber
*/
private $patch;
/**
* @var PreReleaseSuffix
*/
private $preReleaseSuffix;
/**
* @var string
*/
private $versionString = '';
/**
* @param string $versionString
*/
public function __construct($versionString) {
$this->ensureVersionStringIsValid($versionString);
$this->versionString = $versionString;
}
/**
* @param array $matches
*/
private function parseVersion(array $matches) {
$this->major = new VersionNumber($matches['Major']);
$this->minor = new VersionNumber($matches['Minor']);
$this->patch = isset($matches['Patch']) ? new VersionNumber($matches['Patch']) : new VersionNumber(null);
if (isset($matches['ReleaseType'])) {
$preReleaseNumber = isset($matches['ReleaseTypeCount']) ? (int) $matches['ReleaseTypeCount'] : null;
$this->preReleaseSuffix = new PreReleaseSuffix($matches['ReleaseType'], $preReleaseNumber);
}
}
/**
* @return PreReleaseSuffix
*/
public function getPreReleaseSuffix()
{
return $this->preReleaseSuffix;
}
/**
* @return string
*/
public function getVersionString() {
return $this->versionString;
}
/**
* @param Version $version
*
* @return bool
*/
public function isGreaterThan(Version $version) {
if ($version->getMajor()->getValue() > $this->getMajor()->getValue()) {
return false;
}
if ($version->getMajor()->getValue() < $this->getMajor()->getValue()) {
return true;
}
if ($version->getMinor()->getValue() > $this->getMinor()->getValue()) {
return false;
}
if ($version->getMinor()->getValue() < $this->getMinor()->getValue()) {
return true;
}
if ($version->getPatch()->getValue() >= $this->getPatch()->getValue()) {
return false;
}
if ($version->getPatch()->getValue() < $this->getPatch()->getValue()) {
return true;
}
return false;
}
/**
* @return VersionNumber
*/
public function getMajor() {
return $this->major;
}
/**
* @return VersionNumber
*/
public function getMinor() {
return $this->minor;
}
/**
* @return VersionNumber
*/
public function getPatch() {
return $this->patch;
}
/**
* @param string $version
*
* @throws InvalidVersionException
*/
private function ensureVersionStringIsValid($version) {
$regex = '/^v?
(?<Major>(0|(?:[1-9][0-9]*)))
\\.
(?<Minor>(0|(?:[1-9][0-9]*)))
(\\.
(?<Patch>(0|(?:[1-9][0-9]*)))
)?
(?:
-
(?<ReleaseType>(?:(dev|beta|b|RC|alpha|a|patch|p)))
(?:
(?<ReleaseTypeCount>[0-9])
)?
)?
$/x';
if (preg_match($regex, $version, $matches) !== 1) {
throw new InvalidVersionException(
sprintf("Version string '%s' does not follow SemVer semantics", $version)
);
}
$this->parseVersion($matches);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
interface VersionConstraint {
/**
* @param Version $version
*
* @return bool
*/
public function complies(Version $version);
/**
* @return string
*/
public function asString();
}

View File

@@ -0,0 +1,122 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class VersionConstraintParser {
/**
* @param string $value
*
* @return VersionConstraint
*
* @throws UnsupportedVersionConstraintException
*/
public function parse($value) {
if (strpos($value, '||') !== false) {
return $this->handleOrGroup($value);
}
if (!preg_match('/^[\^~\*]?[\d.\*]+$/', $value)) {
throw new UnsupportedVersionConstraintException(
sprintf('Version constraint %s is not supported.', $value)
);
}
switch ($value[0]) {
case '~':
return $this->handleTildeOperator($value);
case '^':
return $this->handleCaretOperator($value);
}
$version = new VersionConstraintValue($value);
if ($version->getMajor()->isAny()) {
return new AnyVersionConstraint();
}
if ($version->getMinor()->isAny()) {
return new SpecificMajorVersionConstraint(
$value,
$version->getMajor()->getValue()
);
}
if ($version->getPatch()->isAny()) {
return new SpecificMajorAndMinorVersionConstraint(
$value,
$version->getMajor()->getValue(),
$version->getMinor()->getValue()
);
}
return new ExactVersionConstraint($value);
}
/**
* @param $value
*
* @return OrVersionConstraintGroup
*/
private function handleOrGroup($value) {
$constraints = [];
foreach (explode('||', $value) as $groupSegment) {
$constraints[] = $this->parse(trim($groupSegment));
}
return new OrVersionConstraintGroup($value, $constraints);
}
/**
* @param string $value
*
* @return AndVersionConstraintGroup
*/
private function handleTildeOperator($value) {
$version = new Version(substr($value, 1));
$constraints = [
new GreaterThanOrEqualToVersionConstraint($value, $version)
];
if ($version->getPatch()->isAny()) {
$constraints[] = new SpecificMajorVersionConstraint(
$value,
$version->getMajor()->getValue()
);
} else {
$constraints[] = new SpecificMajorAndMinorVersionConstraint(
$value,
$version->getMajor()->getValue(),
$version->getMinor()->getValue()
);
}
return new AndVersionConstraintGroup($value, $constraints);
}
/**
* @param string $value
*
* @return AndVersionConstraintGroup
*/
private function handleCaretOperator($value) {
$version = new Version(substr($value, 1));
return new AndVersionConstraintGroup(
$value,
[
new GreaterThanOrEqualToVersionConstraint($value, $version),
new SpecificMajorVersionConstraint($value, $version->getMajor()->getValue())
]
);
}
}

View File

@@ -0,0 +1,123 @@
<?php
namespace PharIo\Version;
class VersionConstraintValue
{
/**
* @var VersionNumber
*/
private $major;
/**
* @var VersionNumber
*/
private $minor;
/**
* @var VersionNumber
*/
private $patch;
/**
* @var string
*/
private $label = '';
/**
* @var string
*/
private $buildMetaData = '';
/**
* @var string
*/
private $versionString = '';
/**
* @param string $versionString
*/
public function __construct($versionString) {
$this->versionString = $versionString;
$this->parseVersion($versionString);
}
/**
* @param $versionString
*/
private function parseVersion($versionString) {
$this->extractBuildMetaData($versionString);
$this->extractLabel($versionString);
$versionSegments = explode('.', $versionString);
$this->major = new VersionNumber($versionSegments[0]);
$minorValue = isset($versionSegments[1]) ? $versionSegments[1] : null;
$patchValue = isset($versionSegments[2]) ? $versionSegments[2] : null;
$this->minor = new VersionNumber($minorValue);
$this->patch = new VersionNumber($patchValue);
}
/**
* @param string $versionString
*/
private function extractBuildMetaData(&$versionString) {
if (preg_match('/\+(.*)/', $versionString, $matches) == 1) {
$this->buildMetaData = $matches[1];
$versionString = str_replace($matches[0], '', $versionString);
}
}
/**
* @param string $versionString
*/
private function extractLabel(&$versionString) {
if (preg_match('/\-(.*)/', $versionString, $matches) == 1) {
$this->label = $matches[1];
$versionString = str_replace($matches[0], '', $versionString);
}
}
/**
* @return string
*/
public function getLabel() {
return $this->label;
}
/**
* @return string
*/
public function getBuildMetaData() {
return $this->buildMetaData;
}
/**
* @return string
*/
public function getVersionString() {
return $this->versionString;
}
/**
* @return VersionNumber
*/
public function getMajor() {
return $this->major;
}
/**
* @return VersionNumber
*/
public function getMinor() {
return $this->minor;
}
/**
* @return VersionNumber
*/
public function getPatch() {
return $this->patch;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
class VersionNumber {
/**
* @var int
*/
private $value;
/**
* @param mixed $value
*/
public function __construct($value) {
if (is_numeric($value)) {
$this->value = $value;
}
}
/**
* @return bool
*/
public function isAny() {
return $this->value === null;
}
/**
* @return int
*/
public function getValue() {
return $this->value;
}
}

View File

@@ -0,0 +1,125 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Version\VersionConstraintParser
*/
class VersionConstraintParserTest extends TestCase {
/**
* @dataProvider versionStringProvider
*
* @param string $versionString
* @param VersionConstraint $expectedConstraint
*/
public function testReturnsExpectedConstraint($versionString, VersionConstraint $expectedConstraint) {
$parser = new VersionConstraintParser;
$this->assertEquals($expectedConstraint, $parser->parse($versionString));
}
/**
* @dataProvider unsupportedVersionStringProvider
*
* @param string $versionString
*/
public function testThrowsExceptionIfVersionStringIsNotSupported($versionString) {
$parser = new VersionConstraintParser;
$this->expectException(UnsupportedVersionConstraintException::class);
$parser->parse($versionString);
}
/**
* @return array
*/
public function versionStringProvider() {
return [
['1.0.2', new ExactVersionConstraint('1.0.2')],
[
'~4.6',
new AndVersionConstraintGroup(
'~4.6',
[
new GreaterThanOrEqualToVersionConstraint('~4.6', new Version('4.6')),
new SpecificMajorVersionConstraint('~4.6', 4)
]
)
],
[
'~4.6.2',
new AndVersionConstraintGroup(
'~4.6.2',
[
new GreaterThanOrEqualToVersionConstraint('~4.6.2', new Version('4.6.2')),
new SpecificMajorAndMinorVersionConstraint('~4.6.2', 4, 6)
]
)
],
[
'^2.6.1',
new AndVersionConstraintGroup(
'^2.6.1',
[
new GreaterThanOrEqualToVersionConstraint('^2.6.1', new Version('2.6.1')),
new SpecificMajorVersionConstraint('^2.6.1', 2)
]
)
],
['5.1.*', new SpecificMajorAndMinorVersionConstraint('5.1.*', 5, 1)],
['5.*', new SpecificMajorVersionConstraint('5.*', 5)],
['*', new AnyVersionConstraint()],
[
'1.0.2 || 1.0.5',
new OrVersionConstraintGroup(
'1.0.2 || 1.0.5',
[
new ExactVersionConstraint('1.0.2'),
new ExactVersionConstraint('1.0.5')
]
)
],
[
'^5.6 || ^7.0',
new OrVersionConstraintGroup(
'^5.6 || ^7.0',
[
new AndVersionConstraintGroup(
'^5.6', [
new GreaterThanOrEqualToVersionConstraint('^5.6', new Version('5.6')),
new SpecificMajorVersionConstraint('^5.6', 5)
]
),
new AndVersionConstraintGroup(
'^7.0', [
new GreaterThanOrEqualToVersionConstraint('^7.0', new Version('7.0')),
new SpecificMajorVersionConstraint('^7.0', 7)
]
)
]
)
]
];
}
public function unsupportedVersionStringProvider() {
return [
['foo'],
['+1.0.2'],
['>=2.0'],
['^5.6 || >= 7.0'],
['2.0 || foo']
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Version\AbstractVersionConstraint
*/
class AbstractVersionConstraintTest extends TestCase {
public function testAsString() {
/** @var AbstractVersionConstraint|\PHPUnit_Framework_MockObject_MockObject $constraint */
$constraint = $this->getMockForAbstractClass(AbstractVersionConstraint::class, ['foo']);
$this->assertSame('foo', $constraint->asString());
}
}

View File

@@ -0,0 +1,52 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\AndVersionConstraintGroup
*/
class AndVersionConstraintGroupTest extends TestCase {
public function testReturnsFalseIfOneConstraintReturnsFalse() {
$firstConstraint = $this->createMock(VersionConstraint::class);
$secondConstraint = $this->createMock(VersionConstraint::class);
$firstConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(true));
$secondConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(false));
$group = new AndVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]);
$this->assertFalse($group->complies(new Version('1.0.0')));
}
public function testReturnsTrueIfAllConstraintsReturnsTrue() {
$firstConstraint = $this->createMock(VersionConstraint::class);
$secondConstraint = $this->createMock(VersionConstraint::class);
$firstConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(true));
$secondConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(true));
$group = new AndVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]);
$this->assertTrue($group->complies(new Version('1.0.0')));
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\AnyVersionConstraint
*/
class AnyVersionConstraintTest extends TestCase {
public function versionProvider() {
return [
[new Version('1.0.2')],
[new Version('4.8')],
[new Version('0.1.1-dev')]
];
}
/**
* @dataProvider versionProvider
*
* @param Version $version
*/
public function testReturnsTrue(Version $version) {
$constraint = new AnyVersionConstraint;
$this->assertTrue($constraint->complies($version));
}
public function testAsString() {
$this->assertSame('*', (new AnyVersionConstraint())->asString());
}
}

View File

@@ -0,0 +1,58 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\ExactVersionConstraint
*/
class ExactVersionConstraintTest extends TestCase {
public function compliantVersionProvider() {
return [
['1.0.2', new Version('1.0.2')],
['4.8.9', new Version('4.8.9')],
['4.8', new Version('4.8')],
];
}
public function nonCompliantVersionProvider() {
return [
['1.0.2', new Version('1.0.3')],
['4.8.9', new Version('4.7.9')],
['4.8', new Version('4.8.5')],
];
}
/**
* @dataProvider compliantVersionProvider
*
* @param string $constraintValue
* @param Version $version
*/
public function testReturnsTrueForCompliantVersion($constraintValue, Version $version) {
$constraint = new ExactVersionConstraint($constraintValue);
$this->assertTrue($constraint->complies($version));
}
/**
* @dataProvider nonCompliantVersionProvider
*
* @param string $constraintValue
* @param Version $version
*/
public function testReturnsFalseForNonCompliantVersion($constraintValue, Version $version) {
$constraint = new ExactVersionConstraint($constraintValue);
$this->assertFalse($constraint->complies($version));
}
}

View File

@@ -0,0 +1,47 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\GreaterThanOrEqualToVersionConstraint
*/
class GreaterThanOrEqualToVersionConstraintTest extends TestCase {
public function versionProvider() {
return [
// compliant versions
[new Version('1.0.2'), new Version('1.0.2'), true],
[new Version('1.0.2'), new Version('1.0.3'), true],
[new Version('1.0.2'), new Version('1.1.1'), true],
[new Version('1.0.2'), new Version('2.0.0'), true],
[new Version('1.0.2'), new Version('1.0.3'), true],
// non-compliant versions
[new Version('1.0.2'), new Version('1.0.1'), false],
[new Version('1.9.8'), new Version('0.9.9'), false],
[new Version('2.3.1'), new Version('2.2.3'), false],
[new Version('3.0.2'), new Version('2.9.9'), false],
];
}
/**
* @dataProvider versionProvider
*
* @param Version $constraintVersion
* @param Version $version
* @param bool $expectedResult
*/
public function testReturnsTrueForCompliantVersions(Version $constraintVersion, Version $version, $expectedResult) {
$constraint = new GreaterThanOrEqualToVersionConstraint('foo', $constraintVersion);
$this->assertSame($expectedResult, $constraint->complies($version));
}
}

View File

@@ -0,0 +1,65 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\OrVersionConstraintGroup
*/
class OrVersionConstraintGroupTest extends TestCase {
public function testReturnsTrueIfOneConstraintReturnsFalse() {
$firstConstraint = $this->createMock(VersionConstraint::class);
$secondConstraint = $this->createMock(VersionConstraint::class);
$firstConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(false));
$secondConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(true));
$group = new OrVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]);
$this->assertTrue($group->complies(new Version('1.0.0')));
}
public function testReturnsTrueIfAllConstraintsReturnsTrue() {
$firstConstraint = $this->createMock(VersionConstraint::class);
$secondConstraint = $this->createMock(VersionConstraint::class);
$firstConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(true));
$group = new OrVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]);
$this->assertTrue($group->complies(new Version('1.0.0')));
}
public function testReturnsFalseIfAllConstraintsReturnsFalse() {
$firstConstraint = $this->createMock(VersionConstraint::class);
$secondConstraint = $this->createMock(VersionConstraint::class);
$firstConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(false));
$secondConstraint->expects($this->once())
->method('complies')
->will($this->returnValue(false));
$group = new OrVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]);
$this->assertFalse($group->complies(new Version('1.0.0')));
}
}

View File

@@ -0,0 +1,45 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\SpecificMajorAndMinorVersionConstraint
*/
class SpecificMajorAndMinorVersionConstraintTest extends TestCase {
public function versionProvider() {
return [
// compliant versions
[1, 0, new Version('1.0.2'), true],
[1, 0, new Version('1.0.3'), true],
[1, 1, new Version('1.1.1'), true],
// non-compliant versions
[2, 9, new Version('0.9.9'), false],
[3, 2, new Version('2.2.3'), false],
[2, 8, new Version('2.9.9'), false],
];
}
/**
* @dataProvider versionProvider
*
* @param int $major
* @param int $minor
* @param Version $version
* @param bool $expectedResult
*/
public function testReturnsTrueForCompliantVersions($major, $minor, Version $version, $expectedResult) {
$constraint = new SpecificMajorAndMinorVersionConstraint('foo', $major, $minor);
$this->assertSame($expectedResult, $constraint->complies($version));
}
}

View File

@@ -0,0 +1,44 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers PharIo\Version\SpecificMajorVersionConstraint
*/
class SpecificMajorVersionConstraintTest extends TestCase {
public function versionProvider() {
return [
// compliant versions
[1, new Version('1.0.2'), true],
[1, new Version('1.0.3'), true],
[1, new Version('1.1.1'), true],
// non-compliant versions
[2, new Version('0.9.9'), false],
[3, new Version('2.2.3'), false],
[3, new Version('2.9.9'), false],
];
}
/**
* @dataProvider versionProvider
*
* @param int $major
* @param Version $version
* @param bool $expectedResult
*/
public function testReturnsTrueForCompliantVersions($major, Version $version, $expectedResult) {
$constraint = new SpecificMajorVersionConstraint('foo', $major);
$this->assertSame($expectedResult, $constraint->complies($version));
}
}

View File

@@ -0,0 +1,104 @@
<?php
/*
* This file is part of PharIo\Version.
*
* (c) Arne Blankerts <arne@blankerts.de>, Sebastian Heuer <sebastian@phpeople.de>, Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PharIo\Version;
use PHPUnit\Framework\TestCase;
/**
* @covers \PharIo\Version\Version
*/
class VersionTest extends TestCase {
/**
* @dataProvider versionProvider
*
* @param string $versionString
* @param string $expectedMajor
* @param string $expectedMinor
* @param string $expectedPatch
* @param string $expectedPreReleaseValue
* @param int $expectedReleaseCount
*/
public function testParsesVersionNumbers($versionString, $expectedMajor, $expectedMinor, $expectedPatch, $expectedPreReleaseValue = '', $expectedReleaseCount = 0) {
$version = new Version($versionString);
$this->assertSame($expectedMajor, $version->getMajor()->getValue());
$this->assertSame($expectedMinor, $version->getMinor()->getValue());
$this->assertSame($expectedPatch, $version->getPatch()->getValue());
if ($expectedPreReleaseValue !== '') {
$this->assertSame($expectedPreReleaseValue, $version->getPreReleaseSuffix()->getValue());
}
if ($expectedReleaseCount !== 0) {
$this->assertSame($expectedReleaseCount, $version->getPreReleaseSuffix()->getNumber());
}
$this->assertSame($versionString, $version->getVersionString());
}
public function versionProvider() {
return [
['0.0.1', '0', '0', '1'],
['0.1.2', '0', '1', '2'],
['1.0.0-alpha', '1', '0', '0', 'alpha'],
['3.4.12-dev3', '3', '4', '12', 'dev', 3],
];
}
/**
* @dataProvider versionGreaterThanProvider
*
* @param Version $versionA
* @param Version $versionB
* @param bool $expectedResult
*/
public function testIsGreaterThan(Version $versionA, Version $versionB, $expectedResult) {
$this->assertSame($expectedResult, $versionA->isGreaterThan($versionB));
}
/**
* @return array
*/
public function versionGreaterThanProvider() {
return [
[new Version('1.0.0'), new Version('1.0.1'), false],
[new Version('1.0.1'), new Version('1.0.0'), true],
[new Version('1.1.0'), new Version('1.0.1'), true],
[new Version('1.1.0'), new Version('2.0.1'), false],
[new Version('1.1.0'), new Version('1.1.0'), false],
[new Version('2.5.8'), new Version('1.6.8'), true],
[new Version('2.5.8'), new Version('2.6.8'), false],
[new Version('2.5.8'), new Version('3.1.2'), false],
];
}
/**
* @dataProvider invalidVersionStringProvider
*
* @param string $versionString
*/
public function testThrowsExceptionIfVersionStringDoesNotFollowSemVer($versionString)
{
$this->expectException(InvalidVersionException::class);
new Version($versionString);
}
/**
* @return array
*/
public function invalidVersionStringProvider()
{
return [
['foo'],
['0.0.1-dev+ABC', '0', '0', '1', 'dev', 'ABC'],
['1.0.0-x.7.z.92', '1', '0', '0', 'x.7.z.92']
];
}
}