Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPUnit >= 5 compatibility #44

Closed
francescozanoni opened this issue Jan 16, 2020 · 3 comments
Closed

PHPUnit >= 5 compatibility #44

francescozanoni opened this issue Jan 16, 2020 · 3 comments

Comments

@francescozanoni
Copy link

Hi, man.
Currently only PHPUnit < 5 is supported out-of-the-box.
My VERY DIRTY solution is the following script, executed after each composer install and composer update:

<?php
/**
 * Zend_Test_PHPUnit fix for PHPUnit > 4
 *
 * This fix is required because PHPUnit > 4 uses namespaces.
 *
 * @author Francesco Zanoni
 * @version 2020-01-05
 */

$basePath = realpath(__DIR__ . "/../vendor/shardj/zf1-future/library/Zend/Test/PHPUnit");

// ########################################################################

$filePath = $basePath . "/ControllerTestCase.php";

file_put_contents(
    $filePath,
    str_replace(
        [
            "/** @see Zend_Controller_Front */",
            "require_once 'Zend/Controller/Front.php';",
            "/** @see Zend_Controller_Action_HelperBroker */",
            "require_once 'Zend/Controller/Action/HelperBroker.php';",
            "/** @see Zend_Layout */",
            "require_once 'Zend/Layout.php';",
            "/** @see Zend_Session */",
            "require_once 'Zend/Session.php';",
            "/** @see Zend_Registry */",
            "require_once 'Zend/Registry.php';",
            "require_once 'Zend/Exception.php';",
            "require_once 'Zend/Loader.php';",
            "require_once 'Zend/Test/PHPUnit/Constraint/DomQuery.php';",
            "require_once 'Zend/Test/PHPUnit/Constraint/Redirect.php';",
            "require_once 'Zend/Test/PHPUnit/Constraint/ResponseHeader.php';",
            "require_once 'Zend/Controller/Request/HttpTestCase.php';",
            "require_once 'Zend/Dom/Query.php';",
        ],
        '',
        file_get_contents($filePath)
    )
);

file_put_contents(
    $filePath,
    str_replace(
        ' extends PHPUnit_Framework_TestCase',
        ' extends \\PHPUnit\\Framework\\TestCase',
        file_get_contents($filePath)
    )
);

file_put_contents(
    $filePath,
    str_replace(
        ' instanceof PHPUnit_Framework_TestCase',
        ' instanceof \\PHPUnit\\Framework\\TestCase',
        file_get_contents($filePath)
    )
);

file_put_contents(
    $filePath,
    str_replace(
        'PHPUnit_Runner_Version',
        '\\PHPUnit\\Runner\\Version',
        file_get_contents($filePath)
    )
);

file_put_contents(
    $filePath,
    str_replace(
        'new Zend_Test_PHPUnit_Constraint_DomQuery(',
        'new Zend_Test_PHPUnit_Constraint_DomQuery41(',
        file_get_contents($filePath)
    )
);

file_put_contents(
    $filePath,
    str_replace(
        'new Zend_Test_PHPUnit_Constraint_Redirect(',
        'new Zend_Test_PHPUnit_Constraint_Redirect41(',
        file_get_contents($filePath)
    )
);

file_put_contents(
    $filePath,
    str_replace(
        'new Zend_Test_PHPUnit_Constraint_ResponseHeader(',
        'new Zend_Test_PHPUnit_Constraint_ResponseHeader41(',
        file_get_contents($filePath)
    )
);

// ########################################################################

$filePath = $basePath . "/Constraint/DomQuery41.php";

file_put_contents(
    $filePath,
    str_replace(
        'extends PHPUnit_Framework_Constraint',
        'extends \\PHPUnit\\Framework\\Constraint\\Constraint',
        file_get_contents($filePath)
    )
);

// ########################################################################

$filePath = $basePath . "/Constraint/Redirect41.php";

file_put_contents(
    $filePath,
    str_replace(
        'extends PHPUnit_Framework_Constraint',
        'extends \\PHPUnit\\Framework\\Constraint\\Constraint',
        file_get_contents($filePath)
    )
);

// ########################################################################

$filePath = $basePath . "/Constraint/ResponseHeader41.php";

file_put_contents(
    $filePath,
    str_replace(
        'extends PHPUnit_Framework_Constraint',
        'extends \\PHPUnit\\Framework\\Constraint\\Constraint',
        file_get_contents($filePath)
    )
);

// ########################################################################

$filePath = $basePath . "/Constraint/Exception.php";

file_put_contents(
    $filePath,
    str_replace(
        'extends PHPUnit_Framework_ExpectationFailedException',
        'extends \\PHPUnit\\Framework\\ExpectationFailedException',
        file_get_contents($filePath)
    )
);

Couldn't this be achieved in a more elegant and convenient way? Any advice is welcome.

Thanks in advance!

Francesco

@Shardj
Copy link
Owner

Shardj commented Jan 20, 2020

We just bootstrap with this file:

<?php

define('TEST_EXECUTION', true);

require_once dirname(__FILE__) . '/../..' . '/app-loader.php';
class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase {}

I'm not really sure as to what you're doing with all of that to be honest.

@francescozanoni
Copy link
Author

francescozanoni commented Jan 20, 2020

Thank you soooooooooo much, I only needed this:

class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase {}
class PHPUnit_Runner_Version extends \PHPUnit\Runner\Version {}
abstract class PHPUnit_Framework_Constraint extends \PHPUnit\Framework\Constraint\Constraint {}
abstract class PHPUnit_Framework_ExpectationFailedException extends \PHPUnit\Framework\ExpectationFailedException {}

:-)

@ikari-pl
Copy link

@francescozanoni I'll just leave a note that in PHPUnit 8:

Fatal error: Class PHPUnit_Runner_Version may not inherit from final class (PHPUnit\Runner\Version) 
Fatal error: Class PHPUnit_Framework_ExpectationFailedException may not inherit from final class (PHPUnit\Framework\ExpectationFailedException) 

as I'm trying to find a combination of patches and placeholders for me to work :(

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

No branches or pull requests

3 participants