-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Make abstract test case for user #116
Comments
I think there can be two sorts of abstract tests :
I think both should be separated, because the first should not be autoloadable Also, I think tests of type 2 should be integration tests (meaning some things are not mocked), because I can't imagine an abstract unit test that would be useful for users, and because I also think we should try to avoid inheritance as much as we can (main reason I prefer data mapper to active record). |
Why? It could be useful to simplify testing. For example, instead of let the user do all the mock logic, we can make an abstract method like
What do you mean? |
If some tests are not meant to be run by the user, or used, they should not be autoloadable (they should be only in dev, thanks to |
Do you have a concrete example ? |
This is a bundle. What about libraries? And what about the future, what if someday Symfony recommends to blacklist tests from the autoload in bundles ? I must go, but I'll have a look at your examples. |
Thanks for the example, it is valid indeed! |
So to sum up my point of view : In a library, tests useful for end-users would go in In a bundle… well I think it would be |
So you mean
Sound good to me. 👍 |
Yes |
@sonata-project/contributors is everyone ok with that? |
Yes for me. 👍 It would be great to add a note about this on the contributing guide. |
23 days have passed... Only 3 reactions :( |
@core23 Testing is not the priority of lot of people... 😉 Let's write this on the contributing guide soon. |
3 positive reactions though. I think we can merge sonata-project/SonataCoreBundle#275 , ok? |
It would be great to have proper guideline about this before merging anything IMHO. |
FYI, usually a TestCase is an abstract, so placing Abstract before it seems a bit redundant. |
Plus, Symfony does it this way ™. |
Symfony did it historically. But each abstract class name must be prefixed by Abstract according to Symfony conventions. |
You mean they are not following their own conventions? |
Historically.
http://symfony.com/doc/current/contributing/code/standards.html#naming-conventions |
If the need comes and someone wants to implement it , it will be welcomed |
Lot of Sonata classes are abstract classes and the goal is to be extended on your projects.
I'm thinking about
AbstractAdmin
orBlockService
.The test case
The goal of a test case is to provide facilities to the user to test project classes extending Sonata classes.
A test case can:
setUp
andsetUpBeforeClass
assert
methodstest*
method that will be launched on each children test class.The name
I suggest to name those kind of class
Abstract<TargetClass>TestCase
.Abstract
prefix because, well, it's an abstract class. :-)TestCase
to differentiate internal abstract test class that should not be used by ending user and abstract class dedicated for thisBC compliance
By definition, test classes should not be affected by the BC rule.
*TestCase
classes must do, because they will be used.Tag all other test classes with the
@internal
label can do the trick, but will be painful to apply.So I'm thinking about the
@api
tag.This is exactly the goal here.
With that, we can quickly see which test class can be broke and which should not.
A documentation about that should be added somewhere for ending users.
Sources
Class example from Symfony: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php
A class from one of my projects: https://github.com/Soullivaneuh/IsoCodesValidator/blob/3.x/tests/Constraints/AbstractConstraintValidatorTest.php
This is not a test case class, but you can see the principle of "default test" like
testNullIsValid
. This avoid test code duplication.What is your opinion about this?
The text was updated successfully, but these errors were encountered: