Autoloading classes in PHPUnit using Composer and autoload.php

后端 未结 5 1779
轻奢々
轻奢々 2020-11-30 21:41

I have just installed PHPUnit version 3.7.19 by Sebastian Bergmann via Composer and have written a class I would like to unit test.

I would like to have all my class

5条回答
  •  天涯浪人
    2020-11-30 22:27

    If you are using PHPUnit 7 you can make your classes from src/ folder to autoload in tests like this:

    1. Ensure that your composer.json file looks similar to this:

      {
          "autoload": {
              "classmap": [
                  "src/"
              ]
          },
          "require-dev": {
              "phpunit/phpunit": "^7"
          }
      }
      
    2. To apply changes in composer.json run command:

      composer install
      
    3. Finally you can run tests in tests/ folder:

      ./vendor/bin/phpunit tests/
      

提交回复
热议问题