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

unit testing improvement #51

merged 8 commits into from
Jan 14, 2020

Conversation

peter279k
Copy link
Contributor

@peter279k peter279k commented Jan 11, 2017

Change log

  • Improve the unit testing and code coverage.
    the travis-ci status is available here.
    the code coverage report is available here.

  • Fix the error in .php_cs.
    In PHP-CS-Fixer version 2.0.0, removing some configurations because they are not available. And fix the class not found error. (please see this issue).

@codecov-io
Copy link

codecov-io commented Jan 11, 2017

Current coverage is 97.17% (diff: 100%)

No coverage report found for master at 69407bb.

Powered by Codecov. Last update 69407bb...808ec2b

@stof
Copy link
Contributor

stof commented Jan 11, 2017

if codecov-io adds a comment each time the PR is updated, this is a no-go IMO. It is spammy.

@@ -1,7 +1,5 @@
language: php

sudo: false
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)

@@ -20,10 +18,14 @@ php:

matrix:
fast_finish: true
allow_failures:
- php: hhvm
Copy link
Contributor

Choose a reason for hiding this comment

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

why ? it is passing in master, so there is no reason to allow it to fail. If your changes are breaking things, you should fix your contribution instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The HHVM is failed because it doesn't support the ReflectionClass.
I use this feature because I want to test some methods directly.

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 @stof, thank you for your suggestions again.
Now the HHVM is fixed and remove the allow_failures.
Thanks.

{
$expectedString = 'pretty string';
$constraint = new \ReflectionClass('\Composer\Semver\Constraint\AbstractConstraint');
$setPrettyString = $constraint->getMethod('setPrettyString');
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be much better to test this through the public API instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I know, the AbstractConstraintTest is deprecated abstract class so I just use the ReflectionClass to test the trigger_error.

Copy link
Contributor

Choose a reason for hiding this comment

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

As they are public method, you should just create a child class extending the abstract class and use the public API if you want to cover these methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your tips.
Fix it.

protected function tearDown()
{
unset($this->versionProvide);
unset($this->emptyConstraint);
Copy link
Contributor

Choose a reason for hiding this comment

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

you should not unset the class properties. You should only reset their values (or do nothing as there is no circular dependency with the TestCase, so the refcounting will work fine)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I will fix it later.

@peter279k
Copy link
Contributor Author

Hi @stof. Thank you for your comment, I just want to show the code coverage report so I add the codecov-io service. The owner can remove this and it's up to them. The PR is updated each time that I think it's not a important problem.

@stof
Copy link
Contributor

stof commented Jan 11, 2017

@peter279k each time there is a comment, maintainers receive an email. Gettings lots of emails just because the service reports the coverage status (which will only change in minor ways) is just spam IMO. github has better ways for automated systems to report an info for the PR (the status API)

@peter279k
Copy link
Contributor Author

Hi @stof, you're right. This should have the spam mail problem.
I think it should show one time and it doesn't show this after the up-coming commit.

- 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.

@Seldaek
Copy link
Member

Seldaek commented Jan 22, 2017

I think it'd be great to have the new tests in a separate PR as that is clearly an improvement.. The code coverage stuff though I am not so sure. I am not a fan of such metrics as they tend to incentivize the wrong things if they're displayed too prominently. Code coverage is a tool and that's available to anyone willing to improve the test suite by locally enabling it when running phpunit

@peter279k
Copy link
Contributor Author

Hi @Seldaek. You're right and I also am not the fan of code metric.
On the other hand, the code coverage is important because doing testing is to find bugs.
If the code coverage is higher, it possibly finds bugs, too.
This is IMO and I hope you can refer it.

Thanks.

@GrahamCampbell
Copy link
Contributor

What's the status here. This should probably go through first, before I (or anyone else) looks to finish #74.

@Seldaek
Copy link
Member

Seldaek commented Jan 14, 2020

I'll merge the tests and skip the rest.. You can work on #74 based on that assumption if it helps.

@GrahamCampbell
Copy link
Contributor

I'll look at that PR next week (hopefully!). :)

@Seldaek Seldaek merged commit 2c00546 into composer:master Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants