Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PhpUnit] Mock clock on @group time-sensitive annotations #16194

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 1 commit into from
Oct 12, 2015

Conversation

nicolas-grekas
Copy link
Member

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Instead of spreading the same clock mock code everywhere, let's create a test case that helps mocking the time related functions.

@@ -43,6 +43,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit")) {
passthru("$COMPOSER remove --no-update symfony/yaml");
passthru("$COMPOSER require --dev --no-update symfony/phpunit-bridge \">=2.8@dev\"");
passthru("$COMPOSER install --prefer-source --no-progress --ansi");
symlink(realpath('../../src/Symfony/Bridge/PhpUnit/ClockMockedTestCase.php'), './vendor/symfony/phpunit-bridge/ClockMockedTestCase.php');
Copy link
Member Author

Choose a reason for hiding this comment

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

This line should be removed when merging

@nicolas-grekas
Copy link
Member Author

Thinking a bit more about this, I'm going to replace the test case by an annotation.
Status: needs work

nicolas-grekas added a commit that referenced this pull request Oct 11, 2015
…ekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[PhpUnit] Auto-register SymfonyTestsListener

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This allows removing the copy/pasted `<listeners>` tags in our phpunit.xml.dist files and opens for future enhancements (like #16194)

Commits
-------

9e2bb00 [PhpUnit] Auto-register SymfonyTestsListener
@nicolas-grekas nicolas-grekas changed the title [PhpUnitBridge] Add ClockMockedTestCase [PhpUnit] Mock time on @group clockMock annotations Oct 11, 2015
@nicolas-grekas
Copy link
Member Author

Updated to use @group clockMock annotations
Status: needs review


/**
* @group clockMock
Copy link
Member

Choose a reason for hiding this comment

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

Not a big fan of the group name. Also, wouldn't it be better for it to be an annotation instead of a group?

Copy link
Member Author

Choose a reason for hiding this comment

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

i'm open for suggestions :) using a group annotation makes the implementation a lot easier by reusing a bunch of existing caching logic. It also allows filtering these specific tests when running the test suite...

Copy link
Contributor

Choose a reason for hiding this comment

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

(clock, time)Related, requiresFixedTime, timeSensitive ?

The mocking of a clock is just a detail, it's more about what it is fixing.

Copy link
Member Author

Choose a reason for hiding this comment

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

clockMockable?

Copy link
Member

Choose a reason for hiding this comment

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

I think I don't like having mock in there.

I do understand that using a group is much easier (I recently tried to add an annotation for BF :)), but that does not make it better (and not sure it makes sense to filter those tests).

Time sensitive sounds much better.

@nicolas-grekas nicolas-grekas force-pushed the clockmock branch 2 times, most recently from 72ed068 to 3e81e43 Compare October 11, 2015 14:05
@nicolas-grekas nicolas-grekas changed the title [PhpUnit] Mock time on @group clockMock annotations [PhpUnit] Mock time on @group clockMockable annotations Oct 11, 2015
@stof
Copy link
Member

stof commented Oct 11, 2015

The phpunit-bridge dev requirement in all these packages needs to be upgraded as it relies on the new feature

@nicolas-grekas
Copy link
Member Author

@stof in fact I removed all of them in 4032c88: now that our phpunit wrapper requires phpunit-bridge, they are not required anymore.

@nicolas-grekas
Copy link
Member Author

Updated to use @group time-sensitive annotations. OK for you?

@nicolas-grekas nicolas-grekas changed the title [PhpUnit] Mock time on @group clockMockable annotations [PhpUnit] Mock clock on @group time-sensitive annotations Oct 12, 2015
@fabpot
Copy link
Member

fabpot commented Oct 12, 2015

👍

@fabpot
Copy link
Member

fabpot commented Oct 12, 2015

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 34a0846 into symfony:2.8 Oct 12, 2015
fabpot added a commit that referenced this pull request Oct 12, 2015
…ons (nicolas-grekas)

This PR was merged into the 2.8 branch.

Discussion
----------

[PhpUnit] Mock clock on @group time-sensitive annotations

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Instead of spreading the same clock mock code everywhere, let's create a test case that helps mocking the time related functions.

Commits
-------

34a0846 [PhpUnit] Mock clock on @group time-sensitive annotations
@nicolas-grekas nicolas-grekas deleted the clockmock branch October 12, 2015 11:10
@fabpot fabpot mentioned this pull request Nov 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants