CoreCommunity ExtensionsIncubatorDistributionsTYPO3 4.5 ProjectsTYPO3 4.6 ProjectsTYPO3 4.7 ProjectsTYPO3 6.0 ProjectsTYPO3 6.1 ProjectsTYPO3 6.2 Projects (+)

Bug #36210

TestFinder::findTestCaseFilesInDirectory must not find Fixture classes

Added by Oliver Klee about 1 year ago. Updated 10 months ago.

Status:Resolved Start date:2012-04-17
Priority:Should have Due date:
Assignee:Nicole Cordes % Done:

100%

Category:-
Target version:3.6.11
PHP Version:
Votes: 0

Description

i.e., it must not find testcase files that are within a subfolder "fixtures" or "Fixtures" of $directory.

20120427_2303_patch_36210.diff (1.4 kB) Nicole Cordes, 2012-04-27 23:07

20120503_2131_patch_36210.diff (13.2 kB) Nicole Cordes, 2012-05-03 21:34

20120509_1430_patch_36210.diff (8.4 kB) Nicole Cordes, 2012-05-09 14:32


Related issues

blocks PHPUnit - Task #36999: Rename TestFinder::findTestCaseFilesDirectory to findTest... New 2012-05-09
blocks PHPUnit - Task #37004: Refactoring: Add helper functions to TestFinderTest for c... New 2012-05-09
blocked by PHPUnit - Task #36188: Rename TestFinder::findTestCasesInDirectory to findTestCa... Resolved 2012-04-16

Associated revisions

Revision 1fc244d3
Added by Nicole Cordes 10 months ago

[BUGFIX] TestFinder::findTestCaseFilesInDirectory finds Fixture classes

Change-Id: I57844e4105849174f5b83e9003a04f33d9167adc
Fixes: #36210

History

Updated by Oliver Klee about 1 year ago

We can use one of the included extensions for testing this, e.g., user_phpunittest.

Updated by Oliver Klee about 1 year ago

  • Subject changed from TestFinder::findTestCasesInDirectory must not find Fixture classes to TestFinder::findTestCaseFilesInDirectory must not find Fixture classes

Updated by Nicole Cordes about 1 year ago

Added condition to exclude directories with "fixture" substring included. Added an own test for this function. Please check if we can use the "backend" path or have to create an own fixture directory inside the service fixture directory itself.

Updated by Oliver Klee about 1 year ago

  • Status changed from New to Accepted

Updated by Oliver Klee about 1 year ago

This patch causes the following breakage on my installation on Linux:

Testsuite: Tx_Phpunit_Service_TestFinderTest

findTestCaseFilesDirectoryFindsFileWithProperTestcaseFileName

Failure in test case findTestCaseFilesDirectoryFindsFileWithProperTestcaseFileName
File: /home/klee/eclipse/phpunit/PEAR/PHPUnit/Framework/Constraint.php
Line: 92
Failed asserting that an array contains 'OneTest.php'.
findTestCaseFilesDirectoryNotFindsFileWithNonProperTestcaseFileName

Failure in test case findTestCaseFilesDirectoryNotFindsFileWithNonProperTestcaseFileName
File: /home/klee/eclipse/phpunit/PEAR/PHPUnit/Framework/MockObject/InvocationMocker.php
Line: 198
Expectation failed for method name is equal to <string:isTestCaseFileName> when invoked at sequence index 0.
The expected invocation at index 0 was never reached.
findTestCaseFilesDirectoryFindsTestcaseInSubfolder

Failure in test case findTestCaseFilesDirectoryFindsTestcaseInSubfolder
File: /home/klee/eclipse/phpunit/PEAR/PHPUnit/Framework/Constraint.php
Line: 92
Failed asserting that an array contains 'Subfolder/AnotherTest.php'.
findTestCaseFilesDirectoryAcceptsPathWithTrailingSlash

Failure in test case findTestCaseFilesDirectoryAcceptsPathWithTrailingSlash
File: /home/klee/eclipse/phpunit/PEAR/PHPUnit/Framework/Constraint.php
Line: 92
Failed asserting that true is false.

findTestCaseFilesDirectoryAcceptsPathWithoutTrailingSlash
Failure in test case findTestCaseFilesDirectoryAcceptsPathWithoutTrailingSlash
File: /home/klee/eclipse/phpunit/PEAR/PHPUnit/Framework/Constraint.php
Line: 92
Failed asserting that true is false.
findTestCaseFilesDirectorySortsFileNamesInAscendingOrder
Failure in test case findTestCaseFilesDirectorySortsFileNamesInAscendingOrder
File: /home/klee/eclipse/phpunit/PEAR/PHPUnit/Framework/Constraint.php
Line: 92
Failed asserting that false is true.
findTestCaseFilesDirectoryNotFindsFixtureTestCases
! Error in test case findTestCaseFilesDirectoryNotFindsFixtureTestCases
File: /home/klee/eclipse/phpunit/Classes/Service/TestFinder.php
Line: 159
The directory /home/klee/public_html/typo3.local/typo3conf/ext/phpunit/Tests/Unit/Backend does not exist.

Generally, we'll need the following changes:

1. Backend -> BackEnd (with uppercase "E")
2. We'll need tests for both cases ("Fixtures" and "fixtures") and the code to cover it.
3. Please move the stristr to a separate function (using the "extract method"/"decompose conditional" refactorings) so the level of abstraction in the conditional is on the same level)
4. get all unit tests to pass (on Windows as well as on Linux)

Updated by Nicole Cordes about 1 year ago

He he. All the tests fail because they are not included anymore :-) The path is a "Fixture" path. So what would be the right name for a test path besides Fixtures? Can we name it something like FolderForTestFinderTests?

Updated by Nicole Cordes about 1 year ago

I completely rewrote the tests and make use of our new accessible mock feature. Now everything is green again even without using another folder name.

Updated by Oliver Klee about 1 year ago

The accessible proxy in the TestFinderTest is something I'd like to get away from. Generally, I'd like that only public methods be tested (and those protected methods that are expected to be called from the subclasses). So I don't think that calling even more protected functions is the way to go.

Testing only the public functions will make refactoring a lot easier because then we can use the existing unit tests to test that everthings still works for the outside world. This will not be possible if we test protected functions.

For this particular issue, we can use the test extensions (aaa, bbb etc.) for having Fixture and fixture folders there (or, for Fixture with uppercase F, we can also use the phpunit extension itself).

===================================================================
--- Classes/Service/TestFinder.php    (revision 61361)
+++ Classes/Service/TestFinder.php    (revision )
+    /**
+     * Checks whether a path contains "fixture" in any case.
+     *
+     * @param string $path the absolute path of a file to check
+     *
+     * @return boolean TRUE if $path is a valid testcase path, FALSE otherwise
+     */
+    protected function isValidPathToInclude($path) {
+        $isValidPath = TRUE;
+        $path = strtolower($path);
+        $pathArray = explode('/', $path);
+        foreach ($pathArray as $pathPart) {
+            if (strpos($pathPart, 'fixture') !== FALSE) {
+                $isValidPath = FALSE;
+                break;
+            }
+        }
+        unset($pathPart);
+
+        return $isValidPath;
     }

The comment should be the other way around: "Checks that a path does not contain "Fixtures" or "fixtures"."

(BTW, it should be "fixtures" (plural).)

I think the name of the function is a bit too general: This neither makes clear that this is about non-fixture paths nor that this is about test case files.

Instead of exploding the string, you could just check that the string does not contain "/fixtures/".

Updated by Nicole Cordes about 1 year ago

Changed the function and added new tests.

Updated by Oliver Klee about 1 year ago

===================================================================
--- Tests/Unit/Fixtures/Extensions/aaa/Tests/Unit/fixtures/AnotherTest.php    (revision )
+++ Tests/Unit/Fixtures/Extensions/aaa/Tests/Unit/fixtures/AnotherTest.php    (revision )
@@ -0,0 +1,35 @@
+<?php
+/***************************************************************
+* Copyright notice
+*
+* (c) 2011-2012 Oliver Klee (typo3-coding@oliverklee.de)

For files which you're created, please enter yourself as the copyright owner and change the copyright from 2011-2012 to just 2012.

+/**
+ * This is another fixture testcase used for testing data providers.

This looks like a copy'n'paste error.

Ditto for the other new class.

===================================================================
--- Tests/Unit/Service/TestFinderTest.php    (revision 61714)
+++ Tests/Unit/Service/TestFinderTest.php    (revision )
@@ -91,6 +91,9 @@
         if (!class_exists($className, FALSE)) {
             eval(
                 'class ' . $className . ' extends Tx_Phpunit_Service_TestFinder {' .
+                '  public function isNotFixturesPath($path) {' .
+                '    return TRUE;' .
+                '  }' .

Can we somehow get around to 1. overwriting and 2. mocking the new protected function (e.g., by having more fixture classes)?

+    /**
+     * @test
+     */
+    public function findTestCaseFilesDirectoryRemovesFixtureClassesWithUppercasePath() {

Concerning the naming: I'd prefer "NotFinds" over "Removes" because "Removes" assumes that it has been there in the first place.

Ditto for the other tests.

     /**
      * @test
      */
+    public function findTestCaseFilesDirectoryRemovesFixtureClassesWithLowercasePath() {
+        if (!t3lib_extMgm::isLoaded('aaa')) {
+            $this->markTestSkipped(
+                'This test can only be run if the extension "aaa" from Tests/Unit/Fixtures/Extensions/ is installed.'
+            );
+        }
+
+        $path = t3lib_extMgm::extPath('aaa') . 'Tests/Unit/';
+        $fileName1 = 'OneTest.php';
+        $fileName2 = 'AnotherTest.php';
+
+        /** @var $fixture Tx_Phpunit_Service_TestFinder|PHPUnit_Framework_MockObject_MockObject */
+        $fixture = $this->getMock('Tx_Phpunit_Service_TestFinder', array('dummy'));
+
+        $this->assertContains(
+            $fileName1,
+            $fixture->findTestCaseFilesDirectory($path)
+        );
+        $this->assertNotContains(
+            $fileName2,
+            $fixture->findTestCaseFilesDirectory($path)
+        );
+    }

Please split this into two tests.

BTW, you don't need to use mocks in the tests if you're not using any mocked methods.

+    /**
+     * Checks that a path does not contain "Fixtures" or "fixtures".
+     *
+     * @param string $path the absolute path of a file to check
+     *
+     * @return boolean TRUE if $fileName is a valid testcase path, FALSE otherwise
+     */
+    protected function isNotFixturesPath($path) {
+        return (stristr($path, '/fixtures/') === FALSE);
     }

I'd prefer the name "isNonFixturePath".

Updated by Oliver Klee 10 months ago

  • Target version changed from 3.6.11 to 3.6.12

Nicole, can we still get this into 3.6.11? I'd like to do the release in a few days.

Updated by Oliver Klee 10 months ago

  • Target version changed from 3.6.12 to 3.6.11

Updated by Gerrit Code Review 10 months ago

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

Updated by Nicole Cordes 10 months ago

  • Status changed from Accepted to Under Review

Updated by Gerrit Code Review 10 months ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/12913

Updated by Gerrit Code Review 10 months ago

Patch set 3 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/12913

Updated by Nicole Cordes 10 months ago

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

Also available in: Atom PDF