diff --git a/.php_cs b/.php_cs index 36cc3fe3a..6f85c6a7b 100644 --- a/.php_cs +++ b/.php_cs @@ -9,7 +9,7 @@ For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; -$finder = Symfony\CS\Finder\DefaultFinder::create() +$finder = PhpCsFixer\Finder::create() ->files() ->name('*.php') ->in(__DIR__.'/src') @@ -17,21 +17,13 @@ $finder = Symfony\CS\Finder\DefaultFinder::create() ; /* fabpot/php-cs-fixer:^2.0-dev */ -return Symfony\CS\Config\Config::create() +return PhpCsFixer\Config::create() ->setRules(array( '@PSR2' => true, - 'duplicate_semicolon' => true, - 'extra_empty_lines' => true, 'header_comment' => array('header' => $header), 'include' => true, - 'long_array_syntax' => true, 'method_separation' => true, - 'multiline_array_trailing_comma' => true, - 'namespace_no_leading_whitespace' => true, 'no_blank_lines_after_class_opening' => true, - 'no_empty_lines_after_phpdocs' => true, - 'object_operator' => true, - 'operators_spaces' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_package' => true, @@ -39,17 +31,7 @@ return Symfony\CS\Config\Config::create() 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_trim' => true, - 'phpdoc_type_to_var' => true, - 'return' => true, - 'remove_leading_slash_use' => true, - 'remove_lines_between_uses' => true, - 'single_array_no_trailing_comma' => true, 'single_blank_line_before_namespace' => true, - 'spaces_cast' => true, - 'standardize_not_equal' => true, - 'ternary_spaces' => true, - 'unused_use' => true, - 'whitespacy_lines' => true, )) - ->finder($finder) + ->setFinder($finder) ; diff --git a/.travis.yml b/.travis.yml index 12bec6789..85521a446 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php -sudo: false - cache: directories: - $HOME/.composer/cache @@ -22,8 +20,7 @@ matrix: fast_finish: true before_script: - - rm -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini - composer install --no-interaction --no-progress --prefer-dist script: - - vendor/bin/phpunit + - vendor/bin/phpunit -d error_reporting=16384 diff --git a/tests/Constraint/AbstractConstraintInstance.php b/tests/Constraint/AbstractConstraintInstance.php new file mode 100644 index 000000000..90779bd18 --- /dev/null +++ b/tests/Constraint/AbstractConstraintInstance.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Composer\Semver\Constraint; + +class AbstractConstraintInstance extends AbstractConstraint +{ + public function __toString() + { + return $this->prettyString; + } +} diff --git a/tests/Constraint/AbstractConstraintTest.php b/tests/Constraint/AbstractConstraintTest.php new file mode 100644 index 000000000..d22ce8746 --- /dev/null +++ b/tests/Constraint/AbstractConstraintTest.php @@ -0,0 +1,24 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Composer\Semver\Constraint; + +class AbstractConstraintTest extends \PHPUnit_Framework_TestCase +{ + /** + * @expectedException PHPUnit_Framework_Error_Deprecated + */ + public function testAbstractConstraintWithDeprecated() + { + $expectedString = 'pretty string'; + $constraint = new AbstractConstraintInstance(); + } +} diff --git a/tests/Constraint/ConstraintTest.php b/tests/Constraint/ConstraintTest.php index dc812de7a..7fff599ab 100644 --- a/tests/Constraint/ConstraintTest.php +++ b/tests/Constraint/ConstraintTest.php @@ -13,6 +13,38 @@ class ConstraintTest extends \PHPUnit_Framework_TestCase { + protected $constraint; + protected $versionProvide; + + protected function setUp() + { + $this->constraint = new Constraint('==', '1'); + $this->versionProvide = new Constraint('==', 'dev-foo'); + } + + /** + * @expectedException \InvalidArgumentException + */ + public function testVersionCompareInvalidArgumentException() + { + $result = $this->constraint->versionCompare('1.1', '1.2', null); + } + + public function testGetPrettyString() + { + $expectedString = 'pretty-string'; + $this->constraint->setPrettyString($expectedString); + $result = $this->constraint->getPrettyString(); + + $this->assertSame($expectedString, $result); + + $expectedVersion = '== 1'; + $this->constraint->setPrettyString(null); + $result = $this->constraint->getPrettyString(); + + $this->assertSame($expectedVersion, $result); + } + public static function successfulVersionMatches() { return array( @@ -119,16 +151,14 @@ public function testInverseMatchingOtherConstraints() public function testComparableBranches() { $versionRequire = new Constraint('>', '0.12'); - $versionProvide = new Constraint('==', 'dev-foo'); - $this->assertFalse($versionRequire->matches($versionProvide)); - $this->assertFalse($versionRequire->matchSpecific($versionProvide, true)); + $this->assertFalse($versionRequire->matches($this->versionProvide)); + $this->assertFalse($versionRequire->matchSpecific($this->versionProvide, true)); $versionRequire = new Constraint('<', '0.12'); - $versionProvide = new Constraint('==', 'dev-foo'); - $this->assertFalse($versionRequire->matches($versionProvide)); - $this->assertTrue($versionRequire->matchSpecific($versionProvide, true)); + $this->assertFalse($versionRequire->matches($this->versionProvide)); + $this->assertTrue($versionRequire->matchSpecific($this->versionProvide, true)); } /** diff --git a/tests/Constraint/EmptyConstraintTest.php b/tests/Constraint/EmptyConstraintTest.php new file mode 100644 index 000000000..6208e33ab --- /dev/null +++ b/tests/Constraint/EmptyConstraintTest.php @@ -0,0 +1,46 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Composer\Semver\Constraint; + +class EmptyConstraintTest extends \PHPUnit_Framework_TestCase +{ + protected $versionProvide; + protected $emptyConstraint; + + protected function setUp() + { + $this->versionProvide = new Constraint('==', '1.1'); + $this->emptyConstraint = new EmptyConstraint(); + } + + public function testMatches() + { + $result = $this->emptyConstraint->matches($this->versionProvide); + + $this->assertTrue($result); + } + + public function testGetPrettyString() + { + $expectedString = 'pretty-string'; + $this->emptyConstraint->setPrettyString($expectedString); + $result = $this->emptyConstraint->getPrettyString(); + + $this->assertSame($expectedString, $result); + + $expectedString = '[]'; + $this->emptyConstraint->setPrettyString(null); + $result = $this->emptyConstraint->getPrettyString(); + + $this->assertSame($expectedString, $result); + } +} diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php index 953ee42fa..85460b888 100644 --- a/tests/Constraint/MultiConstraintTest.php +++ b/tests/Constraint/MultiConstraintTest.php @@ -13,38 +13,84 @@ class MultiConstraintTest extends \PHPUnit_Framework_TestCase { + protected $multiConstraint; + protected $versionRequireStart; + protected $versionRequireEnd; + + protected function setUp() + { + $this->multiConstraint = new MultiConstraint(array()); + $this->versionRequireStart = new Constraint('>', '1.0'); + $this->versionRequireEnd = new Constraint('<', '1.2'); + } + + public function testIsConjunctive() + { + $result = $this->multiConstraint->isConjunctive(); + + $this->assertTrue($result); + } + + public function testIsDisjunctive() + { + $result = $this->multiConstraint->isDisjunctive(); + + $this->assertFalse($result); + } + public function testMultiVersionMatchSucceeds() { - $versionRequireStart = new Constraint('>', '1.0'); - $versionRequireEnd = new Constraint('<', '1.2'); $versionProvide = new Constraint('==', '1.1'); - $multiRequire = new MultiConstraint(array($versionRequireStart, $versionRequireEnd)); + $multiRequire = new MultiConstraint(array($this->versionRequireStart, $this->versionRequireEnd)); $this->assertTrue($multiRequire->matches($versionProvide)); } public function testMultiVersionProvidedMatchSucceeds() { - $versionRequireStart = new Constraint('>', '1.0'); - $versionRequireEnd = new Constraint('<', '1.2'); $versionProvideStart = new Constraint('>=', '1.1'); $versionProvideEnd = new Constraint('<', '2.0'); - $multiRequire = new MultiConstraint(array($versionRequireStart, $versionRequireEnd)); + $multiRequire = new MultiConstraint(array($this->versionRequireStart, $this->versionRequireEnd)); $multiProvide = new MultiConstraint(array($versionProvideStart, $versionProvideEnd)); $this->assertTrue($multiRequire->matches($multiProvide)); } + public function testMultiVersionMatchSucceedsInsideForeachLoop() + { + $versionProvideStart = new Constraint('>', '1.0'); + $versionProvideEnd = new Constraint('<', '1.2'); + + $multiRequire = new MultiConstraint(array($this->versionRequireStart, $this->versionRequireEnd), false); + $multiProvide = new MultiConstraint(array($versionProvideStart, $versionProvideEnd), false); + + $this->assertTrue($multiRequire->matches($multiProvide)); + } + public function testMultiVersionMatchFails() { - $versionRequireStart = new Constraint('>', '1.0'); - $versionRequireEnd = new Constraint('<', '1.2'); $versionProvide = new Constraint('==', '1.2'); - $multiRequire = new MultiConstraint(array($versionRequireStart, $versionRequireEnd)); + $multiRequire = new MultiConstraint(array($this->versionRequireStart, $this->versionRequireEnd)); $this->assertFalse($multiRequire->matches($versionProvide)); } + + public function testGetPrettyString() + { + $multiConstraint = new MultiConstraint(array()); + $expectedString = 'pretty-string'; + $multiConstraint->setPrettyString($expectedString); + $result = $multiConstraint->getPrettyString(); + + $this->assertSame($expectedString, $result); + + $expectedString = '[]'; + $multiConstraint->setPrettyString(null); + $result = $multiConstraint->getPrettyString(); + + $this->assertSame($expectedString, $result); + } } diff --git a/tests/SemverTest.php b/tests/SemverTest.php index 878c25214..635740dba 100644 --- a/tests/SemverTest.php +++ b/tests/SemverTest.php @@ -58,6 +58,22 @@ public function testSort(array $versions, array $sorted, array $rsorted) $this->assertEquals($rsorted, Semver::rsort($versions)); } + public function testUsortShouldInitialVersionParserClass() + { + $versions = array('1.0', '2.0', '2.1'); + $semver = new \ReflectionClass('\Composer\Semver\Semver'); + $versionParserProperty = $semver->getProperty('versionParser'); + $versionParserProperty->setAccessible(true); + $versionParserProperty = $versionParserProperty->setValue(null); + + $manipulateVersionStringMethod = $semver->getMethod('usort'); + $manipulateVersionStringMethod->setAccessible(true); + $result = $manipulateVersionStringMethod->invoke(new Semver(), $versions, 1); + + $this->assertInternalType('array', $result); + $this->assertCount(3, $versions); + } + /** * @return array */ diff --git a/tests/VersionParserTest.php b/tests/VersionParserTest.php index 87fa0d9e2..60b772665 100644 --- a/tests/VersionParserTest.php +++ b/tests/VersionParserTest.php @@ -23,6 +23,7 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase public function testParseNumericAliasPrefix($input, $expected) { $parser = new VersionParser(); + $this->assertSame($expected, $parser->parseNumericAliasPrefix($input)); } @@ -46,6 +47,7 @@ public function numericAliasVersions() public function testNormalizeSucceeds($input, $expected) { $parser = new VersionParser(); + $this->assertSame($expected, $parser->normalize($input)); } @@ -119,12 +121,31 @@ public function failingNormalizedVersions() ); } + /** + * @expectedException \UnexpectedValueException + */ + public function testNormalizeFailsWithExtraMessage() + { + $parser = new VersionParser(); + $parser->normalize('', ' as '); + } + + /** + * @expectedException \UnexpectedValueException + */ + public function testNormalizeFailsWithOtherExtraMessage() + { + $parser = new VersionParser(); + $parser->normalize('', ' as 123'); + } + /** * @dataProvider successfulNormalizedBranches */ public function testNormalizeBranch($input, $expected) { $parser = new VersionParser(); + $this->assertSame((string) $expected, (string) $parser->normalizeBranch($input)); } @@ -150,12 +171,14 @@ public function successfulNormalizedBranches() public function testParseConstraintsIgnoresStabilityFlag() { $parser = new VersionParser(); + $this->assertSame((string) new Constraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0@dev')); } public function testParseConstraintsIgnoresReferenceOnDevVersion() { $parser = new VersionParser(); + $this->assertSame((string) new Constraint('=', '1.0.9999999.9999999-dev'), (string) $parser->parseConstraints('1.0.x-dev#abcd123')); $this->assertSame((string) new Constraint('=', '1.0.9999999.9999999-dev'), (string) $parser->parseConstraints('1.0.x-dev#trunk/@123')); } @@ -166,6 +189,7 @@ public function testParseConstraintsIgnoresReferenceOnDevVersion() public function testParseConstraintsFailsOnBadReference() { $parser = new VersionParser(); + $this->assertSame((string) new Constraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0#abcd123')); $this->assertSame((string) new Constraint('=', '1.0.0.0'), (string) $parser->parseConstraints('1.0#trunk/@123')); } @@ -189,6 +213,7 @@ public function testParseConstraintsNudgesRubyDevsTowardsThePathOfRighteousness( public function testParseConstraintsSimple($input, $expected) { $parser = new VersionParser(); + $this->assertSame((string) $expected, (string) $parser->parseConstraints($input)); } @@ -397,6 +422,7 @@ public function testParseConstraintsMultiCollapsesContiguous() $first = new Constraint('>=', '2.5.0.0-dev'); $second = new Constraint('<', '4.0.0.0-dev'); $multi = new MultiConstraint(array($first, $second)); + $this->assertSame((string) $multi, (string) $parser->parseConstraints('^2.5 || ^3.0')); } @@ -413,6 +439,7 @@ public function testParseCaretConstraintsMultiDoesNotCollapseNonContiguousRange( )); $multi = new MultiConstraint(array($first, $second), false); $parsed = $parser->parseConstraints('^0.2 || ^1.0'); + $this->assertSame((string) $multi, (string) $parsed); } @@ -432,9 +459,11 @@ public function testDoNotCollapseContiguousRangeIfOtherConstraintsAlsoApply() $multi = new MultiConstraint(array($first, $second), false); $version = new Constraint('=', '1.0.1.0'); + $this->assertFalse($multi->matches($version), 'Generated expectation should not allow version "1.0.1.0"'); $parsed = $parser->parseConstraints('~0.1 || ~1.0 !=1.0.1'); + $this->assertFalse($parsed->matches($version), '"~0.1 || ~1.0 !=1.0.1" should not allow version "1.0.1.0"'); $this->assertSame((string) $multi, (string) $parsed); @@ -449,6 +478,7 @@ public function testParseConstraintsMulti($constraint) $first = new Constraint('>', '2.0.0.0'); $second = new Constraint('<=', '3.0.0.0'); $multi = new MultiConstraint(array($first, $second)); + $this->assertSame((string) $multi, (string) $parser->parseConstraints($constraint)); } @@ -477,11 +507,13 @@ public function testParseConstraintsMultiWithStabilitySuffix() $first = new Constraint('>=', '1.1.0.0-alpha4'); $second = new Constraint('<', '1.2.9999999.9999999-dev'); $multi = new MultiConstraint(array($first, $second)); + $this->assertSame((string) $multi, (string) $parser->parseConstraints('>=1.1.0-alpha4,<1.2.x-dev')); $first = new Constraint('>=', '1.1.0.0-alpha4'); $second = new Constraint('<', '1.2.0.0-beta2'); $multi = new MultiConstraint(array($first, $second)); + $this->assertSame((string) $multi, (string) $parser->parseConstraints('>=1.1.0-alpha4,<1.2-beta2')); } @@ -498,6 +530,7 @@ public function testParseConstraintsMultiDisjunctiveHasPrioOverConjuctive($const $third = new Constraint('>', '2.0.6.0'); $multi1 = new MultiConstraint(array($first, $second)); $multi2 = new MultiConstraint(array($multi1, $third), false); + $this->assertSame((string) $multi2, (string) $parser->parseConstraints($constraint)); } @@ -519,6 +552,7 @@ public function testParseConstraintsMultiWithStabilities() $first = new Constraint('>', '2.0.0.0'); $second = new Constraint('<=', '3.0.0.0-dev'); $multi = new MultiConstraint(array($first, $second)); + $this->assertSame((string) $multi, (string) $parser->parseConstraints('>2.0@stable,<=3.0@dev')); } @@ -586,6 +620,36 @@ public function stabilityProvider() array('alpha', '1.2_a1'), array('RC', '2.0.0rc1'), array('alpha', '1.0.0-alpha11+cs-1.1.0'), + array('dev', '1-2_dev'), ); } + + public function testNormalizeStability() + { + $parser = new VersionParser(); + $stability = 'rc'; + $expectedValue = 'RC'; + $result = $parser->normalizeStability($stability); + + $this->assertSame($expectedValue, $result); + + $stability = 'no-rc'; + $expectedValue = $stability; + $result = $parser->normalizeStability($stability); + + $this->assertSame($expectedValue, $result); + } + + public function testManipulateVersionStringWithReturnNull() + { + $position = 1; + $increment = 2; + $matches = array(-1, -3, -2, -5, -9); + $parser = new \ReflectionClass('\Composer\Semver\VersionParser'); + $manipulateVersionStringMethod = $parser->getMethod('manipulateVersionString'); + $manipulateVersionStringMethod->setAccessible(true); + $result = $manipulateVersionStringMethod->invoke(new VersionParser(), $matches, $position, $increment); + + $this->assertNull($result); + } }