Skip to content
This repository was archived by the owner on Apr 12, 2018. It is now read-only.

Bootstrap file only loaded if --bootstrap option included on command line #290

Closed
GreeKatrina opened this issue Mar 30, 2015 · 1 comment

Comments

@GreeKatrina
Copy link

My folder structure

tests/
    Controller/
    Library/
    Model/
    MainTest.php
    bootstrap.php
    phpunit.xml
env.php

My phpunit.xml file:

<?xml version="1.0" ?>
<document>
    <phpunit bootstrap="bootstrap.php">
        <testsuites>
            <testsuite name="Library">
              <directory>./Library/</directory>
            </testsuite>
            <testsuite name="Model">
                <directory>./Model/</directory>
            </testsuite>
            <testsuite name="Controller">
                <directory>./Controller/</directory>
            </testsuite>
        </testsuites>
    </phpunit>
</document>

My MainTest.php file:

<?php

class MainTest extends PHPUnit_Framework_TestCase
{
    public function testTestingEnvironment()
    {
        //constants are defined in env.php
        $this->assertTrue(defined(APP_ROOT));
        $this->assertFileExists(VENDOR_PATH.'autoloader.php');
        $this->assertTrue(class_exists('MyApp\Library\Utility'));
    }
}

When I run phpunit --bootstrap bootstrap.php MainTest everything works fine. But since I have included the bootstrap file in my phpunit.xml file, I shouldn't need to do that. However, when I run phpunit MainTest it doesn't include my bootstrap file. It will throw an error that APP_ROOT has not been defined. APP_ROOT is defined in env.php, which is included in the bootstrap.php file.

I would like to be able to run my tests without having to explicitly include my bootstrap file since that functionality is built in.

Thanks in advance for the help.

@sebastianbergmann
Copy link
Owner

Dear contributor,

thanks to the hard work by @belanur, @starikovm, @trueromio, and others, the changes outlined in #471 (comment) have been implemented.

This repository, https://github.com/sebastianbergmann/phpunit-documentation, is now archived and read-only. The documentation for PHPUnit version prior to PHPUnit 7.0 will no longer be changed or updated. It is still hosted at

  • Multiple HTML files: https://phpunit.de/manual/6.5/en/index.html
  • Multiple HTML files (in a .tar.bz2 archive): https://phpunit.de/manual/current/en/download.tar.bz2
  • Single HTML file: https://phpunit.de/manual/current/en/phpunit-book.html
  • PDF: https://phpunit.de/manual/current/en/phpunit-book.pdf
  • ePub: https://phpunit.de/manual/current/en/phpunit-book.epub

Simply replace 6.5 with the version number you are looking for. Simply replace en with fr, pt_br, ja, or zh_cn to access the French, Brazilian Portuguese, Japanese, or Simplified Chinese translation, respectively.

Starting with the documentation for PHPUnit 7.0, the PHPUnit documentation is hosted at https://phpunit.readthedocs.io/.

I am sorry that I have to close this issue here as GitHub does not support moving issues from one project to another. Please open a new ticket for this issue in one of the new issue trackers (see above).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants