N
N
nepster-web2015-12-24 16:37:19
PHP
nepster-web, 2015-12-24 16:37:19

Why does an error occur when phpUnit tests fail?

I'm writing a small console application for testing. I don't use composer. As a training, I decided to work with tests. If the tests run, everything is ok. However, if the tests fail:

1) tests\CrawlerTest::testFunctionBuildUrl
PHP Warning:  require(Composer/Autoload/ClassLoader.php): failed to open stream: No such file or directory in /home/nepster/www/test.ru/bot/vendor/autoload.php on line 18
PHP Fatal error:  require(): Failed opening required 'Composer/Autoload/ClassLoader.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/nepster/www/test.ru/bot/vendor/autoload.php on line 18

To make namespaces work, I connected the following function:
/**
 * PSR-0
 * @param $className
 */
function autoload($className) {
    $className = ltrim($className, '\\');
    $fileName  = '';
    $namespace = '';
    if ($lastNsPos = strrpos($className, '\\')) {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName  = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

    require $fileName;
}

spl_autoload_register('autoload');

Why does phpunit require composer and only if tests fail?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl1m_dogg, 2016-01-05
@sl1m_dogg

well, the composer seems to be the best practice now, so it’s better to use it, but I would also like to see how you run tests for execution

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question