Skip to content

unit testing improvement #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,29 @@ 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')
->in(__DIR__.'/tests')
;

/* 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,
'phpdoc_order' => true,
'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)
;
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: php

sudo: false

cache:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @stof, the original configuration is false.
Please see this PR. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default value for sudo is not always false actually. It depends on repositories.

Copy link
Contributor Author

@peter279k peter279k Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have been confused this for a long time.
Would you please provide some references about this?
Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's false for this repo by default though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alcohol but it makes it harder to copy-paste the config elsewhere (composer has some repository where it is not the default)

Copy link
Contributor Author

@peter279k peter279k Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi all, I think the proper way is adding the sudo: false for each time so that it can always make sure that it's running on the non-root environment.

What do you think?

Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I prefer being explicit too, as it does not require knowing at which date the repo started using Travis (this info is not available anywhere except in the Travis database AFAIK, and we cannot access it)

directories:
- $HOME/.composer/cache
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add -d option for hhvm

Guess it is related to hhvm?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Please refer this issue.

Thanks.

20 changes: 20 additions & 0 deletions tests/Constraint/AbstractConstraintInstance.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of composer/semver.
*
* (c) Composer <https://github.com/composer>
*
* 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;
}
}
24 changes: 24 additions & 0 deletions tests/Constraint/AbstractConstraintTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/*
* This file is part of composer/semver.
*
* (c) Composer <https://github.com/composer>
*
* 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();
}
}
42 changes: 36 additions & 6 deletions tests/Constraint/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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));
}

/**
Expand Down
46 changes: 46 additions & 0 deletions tests/Constraint/EmptyConstraintTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* This file is part of composer/semver.
*
* (c) Composer <https://github.com/composer>
*
* 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);
}
}
64 changes: 55 additions & 9 deletions tests/Constraint/MultiConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 16 additions & 0 deletions tests/SemverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading