Skip to content

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

Closed
wants to merge 6 commits into from

Conversation

moroine
Copy link

@moroine moroine commented Dec 18, 2017

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,

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,
}
}

class MyClass
Copy link
Contributor

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

Copy link
Author

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

@moroine
Copy link
Author

moroine commented Jun 27, 2018

@ndench @OskarStark @Jean85 any update ?

@Jean85
Copy link
Contributor

Jean85 commented Jun 27, 2018

Build is broken, maybe we should re-trigger it to see if now is ok?

Copy link
Contributor

@HeahDude HeahDude left a 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.


.. code-block::

namespace Tests/App;
Copy link
Contributor

Choose a reason for hiding this comment

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

App\Tests

.. 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
Copy link
Contributor

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

namespace Tests/App;

use PHPUnit\Framework\TestCase;
use App\MyClass;
Copy link
Contributor

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?

@moroine
Copy link
Author

moroine commented Jun 28, 2018

Thanks for reviewing, just updated according to your feedbacks

Copy link
Contributor

@HeahDude HeahDude left a 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.

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.


Copy link
Contributor

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.

``time()`` you will use the mock instead of the default one.


.. code-block:: php
Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Author

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.

}
}

.. code-block:: php
Copy link
Contributor

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.

Copy link
Author

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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes!

.. 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
Copy link
Member

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"?

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
Copy link
Member

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

@nicolas-grekas
Copy link
Member

@moroine it could be great to add a note to fix #9620 also btw, could you have a look? This seems very related to me.

@moroine
Copy link
Author

moroine commented Jul 2, 2018

Done

Copy link
Contributor

@HeahDude HeahDude left a comment

Choose a reason for hiding this comment

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

Thanks!

@moroine
Copy link
Author

moroine commented Jul 13, 2018

@nicolas-grekas @Jean85 I think it's ready to be merged 👼

@javiereguiluz javiereguiluz added this to the 2.8 milestone Oct 15, 2018
javiereguiluz added a commit that referenced this pull request Oct 15, 2018
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
@javiereguiluz
Copy link
Member

@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!

@moroine moroine deleted the patch-1 branch October 23, 2018 08:31
@moroine moroine restored the patch-1 branch October 23, 2018 08:32
@moroine moroine deleted the patch-1 branch October 23, 2018 08:33
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.

9 participants