propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 399 forks source link

fix tests #1748

Closed mringler closed 3 years ago

mringler commented 3 years ago

So, currently all CI tests fail before start (see here). Output looks like this:

> phpunit --colors=always '-c' 'tests/agnostic.phpunit.xml' '--stop-on-error'
Tests started in temp /tmp.

PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
Could not read "tests/agnostic.phpunit.xml".
Script phpunit --colors=always handling the test event returned with error code 2
Script @test -c tests/agnostic.phpunit.xml was called via test:agnostic

Reason for this is that TestPrepareCommand (Propel\Generator\Command\TestPrepareCommand) changes directory when building tests, but does not change back on early return:

    protected function buildFixtures($fixturesDir, $connections, InputInterface $input, OutputInterface $output): int
    {
        chdir($this->root . '/' . $fixturesDir);
        ...
        if ($input->getOption('exclude-database')) {
            return static::CODE_SUCCESS;
        }
        ...
        chdir($this->root);

        return static::CODE_SUCCESS;
    }

So we end up in the wrong directory, and phpunit cannot find the config file.

This bug was created back in 2014 and has been present ever since, but did not show before. Apparently, until now, the fixture that was built last did not use the early return, so the command ultimately left back in the correct working directory.

I could make an educated guess why the order in which Fixtures are built has changed so that the error suddenly showed up in an unrelated PR, but it doesn't matter. Simple solution is to move the chdir() to the end of the command's execute() function, so we are sure we leave at where we entered.

codecov-commenter commented 3 years ago

Codecov Report

Merging #1748 (841fd9e) into master (294de32) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1748   +/-   ##
=========================================
  Coverage     87.86%   87.86%           
  Complexity     7809     7809           
=========================================
  Files           267      267           
  Lines         22480    22480           
=========================================
  Hits          19753    19753           
  Misses         2727     2727           
Flag Coverage Δ
5-max 87.86% <100.00%> (ø)
7.4 87.86% <100.00%> (ø)
agnostic 73.43% <100.00%> (+<0.01%) :arrow_up:
mysql 69.85% <100.00%> (ø)
pgsql 69.84% <100.00%> (ø)
sqlite 67.82% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/Propel/Generator/Command/TestPrepareCommand.php 95.12% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 294de32...841fd9e. Read the comment docs.