Autoloading classes in PHPUnit using Composer and autoload.php

后端 未结 5 1778
轻奢々
轻奢々 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:23

    There is a really simple way to set up phpunit with autoloading and bootstap. Use phpunit's --generate-configuration option to create your phpunit.xml configuration in a few seconds-:

    vendor/bin/phpunit --generate-configuration
    

    (Or just phpunit --generate-configuration if phpunit is set in your PATH). This option has been available from version phpunit5 and upwards.

    This option will prompt you for your bootstrap file (vendor/autoload.php), tests and source directories. If your project is setup with composer defaults (see below directory structure) the default options will be all you need. Just hit RETURN three times!

    project-dir
       -- src
       -- tests
       -- vendor
    

    You get a default phpunit.xml which is good to go. You can of course edit to include any specialisms (e.g. colors="true") you require-:

    
    
        
            
                tests
            
        
        
            
                src
            
        
    
    

提交回复
热议问题