Codeception / Verify

BDD Assertions for PHPUnit and Codeception
MIT License
146 stars 25 forks source link

Warning: Cannot declare class PHPUnit_Framework_Assert #32

Closed silwerclaw closed 7 years ago

silwerclaw commented 7 years ago

Because of latest commit Fix ClassNotFound for PHPUnit > v6 with included in composer dependency codeception/base v.2.3 I get following warning:

Warning: Cannot declare class PHPUnit_Framework_Assert, because the name is already in use in ../vendor/codeception/base/shim.php on line 17

That happens, because file vendor/codeception/base/shim.php checks only for absence of class PHPUnit_Framework_TestCase, creating ALL of related class aliases for phpunit v.6

namespace {
    if (!class_exists('PHPUnit_Framework_TestCase') && class_exists('PHPUnit\Framework\TestCase')) {
        class_alias('PHPUnit\Framework\Assert', 'PHPUnit_Framework_Assert');
        class_alias('PHPUnit\Framework\AssertionFailedError', 'PHPUnit_Framework_AssertionFailedError');
        class_alias('PHPUnit\Framework\Constraint\Constraint', 'PHPUnit_Framework_Constraint');
        class_alias('PHPUnit\Framework\Constraint\LogicalNot', 'PHPUnit_Framework_Constraint_Not');
        class_alias('PHPUnit\Framework\DataProviderTestSuite', 'PHPUnit_Framework_TestSuite_DataProvider');
        class_alias('PHPUnit\Framework\Exception', 'PHPUnit_Framework_Exception');
        class_alias('PHPUnit\Framework\ExceptionWrapper', 'PHPUnit_Framework_ExceptionWrapper');
        class_alias('PHPUnit\Framework\ExpectationFailedException', 'PHPUnit_Framework_ExpectationFailedException');
        class_alias('PHPUnit\Framework\IncompleteTestError', 'PHPUnit_Framework_IncompleteTestError');
        class_alias('PHPUnit\Framework\SelfDescribing', 'PHPUnit_Framework_SelfDescribing');
        class_alias('PHPUnit\Framework\SkippedTestError', 'PHPUnit_Framework_SkippedTestError');
        class_alias('PHPUnit\Framework\Test', 'PHPUnit_Framework_Test');
        class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase');
        class_alias('PHPUnit\Framework\TestFailure', 'PHPUnit_Framework_TestFailure');
        class_alias('PHPUnit\Framework\TestListener', 'PHPUnit_Framework_TestListener');
        class_alias('PHPUnit\Framework\TestResult', 'PHPUnit_Framework_TestResult');
        class_alias('PHPUnit\Framework\TestSuite', 'PHPUnit_Framework_TestSuite');
        class_alias('PHPUnit\Framework\Warning', 'PHPUnit_Framework_Warning');
        class_alias('PHPUnit\Runner\BaseTestRunner', 'PHPUnit_Runner_BaseTestRunner');
        class_alias('PHPUnit\Runner\Filter\Factory', 'PHPUnit_Runner_Filter_Factory');
        class_alias('PHPUnit\Runner\Filter\NameFilterIterator', 'PHPUnit_Runner_Filter_Test');
        class_alias('PHPUnit\Runner\Filter\IncludeGroupFilterIterator', 'PHPUnit_Runner_Filter_Group_Include');
        class_alias('PHPUnit\Runner\Filter\ExcludeGroupFilterIterator', 'PHPUnit_Runner_Filter_Group_Exclude');
        class_alias('PHPUnit\Runner\Version', 'PHPUnit_Runner_Version');
        class_alias('PHPUnit\TextUI\ResultPrinter', 'PHPUnit_TextUI_ResultPrinter');
        class_alias('PHPUnit\TextUI\TestRunner', 'PHPUnit_TextUI_TestRunner');
        class_alias('PHPUnit\Util\Log\JUnit', 'PHPUnit_Util_Log_JUnit');
        class_alias('PHPUnit\Util\Printer', 'PHPUnit_Util_Printer');
        class_alias('PHPUnit\Util\Test', 'PHPUnit_Util_Test');
        class_alias('PHPUnit\Util\TestDox\ResultPrinter', 'PHPUnit_Util_TestDox_ResultPrinter');
        class_alias('PHPUnit\Framework\BaseTestListener', 'PHPUnit_Framework_BaseTestListener');

        require_once __DIR__ . '/phpunit5-loggers.php'; // TAP and JSON loggers were removed in PHPUnit 6
    }
}

Not sure what solutions there can be applied: change check in codeception/base shim.php to look for each class separately, or to make this condition more advanced.

Naktibalda commented 7 years ago

I think that to fix this specific issue it should be enough to add class_exists condition for Assert to https://github.com/Codeception/Codeception/blob/2.3/shim.php#L17

codeception/base is regularly updated from codeception/codeception.

silwerclaw commented 7 years ago

I would better add class_exists() for each entry of class_alias() to prevent such situations in future in codeception/codeception