Project

General

Profile

Actions

Feature #69643

closed

Unit Tests can not be executed in "composer mode" projects

Added by most wanted about 9 years ago. Updated about 6 years ago.

Status:
Closed
Priority:
Could have
Assignee:
-
Category:
composer
Target version:
-
Start date:
2015-09-10
Due date:
% Done:

0%

Estimated time:
PHP Version:
5.5
Tags:
Complexity:
Sprint Focus:

Description

I am not sure if I found a bug/missing feature - this should be possible, right?

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://composer.typo3.org/" 
        }
    ],
    "require": {
        "typo3/cms": "7.4.0" 
    },
    "require-dev": {
        "phpunit/phpunit": "~4.7.0" 
    },
    "config": {
        "bin-dir": "bin" 
    }
}
composer install
./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml

This leads to this error message:

Fatal error: Class 'TYPO3\CMS\Core\Tests\UnitTestCase' not found in /Users/mostwanted/Projects/_sandbox/MyProject/typo3_src/typo3/sysext/backend/Tests/Unit/Configuration/TypoScript/ConditionMatching/ConditionMatcherTest.php on line 23

On the other hand this is working properly:

git clone git://git.typo3.org/Packages/TYPO3.CMS.git
cd TYPO3.CMS
git checkout 7.4.0
composer install
./bin/phpunit -c typo3/sysext/core/Build/UnitTests.xml
Actions #1

Updated by most wanted about 9 years ago

This also leads to an error message:

composer.json

{
    "repositories": [
        {
            "type": "composer",
            "url": "https://composer.typo3.org/" 
        }
    ],
    "require": {
        "typo3/cms": "7.4.0",
        "typo3-ter/news": "*" 
    },
    "require-dev": {
        "phpunit/phpunit": "~4.7.0" 
    },
    "config": {
        "bin-dir": "bin" 
    }
}

run phpunit

./bin/phpunit --bootstrap ./typo3/sysext/core/Build/UnitTestsBootstrap.php ./typo3conf/ext/news/Tests/Unit/

error message

Fatal error: Class 'TYPO3\CMS\Core\Tests\UnitTestCase' not found in /Users/mostwanted/Projects/_sandbox/MyProject/typo3conf/ext/news/Tests/Unit/Controller/NewsBaseControllerTest.php on line 26
Actions #2

Updated by Mathias Brodala about 9 years ago

This is the expected behavior since typo3/cms was pulled in as dependency, thus both autoload-dev and require-dev are ignored.

One can do composer create-project typo3/cms:7.4.0 instead which makes typo3/cms the root package.

Alternatively you have to copy/add all necessary autoload-dev and require-dev entries to your root composer.json. This is the way to go if you are trying to integrate tests into a TYPO3 extension.

See this blog entry for some insights.

Actions #3

Updated by Oliver Eglseder about 9 years ago

When you use "require typo3/cms" instead of create-project, you may work around the missing dev Namespaces of the Core and its dev dependencies. Copy the require-dev and autoload-dev part from the core's composer.json to your root composer.json.

Looks like this: (Full list, you may run core unit tests with this)

