ReStructured Text Infrastructurewiki.typo3.orgOfficial Documentation

Task #12297

Adjust section on filenames of unit tests

Added by Stefano Kowalke over 2 years ago. Updated 14 days ago.

Status:Resolved Start date:2011-01-16
Priority:Should have Due date:
Assignee:Chris topher % Done:

100%

Category:-
Target version:6.0.0
Votes: 0

Description

TYPO3 requires all PHP class file names to start with class. prefix.

Unittest files contains classes too, but don't have the class. prefix in its filename.

Is there a reason for this?


Related issues

related to Core - Task #25869: Sysext should ship with their tests in their own directly Resolved 2011-04-10
related to Core - Task #25868: Add class. prefix to all unit test files Resolved 2011-04-10
related to Coding Guidelines - Task #47956: Update information on file names and class names Resolved 2013-05-05

Associated revisions

Revision 65a7f18f
Added by Chris topher 14 days ago

[TASK] Adjust section on filenames of unit tests

Update the information on the file names and file structure of unit
tests.

Change-Id: I7b6da572541855b060429540c9daaf1b68a51117
Resolves: #12297
Reviewed-on: https://review.typo3.org/20689
Reviewed-by: Chris topher
Tested-by: Chris topher

History

Updated by Ernesto Baschny about 2 years ago

Good question, maybe it is a matter of phpUnit finding the classes? We should ask Oli Klee - our tests expert - for his opinion on that.

Updated by Stefano Kowalke about 2 years ago

Shall unit test files following the CGL?

Updated by Francois Suter about 2 years ago

Stefano Kowalke wrote:

Shall unit test files following the CGL?

Yes, they should. There might be some exceptions due to special features of unit test files, but I don't think this needs to be documented.

Updated by Francois Suter about 2 years ago

  • Status changed from New to Needs Feedback
  • Assignee set to Francois Suter
  • Target version set to 4.5.0

Sent a mail to Oliver Klee. Waiting for his answer.

Updated by Francois Suter about 2 years ago

Oliver's answer:

in order for the tests to work both in the CLI runner as well as the BE test runner, the file names need to end with "Test.php" and the contained test classes need to end with "Test".

I strongly recommend to name the test class for a class like the tested class plus just the suffix "Test" and name the file like the tested file name plus the same suffix. (However, this is only a convention, not a technical necessity. For some very large classes, it might make sense to have more than one test class - before refactoring the big class to smaller classes, of course. :-)

So, to sum up, for the CGL I propose to use the same class and file names as the original class and just add the suffix "Test".

Updated by Francois Suter about 2 years ago

Ernesto's reflections based on Oliver's information:

I think something should be cleaned up, especially if we also consider that we have sysext that also ship with tests. Some examples of what we have currently:

typo3/sysext/saltedpasswords/tests/tx_saltedpasswords_divTest.php => class = tx_saltedpasswords_divTest

tests/typo3/sysext/cms/tslib/tslib_contentTest.php => class = tslib_contentTest

tests/t3lib/t3lib_spritemanagerTest.php => class = t3lib_spritemanagerTest

tests/t3lib/tree/t3lib_tree_nodeTest.php => class = t3lib_tree_nodeTest

tests/contrib/removexssTest.php => class removexssTest

My suggestion for the rules and what then have to be done in our current code base in order to adhere to it:

1) sysext should ship with their tests in their own directly. => Meaning move the tests from tests/typo3/sysext/cms/ to typo3/sysext/cms/tests/.

2) Tests for typo3/ and t3lib/ classes are the only ones kept under our root "tests/". => Meaning move tests/contrib/removexssTest.php to tests/typo3/contrib/RemoveXSS/

3) Use the same filename as the original ones only with the "Test.php" suffix appended. => Meaning adding the "class." in front of all test classes, i.e. tests/t3lib/t3lib_divTest.php => tests/t3lib/class.t3lib_divTest.php

Only exception to these rules are Extbase / Fluid and all Extbase-based extensions, which have their own CGL for file naming anyway.

Updated by Francois Suter about 2 years ago

  • Status changed from Needs Feedback to On Hold
  • Target version deleted (4.5.0)

My conclusion for now:

I agree with Ernesto that a clean up should be done, but I think the clean up should be done first and the CGLs adapted later. So I propose to postpone this issue until then.

Updated by Stefano Kowalke about 2 years ago

Ok, I am fine with this. I will provide patches for the renaming and moving

Updated by Philipp Gampe 8 months ago

I guess after namespacing, all files have been renamed.

Updated by Chris topher 19 days ago

  • Status changed from On Hold to Needs Feedback

Philipp Gampe wrote:

I guess after namespacing, all files have been renamed.

Yes, the overall structure changed.

E.g. unit tests now are no longer in a folder in the root of the TYPO3 directory, but in a folder close to the actual files, which they test.

As far as they still apply, I will take Oliver's and Ernesto's notes into account.

Updated by Chris topher 14 days ago

  • Assignee changed from Francois Suter to Chris topher
  • Target version set to 6.0.0

Updated by Chris topher 14 days ago

  • Tracker changed from Bug to Task
  • Subject changed from Filenames of Unittests to Adjust section on filenames of unit tests

Updated by Gerrit Code Review 14 days ago

  • Status changed from Needs Feedback to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20689

Updated by Chris topher 14 days ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF