From cc36d516dc56a66abf1d642b9c444b51ff990049 Mon Sep 17 00:00:00 2001 From: peter279k Date: Wed, 11 Jan 2017 20:35:57 +0800 Subject: [PATCH 1/8] unit testing improvement --- .styleci.yml | 2 + .travis.yml | 2 - tests/Constraint/AbstractConstraintTest.php | 33 ++++++++++ tests/Constraint/ConstraintTest.php | 48 ++++++++++++-- tests/Constraint/EmptyConstraintTest.php | 52 +++++++++++++++ tests/Constraint/MultiConstraintTest.php | 72 ++++++++++++++++++--- tests/SemverTest.php | 16 +++++ tests/VersionParserTest.php | 64 ++++++++++++++++++ 8 files changed, 272 insertions(+), 17 deletions(-) create mode 100644 .styleci.yml create mode 100644 tests/Constraint/AbstractConstraintTest.php create mode 100644 tests/Constraint/EmptyConstraintTest.php diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 000000000..9f7eac2e4 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1,2 @@ +preset: psr2 + diff --git a/.travis.yml b/.travis.yml index 12bec6789..6076acf94 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: php -sudo: false - cache: directories: - $HOME/.composer/cache diff --git a/tests/Constraint/AbstractConstraintTest.php b/tests/Constraint/AbstractConstraintTest.php new file mode 100644 index 000000000..171cd84af --- /dev/null +++ b/tests/Constraint/AbstractConstraintTest.php @@ -0,0 +1,33 @@ + + * + * 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 \ReflectionClass('\Composer\Semver\Constraint\AbstractConstraint'); + $setPrettyString = $constraint->getMethod('setPrettyString'); + $setPrettyString->setAccessible(true); + $setPrettyString->invoke($constraint, 'pretty string'); + + $getPrettyString = $constraint->getMethod('getPrettyString'); + $getPrettyString->setAccessible(true); + $result = $setPrettyString->invoke($constraint); + + $this->assertSame($expectedString, $result); + } +} \ No newline at end of file diff --git a/tests/Constraint/ConstraintTest.php b/tests/Constraint/ConstraintTest.php index dc812de7a..dc65f09e9 100644 --- a/tests/Constraint/ConstraintTest.php +++ b/tests/Constraint/ConstraintTest.php @@ -13,6 +13,44 @@ class ConstraintTest extends \PHPUnit_Framework_TestCase { + protected $constraint; + protected $versionProvide; + + protected function setUp() + { + $this->constraint = new Constraint('==', '1'); + $this->versionProvide = new Constraint('==', 'dev-foo'); + } + + protected function tearDown() + { + unset($this->constraint); + unset($this->versionProvide); + } + + /** + * @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 +157,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..f06bb4a6a --- /dev/null +++ b/tests/Constraint/EmptyConstraintTest.php @@ -0,0 +1,52 @@ + + * + * 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(); + } + + protected function tearDown() + { + unset($this->versionProvide); + unset($this->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); + } +} \ No newline at end of file diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php index 953ee42fa..862f20303 100644 --- a/tests/Constraint/MultiConstraintTest.php +++ b/tests/Constraint/MultiConstraintTest.php @@ -13,38 +13,92 @@ 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'); + } + + protected function tearDown() + { + unset($this->multiConstraint); + unset($this->versionRequireStart); + unset($this->versionRequireEnd); + } + + 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); + } } From 808ec2b0b0244fc5d41fc02011f6fa912dda2be9 Mon Sep 17 00:00:00 2001 From: peter279k Date: Wed, 11 Jan 2017 21:07:00 +0800 Subject: [PATCH 2/8] .php_cs fix psr2 syntax(and using fixer 2.0) --- .php_cs | 24 +++------------------ .styleci.yml | 2 -- .travis.yml | 8 +++++-- tests/Constraint/AbstractConstraintTest.php | 2 +- tests/Constraint/EmptyConstraintTest.php | 2 +- tests/Constraint/MultiConstraintTest.php | 1 - 6 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 .styleci.yml 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/.styleci.yml b/.styleci.yml deleted file mode 100644 index 9f7eac2e4..000000000 --- a/.styleci.yml +++ /dev/null @@ -1,2 +0,0 @@ -preset: psr2 - diff --git a/.travis.yml b/.travis.yml index 6076acf94..273b5a193 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,10 +18,14 @@ php: matrix: fast_finish: true + allow_failures: + - php: hhvm 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 --coverage-clover=coverage.xml + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/tests/Constraint/AbstractConstraintTest.php b/tests/Constraint/AbstractConstraintTest.php index 171cd84af..f6f019224 100644 --- a/tests/Constraint/AbstractConstraintTest.php +++ b/tests/Constraint/AbstractConstraintTest.php @@ -30,4 +30,4 @@ public function testAbstractConstraintWithDeprecated() $this->assertSame($expectedString, $result); } -} \ No newline at end of file +} diff --git a/tests/Constraint/EmptyConstraintTest.php b/tests/Constraint/EmptyConstraintTest.php index f06bb4a6a..ae73ef0d1 100644 --- a/tests/Constraint/EmptyConstraintTest.php +++ b/tests/Constraint/EmptyConstraintTest.php @@ -49,4 +49,4 @@ public function testGetPrettyString() $this->assertSame($expectedString, $result); } -} \ No newline at end of file +} diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php index 862f20303..b643d4c0c 100644 --- a/tests/Constraint/MultiConstraintTest.php +++ b/tests/Constraint/MultiConstraintTest.php @@ -17,7 +17,6 @@ class MultiConstraintTest extends \PHPUnit_Framework_TestCase protected $versionRequireStart; protected $versionRequireEnd; - protected function setUp() { $this->multiConstraint = new MultiConstraint(array()); From 6de4ba414e52e07e275d2b38b7ca8d1b2ec6f665 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 12 Jan 2017 03:16:42 +0800 Subject: [PATCH 3/8] remove unset class properties --- .travis.yml | 5 +---- tests/Constraint/ConstraintTest.php | 6 ------ tests/Constraint/EmptyConstraintTest.php | 6 ------ tests/Constraint/MultiConstraintTest.php | 7 ------- 4 files changed, 1 insertion(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 273b5a193..e6c1b6f0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,4 @@ before_script: - composer install --no-interaction --no-progress --prefer-dist script: - - vendor/bin/phpunit --coverage-clover=coverage.xml - -after_success: - - bash <(curl -s https://codecov.io/bash) + - vendor/bin/phpunit diff --git a/tests/Constraint/ConstraintTest.php b/tests/Constraint/ConstraintTest.php index dc65f09e9..7fff599ab 100644 --- a/tests/Constraint/ConstraintTest.php +++ b/tests/Constraint/ConstraintTest.php @@ -22,12 +22,6 @@ protected function setUp() $this->versionProvide = new Constraint('==', 'dev-foo'); } - protected function tearDown() - { - unset($this->constraint); - unset($this->versionProvide); - } - /** * @expectedException \InvalidArgumentException */ diff --git a/tests/Constraint/EmptyConstraintTest.php b/tests/Constraint/EmptyConstraintTest.php index ae73ef0d1..6208e33ab 100644 --- a/tests/Constraint/EmptyConstraintTest.php +++ b/tests/Constraint/EmptyConstraintTest.php @@ -22,12 +22,6 @@ protected function setUp() $this->emptyConstraint = new EmptyConstraint(); } - protected function tearDown() - { - unset($this->versionProvide); - unset($this->emptyConstraint); - } - public function testMatches() { $result = $this->emptyConstraint->matches($this->versionProvide); diff --git a/tests/Constraint/MultiConstraintTest.php b/tests/Constraint/MultiConstraintTest.php index b643d4c0c..85460b888 100644 --- a/tests/Constraint/MultiConstraintTest.php +++ b/tests/Constraint/MultiConstraintTest.php @@ -24,13 +24,6 @@ protected function setUp() $this->versionRequireEnd = new Constraint('<', '1.2'); } - protected function tearDown() - { - unset($this->multiConstraint); - unset($this->versionRequireStart); - unset($this->versionRequireEnd); - } - public function testIsConjunctive() { $result = $this->multiConstraint->isConjunctive(); From e4117d29300e8c739ad6c3af2c5833c0a88e0eb9 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 12 Jan 2017 17:21:22 +0800 Subject: [PATCH 4/8] extend abstract class and testing --- tests/Constraint/AbstractConstraintInstance.php | 16 ++++++++++++++++ tests/Constraint/AbstractConstraintTest.php | 12 ++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 tests/Constraint/AbstractConstraintInstance.php diff --git a/tests/Constraint/AbstractConstraintInstance.php b/tests/Constraint/AbstractConstraintInstance.php new file mode 100644 index 000000000..a5466a0f7 --- /dev/null +++ b/tests/Constraint/AbstractConstraintInstance.php @@ -0,0 +1,16 @@ + + * + * 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 +{ +} diff --git a/tests/Constraint/AbstractConstraintTest.php b/tests/Constraint/AbstractConstraintTest.php index f6f019224..c8fcf525c 100644 --- a/tests/Constraint/AbstractConstraintTest.php +++ b/tests/Constraint/AbstractConstraintTest.php @@ -19,14 +19,10 @@ class AbstractConstraintTest extends \PHPUnit_Framework_TestCase public function testAbstractConstraintWithDeprecated() { $expectedString = 'pretty string'; - $constraint = new \ReflectionClass('\Composer\Semver\Constraint\AbstractConstraint'); - $setPrettyString = $constraint->getMethod('setPrettyString'); - $setPrettyString->setAccessible(true); - $setPrettyString->invoke($constraint, 'pretty string'); - - $getPrettyString = $constraint->getMethod('getPrettyString'); - $getPrettyString->setAccessible(true); - $result = $setPrettyString->invoke($constraint); + $constraint = new AbstractConstraintInstance(); + + $constraint->setPrettyString('pretty-string'); + $result = $constraint->getPrettyString(); $this->assertSame($expectedString, $result); } From 4c84154ef52b9a539dcc912d98d820ed1a6a90da Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 12 Jan 2017 17:28:32 +0800 Subject: [PATCH 5/8] add __toString method (implement) --- tests/Constraint/AbstractConstraintInstance.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Constraint/AbstractConstraintInstance.php b/tests/Constraint/AbstractConstraintInstance.php index a5466a0f7..90779bd18 100644 --- a/tests/Constraint/AbstractConstraintInstance.php +++ b/tests/Constraint/AbstractConstraintInstance.php @@ -13,4 +13,8 @@ class AbstractConstraintInstance extends AbstractConstraint { + public function __toString() + { + return $this->prettyString; + } } From 48550d5f697ddde00d29d5e9f03075454bbbcd1f Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 12 Jan 2017 17:34:57 +0800 Subject: [PATCH 6/8] fix the hhvm problem about PHPUnit exception --- tests/Constraint/AbstractConstraintTest.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/Constraint/AbstractConstraintTest.php b/tests/Constraint/AbstractConstraintTest.php index c8fcf525c..d22ce8746 100644 --- a/tests/Constraint/AbstractConstraintTest.php +++ b/tests/Constraint/AbstractConstraintTest.php @@ -20,10 +20,5 @@ public function testAbstractConstraintWithDeprecated() { $expectedString = 'pretty string'; $constraint = new AbstractConstraintInstance(); - - $constraint->setPrettyString('pretty-string'); - $result = $constraint->getPrettyString(); - - $this->assertSame($expectedString, $result); } } From ce5854e316dc2cdf3380f943e1d8d5eb11e75c44 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 12 Jan 2017 17:42:43 +0800 Subject: [PATCH 7/8] add -d option for hhvm --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e6c1b6f0a..9c9cfc4ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,4 @@ before_script: - composer install --no-interaction --no-progress --prefer-dist script: - - vendor/bin/phpunit + - vendor/bin/phpunit -d error_reporting=16384 From 2c005469b740911f46779c3a3af28f0cc4ff22fa Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 12 Jan 2017 17:47:16 +0800 Subject: [PATCH 8/8] remove allow_failures option --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9c9cfc4ab..85521a446 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,8 +18,6 @@ php: matrix: fast_finish: true - allow_failures: - - php: hhvm before_script: - composer install --no-interaction --no-progress --prefer-dist