{
  "repositories": [
    {
      "type": "composer",
      "url": "https://composer.typo3.org/" 
    }
  ],
  "require": {
    "typo3/cms": "7.4.0" 
  },
  "require-dev": {
    "phpunit/phpunit": "~4.7.0",
    "mikey179/vfsStream": "1.4.*@dev",
    "codeception/codeception": "~2.1.0" 
  },
  "config": {
    "bin-dir": "bin" 
  },
  "autoload-dev": {
    "psr-4": {
      "TYPO3\\CMS\\Backend\\Tests\\": "typo3/sysext/backend/Tests/",
      "TYPO3\\CMS\\Belog\\Tests\\": "typo3/sysext/belog/Tests/",
      "TYPO3\\CMS\\Beuser\\Tests\\": "typo3/sysext/beuser/Tests/",
      "TYPO3\\CMS\\Core\\Tests\\": "typo3/sysext/core/Tests/",
      "TYPO3\\CMS\\Dbal\\Tests\\": "typo3/sysext/dbal/Tests/",
      "TYPO3\\CMS\\Documentation\\Tests\\": "typo3/sysext/documentation/Tests/",
      "TYPO3\\CMS\\Extbase\\Tests\\": "typo3/sysext/extbase/Tests/",
      "TYPO3\\CMS\\Extensionmanager\\Tests\\": "typo3/sysext/extensionmanager/Tests/",
      "TYPO3\\CMS\\Felogin\\Tests\\": "typo3/sysext/felogin/Tests/",
      "TYPO3\\CMS\\Fluid\\Tests\\": "typo3/sysext/fluid/Tests/",
      "TYPO3\\CMS\\Form\\Tests\\": "typo3/sysext/form/Tests/",
      "TYPO3\\CMS\\Frontend\\Tests\\": "typo3/sysext/frontend/Tests/",
      "TYPO3\\CMS\\Impexp\\Tests\\": "typo3/sysext/impexp/Tests/",
      "TYPO3\\CMS\\IndexedSearch\\Tests\\": "typo3/sysext/indexed_search/Tests/",
      "TYPO3\\CMS\\Install\\Tests\\": "typo3/sysext/install/Tests/",
      "TYPO3\\CMS\\Lang\\Tests\\": "typo3/sysext/lang/Tests/",
      "TYPO3\\CMS\\Lowlevel\\Tests\\": "typo3/sysext/lowlevel/Tests/",
      "TYPO3\\CMS\\Mediace\\": "typo3/sysext/mediace/Classes/",
      "TYPO3\\CMS\\Mediace\\Tests\\": "typo3/sysext/mediace/Tests/",
      "TYPO3\\CMS\\Recordlist\\Tests\\": "typo3/sysext/recordlist/Tests/",
      "TYPO3\\CMS\\Reports\\Tests\\": "typo3/sysext/reports/Tests/",
      "TYPO3\\CMS\\Rsaauth\\Tests\\": "typo3/sysext/rsaauth/Tests/",
      "TYPO3\\CMS\\Saltedpasswords\\Tests\\": "typo3/sysext/saltedpasswords/Tests/",
      "TYPO3\\CMS\\Scheduler\\Tests\\": "typo3/sysext/scheduler/Tests/",
      "TYPO3\\CMS\\Sv\\Tests\\": "typo3/sysext/sv/Tests/",
      "TYPO3\\CMS\\Workspaces\\Tests\\": "typo3/sysext/workspaces/Tests/" 
    }
  }
}

If you want to run only tests of extensions you have to add any Namepsace from the extension's dependency (like Dbal, Fluid, Extbase...)

Actions #4

Updated by most wanted about 9 years ago

Mathias and Olivers suggested solution works. Thanks.

Still feels suboptimal. Would be great if this would not be necessary. Maybe typo3/sysext/core/Build/UnitTestsBootstrap.php could handle the autoloading of those classes in the future?

So I would still call it a missing feature that would bring a lot convenience.

Actions #5

Updated by Stephan Großberndt about 9 years ago

  • Tracker changed from Bug to Feature
  • Priority changed from Should have to Could have
Actions #6

Updated by Helmut Hummel about 9 years ago

  • Category changed from composer to 1594
  • Status changed from New to Accepted

We should indeed add this section to the base distribution:

https://git.typo3.org/TYPO3CMS/Distributions/Base.git/blob_plain/HEAD:/composer.json

Can somebody push a patch set for that to Gerrit? Thanks.

Actions #7

Updated by Gerrit Code Review about 9 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master of project TYPO3CMS/Distributions/Base has been pushed to the review server.
It is available at http://review.typo3.org/43201

Actions #8

Updated by Gerrit Code Review about 9 years ago

Patch set 2 for branch master of project TYPO3CMS/Distributions/Base has been pushed to the review server.
It is available at http://review.typo3.org/43201

Actions #9

Updated by Wouter Wolters about 9 years ago

  • Status changed from Under Review to Resolved
Actions #10

Updated by Benni Mack about 6 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF