-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add details on how the ClockMock::register works #8899
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
Conversation
Hi, I got some trouble mocking using the ClockMock feature. After dig into the code, I figure myself how it works ! So I decided to do a PR, but I'm not sure of the formatting,
components/phpunit_bridge.rst
Outdated
} | ||
} | ||
|
||
class MyClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to add this again, or remove the code sample above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True ! Thanks, I removed it
@ndench @OskarStark @Jean85 any update ? |
Build is broken, maybe we should re-trigger it to see if now is ok? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your work on this.
components/phpunit_bridge.rst
Outdated
|
||
.. code-block:: | ||
|
||
namespace Tests/App; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
App\Tests
components/phpunit_bridge.rst
Outdated
.. caution:: | ||
|
||
The ``@group time-sensitive`` annotation is equivalent to ``ClockMock::register(MyTest::class)``, | ||
so if you want to mock a time based function mocked into one of the source code you will need to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to mock a time based function into ...
or if you want to get a time based function mocked into ...
?
components/phpunit_bridge.rst
Outdated
namespace Tests/App; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use App\MyClass; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please use an alpha order?
Thanks for reviewing, just updated according to your feedbacks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! last comments from me.
components/phpunit_bridge.rst
Outdated
only create a mock of the time based functions into the same namespace as your class. So when using | ||
``time()`` you will use the mock instead of the default one. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line can be removed.
components/phpunit_bridge.rst
Outdated
``time()`` you will use the mock instead of the default one. | ||
|
||
|
||
.. code-block:: php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be replaced by ::
at the end of line 241 instead of the dot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean I can replace
``time()`` you will use the mock instead of the default one.
.. code-block:: php
By
``time()`` you will use the mock instead of the default one::
How can I show the output of this file locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, that's what I meant. Fon't bother you can push and let our host hook build the demo, its link will be accessible in the PR checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, it isn't deployed on Platform.sh as specified here https://symfony.com/doc/current/contributing/documentation/overview.html#review-your-changes while branch 2.8 is in a maintained branch.
components/phpunit_bridge.rst
Outdated
} | ||
} | ||
|
||
.. code-block:: php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the code added here should keep an extra indent to be part of the caution block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I can indent also the code-block ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
components/phpunit_bridge.rst
Outdated
.. caution:: | ||
|
||
The ``@group time-sensitive`` annotation is equivalent to ``ClockMock::register(MyTest::class)``, | ||
so if you want to get a time based function mocked into one of the source code you will need to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
time-based (missing dash)
I don't understand "into one of the source code". Maybe "into another class"?
components/phpunit_bridge.rst
Outdated
The ``@group time-sensitive`` annotation is equivalent to ``ClockMock::register(MyTest::class)``, | ||
so if you want to get a time based function mocked into one of the source code you will need to | ||
add it explicitly using ``ClockMock::register(MyClass::class)``. The ``ClockMock::register`` method | ||
only create a mock of the time based functions into the same namespace as your class. So when using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creates (missing "s") - not need for "only" I suppose
time-based
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@nicolas-grekas @Jean85 I think it's ready to be merged 👼 |
This PR was squashed before being merged into the 2.8 branch (closes #8899). Discussion ---------- Add details on how the ClockMock::register works Hi, I got some trouble mocking using the ClockMock feature. After dig into the code, I figure myself how it works ! So I decided to do a PR, but I'm not sure of the formatting, Commits ------- a103731 Add details on how the ClockMock::register works
@moroine thanks for improving this doc! I'm sorry it took us so long to merge it. Also, congrats on your first Symfony Docs contribution! |
Hi,
I got some trouble mocking using the ClockMock feature. After dig into the code, I figure myself how it works !
So I decided to do a PR, but I'm not sure of the formatting,