sebastianbergmann / phpunit

The PHP Unit Testing framework.
https://phpunit.de/
BSD 3-Clause "New" or "Revised" License
19.67k stars 2.2k forks source link

Updating from 5.7.5 to 5.7.6 causes error #2432

Closed tarlepp closed 7 years ago

tarlepp commented 7 years ago

With symfony project after updating to newer version I get following when I run phpunit

PHP Fatal error:  Uncaught Error: Call to undefined method PHPUnit_Util_Configuration::getTestdoxGroupConfiguration() in /home/wunder/projects/symfony-backend/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:1042
Stack trace:
#0 /home/wunder/projects/symfony-backend/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(163): PHPUnit_TextUI_TestRunner->handleConfiguration(Array)
#1 /usr/share/php/PHPUnit/TextUI/Command.php(155): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array)
#2 /usr/share/php/PHPUnit/TextUI/Command.php(106): PHPUnit_TextUI_Command->run(Array, true)
#3 /usr/bin/phpunit(29): PHPUnit_TextUI_Command::main()
#4 {main}
  thrown in /home/wunder/projects/symfony-backend/vendor/phpunit/phpunit/src/TextUI/TestRunner.php on line 1042

How to make this happen, just clone my repo and update composer.json to use newer version.

sebastianbergmann commented 7 years ago

The method exists, see https://github.com/sebastianbergmann/phpunit/blob/5.7.6/src/Util/Configuration.php#L289

Are you sure you are not mixing different versions of PHPUnit (global vs. PHAR vs. Composer-installed)?

sebastianbergmann commented 7 years ago

I tried to reproduce this but your testsuite does not work for me:

$ git clone git@github.com:tarlepp/symfony-backend.git
Cloning into 'symfony-backend'...
remote: Counting objects: 5757, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5757 (delta 0), reused 0 (delta 0), pack-reused 5753
Receiving objects: 100% (5757/5757), 964.12 KiB | 478.00 KiB/s, done.
Resolving deltas: 100% (3445/3445), done.
Checking connectivity... done.

$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 88 installs, 0 updates, 0 removals
  - Installing ocramius/package-versions (1.1.2) Downloading: 100%         
  - Installing doctrine/lexer (v1.0.1) Downloading: 100%         
  - Installing doctrine/annotations (v1.3.1) Downloading: 100%         
  - Installing doctrine/collections (v1.4.0) Downloading: 100%         
  - Installing symfony/polyfill-mbstring (v1.3.0) Loading from cache
  - Installing twig/twig (v2.1.0) Downloading: 100%         
  - Installing symfony/polyfill-util (v1.3.0) Downloading: 100%         
  - Installing paragonie/random_compat (v2.0.4) Downloading: 100%         
  - Installing symfony/polyfill-php70 (v1.3.0) Downloading: 100%         
  - Installing symfony/polyfill-php56 (v1.3.0) Downloading: 100%         
  - Installing symfony/symfony (v3.2.2) Downloading: 100%         
  - Installing symfony/polyfill-intl-icu (v1.3.0) Downloading: 100%         
  - Installing psr/log (1.0.2) Loading from cache
  - Installing psr/cache (1.0.1) Loading from cache
  - Installing doctrine/inflector (v1.1.0) Downloading: 100%         
  - Installing doctrine/cache (v1.6.1) Loading from cache
  - Installing doctrine/common (v2.7.2) Downloading: 100%         
  - Installing doctrine/doctrine-cache-bundle (1.3.0) Downloading: 100%         
  - Installing zendframework/zend-eventmanager (3.1.0) Downloading: 100%         
  - Installing zendframework/zend-code (3.1.0) Downloading: 100%         
  - Installing ocramius/proxy-manager (2.0.4) Downloading: 100%         
  - Installing doctrine/dbal (v2.5.9) Downloading: 100%         
  - Installing doctrine/migrations (v1.5.0) Downloading: 100%         
  - Installing jdorn/sql-formatter (v1.2.17) Downloading: 100%         
  - Installing doctrine/doctrine-bundle (1.6.7) Downloading: 100%         
  - Installing doctrine/doctrine-migrations-bundle (v1.2.1) Downloading: 100%         
  - Installing namshi/jose (7.2.3) Downloading: 100%         
  - Installing lexik/jwt-authentication-bundle (v2.1.1) Downloading: 100%         
  - Installing doctrine/instantiator (1.0.5) Loading from cache
  - Installing doctrine/orm (v2.5.6) Downloading: 100%         
  - Installing gesdinet/jwt-refresh-token-bundle (v0.1.8) Downloading: 100%         
  - Installing gfreeau/get-jwt-bundle (dev-master 7444d2b) Cloning 7444d2b2fa from cache
  - Installing incenteev/composer-parameter-handler (v2.1.2) Loading from cache
  - Installing jms/metadata (1.6.0) Downloading: 100%         
  - Installing phpoption/phpoption (1.5.0) Downloading: 100%         
  - Installing jms/parser-lib (1.0.0) Downloading: 100%         
  - Installing phpcollection/phpcollection (0.5.0) Downloading: 100%         
  - Installing jms/serializer (1.4.2) Downloading: 100%         
  - Installing jms/serializer-bundle (1.1.0) Downloading: 100%         
  - Installing behat/transliterator (v1.1.0) Loading from cache
  - Installing knplabs/doctrine-behaviors (1.4.0) Downloading: 100%         
  - Installing matthiasnoback/symfony-console-form (v2.1.0) Downloading: 100%         
  - Installing michelf/php-markdown (1.7.0) Downloading: 100%         
  - Installing nelmio/api-doc-bundle (dev-master b01128d) Cloning b01128dc13 from cache
  - Installing nelmio/cors-bundle (1.5.1) Downloading: 100%         
  - Installing mustangostang/spyc (0.6.1) Loading from cache
  - Installing piwik/device-detector (3.7.5) Loading from cache
  - Installing ramsey/uuid (3.5.2) Downloading: 100%         
  - Installing sensiolabs/security-checker (v4.0.0) Downloading: 100%         
  - Installing sensio/distribution-bundle (v5.0.18) Downloading: 100%         
  - Installing sensio/framework-extra-bundle (v3.0.19) Downloading: 100%         
  - Installing monolog/monolog (1.22.0) Loading from cache
  - Installing symfony/monolog-bundle (v3.0.3) Downloading: 100%         
  - Installing swiftmailer/swiftmailer (v5.4.5) Downloading: 100%         
  - Installing symfony/swiftmailer-bundle (v2.4.2) Downloading: 100%         
  - Installing doctrine/data-fixtures (v1.2.2) Downloading: 100%         
  - Installing doctrine/doctrine-fixtures-bundle (2.3.0) Downloading: 100%         
  - Installing webmozart/assert (1.2.0) Loading from cache
  - Installing phpdocumentor/reflection-common (1.0) Loading from cache
  - Installing phpdocumentor/type-resolver (0.2.1) Loading from cache
  - Installing phpdocumentor/reflection-docblock (3.1.1) Loading from cache
  - Installing sebastian/recursion-context (2.0.0) Loading from cache
  - Installing sebastian/exporter (2.0.0) Loading from cache
  - Installing sebastian/diff (1.4.1) Loading from cache
  - Installing sebastian/comparator (1.2.2) Loading from cache
  - Installing phpspec/prophecy (v1.6.2) Loading from cache
  - Installing phpspec/php-diff (v1.1.0) Downloading: 100%         
  - Installing phpspec/phpspec (3.2.2) Downloading: 100%         
  - Installing phpunit/php-token-stream (1.4.9) Loading from cache
  - Installing sebastian/version (2.0.1) Loading from cache
  - Installing sebastian/resource-operations (1.0.0) Loading from cache
  - Installing sebastian/object-enumerator (2.0.0) Loading from cache
  - Installing sebastian/global-state (1.1.1) Loading from cache
  - Installing sebastian/environment (2.0.0) Loading from cache
  - Installing phpunit/php-text-template (1.2.1) Loading from cache
  - Installing phpunit/phpunit-mock-objects (3.4.3) Loading from cache
  - Installing phpunit/php-timer (1.0.8) Loading from cache
  - Installing phpunit/php-file-iterator (1.4.2) Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.0) Loading from cache
  - Installing phpunit/php-code-coverage (4.0.5) Loading from cache
  - Installing myclabs/deep-copy (1.5.5) Loading from cache
  - Installing phpunit/phpunit (5.7.5) Loading from cache
  - Installing guzzle/guzzle (v3.8.1) Downloading: 100%         
  - Installing satooshi/php-coveralls (v1.0.1) Downloading: 100%         
  - Installing sensio/generator-bundle (v3.1.2) Downloading: 100%         
  - Installing squizlabs/php_codesniffer (2.7.1) Loading from cache
  - Installing symfony/phpunit-bridge (v3.2.2) Downloading: 100%         
paragonie/random_compat suggests installing ext-libsodium (Provides a modern crypto API that can be used to generate random bytes.)
doctrine/doctrine-cache-bundle suggests installing symfony/security-acl (For using this bundle to cache ACLs)
zendframework/zend-eventmanager suggests installing container-interop/container-interop (^1.1.0, to use the lazy listeners feature)
zendframework/zend-eventmanager suggests installing zendframework/zend-stdlib (^2.7.3 || ^3.0, to use the FilterChain feature)
zendframework/zend-code suggests installing zendframework/zend-stdlib (Zend\Stdlib component)
ocramius/proxy-manager suggests installing ocramius/generated-hydrator (To have very fast object to array to object conversion for ghost objects)
ocramius/proxy-manager suggests installing zendframework/zend-json (To have the JsonRpc adapter (Remote Object feature))
ocramius/proxy-manager suggests installing zendframework/zend-soap (To have the Soap adapter (Remote Object feature))
ocramius/proxy-manager suggests installing zendframework/zend-xmlrpc (To have the XmlRpc adapter (Remote Object feature))
namshi/jose suggests installing phpseclib/phpseclib (Allows to use Phpseclib as crypto engine, use version ^2.0.)
lexik/jwt-authentication-bundle suggests installing lcobucci/jwt (For using the LcobucciJWTEncoder)
lexik/jwt-authentication-bundle suggests installing spomky-labs/lexik-jose-bridge (Provides a JWT Token encoder with encryption support)
jms/serializer-bundle suggests installing jms/di-extra-bundle (Required to get lazy loading (de)serialization visitors, ~1.3)
nelmio/api-doc-bundle suggests installing dunglas/api-bundle (For making use of resources definitions of DunglasApiBundle.)
nelmio/api-doc-bundle suggests installing friendsofsymfony/rest-bundle (For making use of REST information in the doc.)
ramsey/uuid suggests installing ext-libsodium (Provides the PECL libsodium extension for use with the SodiumRandomGenerator)
ramsey/uuid suggests installing ext-uuid (Provides the PECL UUID extension for use with the PeclUuidTimeGenerator and PeclUuidRandomGenerator)
ramsey/uuid suggests installing ircmaxell/random-lib (Provides RandomLib for use with the RandomLibAdapter)
ramsey/uuid suggests installing moontoast/math (Provides support for converting UUID to 128-bit integer (in string form).)
ramsey/uuid suggests installing ramsey/uuid-console (A console application for generating UUIDs with ramsey/uuid)
ramsey/uuid suggests installing ramsey/uuid-doctrine (Allows the use of Ramsey\Uuid\Uuid as Doctrine field type.)
sensio/framework-extra-bundle suggests installing symfony/psr-http-message-bridge (To use the PSR-7 converters)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
monolog/monolog suggests installing doctrine/couchdb (Allow sending log messages to a CouchDB server)
monolog/monolog suggests installing ext-amqp (Allow sending log messages to an AMQP server (1.0+ required))
monolog/monolog suggests installing ext-mongo (Allow sending log messages to a MongoDB server)
monolog/monolog suggests installing graylog2/gelf-php (Allow sending log messages to a GrayLog2 server)
monolog/monolog suggests installing mongodb/mongodb (Allow sending log messages to a MongoDB server via PHP Driver)
monolog/monolog suggests installing php-amqplib/php-amqplib (Allow sending log messages to an AMQP server using php-amqplib)
monolog/monolog suggests installing php-console/php-console (Allow sending log messages to Google Chrome)
monolog/monolog suggests installing rollbar/rollbar (Allow sending log messages to Rollbar)
monolog/monolog suggests installing ruflin/elastica (Allow sending log messages to an Elastic Search server)
monolog/monolog suggests installing sentry/sentry (Allow sending log messages to a Sentry server)
doctrine/data-fixtures suggests installing doctrine/mongodb-odm (For loading MongoDB ODM fixtures)
doctrine/data-fixtures suggests installing doctrine/phpcr-odm (For loading PHPCR ODM fixtures)
phpspec/phpspec suggests installing phpspec/nyan-formatters (Adds Nyan formatters)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Generating autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Creating the "app/config/parameters.yml" file
Some parameters are missing. Please provide them.
database_host (127.0.0.1): 
database_port (null): 
database_name (symfony): 
database_user (root): 
database_password (null): 
mailer_transport (smtp): 
mailer_host (127.0.0.1): 
mailer_user (null): 
mailer_password (null): 
secret (ThisTokenIsNotSoSecretChangeIt): 
jwt_private_key_path ('%kernel.root_dir%/var/jwt/private.pem'): 
jwt_public_key_path ('%kernel.root_dir%/var/jwt/public.pem'): 
jwt_key_pass_phrase (''): 
jwt_token_ttl (86400): 
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache

 // Clearing the cache for the dev environment with debug                       
 // true                                                                        

 [OK] Cache for the "dev" environment (debug=true) was successfully cleared.    

> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets

 Trying to install assets as relative symbolic links.

 --- -------------------- ------------------ 
      Bundle               Method / Error    
 --- -------------------- ------------------ 
  ✔   NelmioApiDocBundle   relative symlink  
 --- -------------------- ------------------ 

 [OK] All assets were successfully installed.                                   

> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget

$ ./vendor/bin/phpunit
PHP Fatal error:  Uncaught Symfony\Component\Config\Exception\FileLocatorFileNotFoundException: The file "parameters_test.yml" does not exist (in: /home/sb/symfony-backend/app/config). in /home/sb/symfony-backend/vendor/symfony/symfony/src/Symfony/Component/Config/FileLocator.php:71
Stack trace:
#0 /home/sb/symfony-backend/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Config/FileLocator.php(54): Symfony\Component\Config\FileLocator->locate('parameters_test...', '/home/sb/symfon...', false)
#1 /home/sb/symfony-backend/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php(86): Symfony\Component\HttpKernel\Config\FileLocator->locate('parameters_test...', '/home/sb/symfon...', false)
#2 /home/sb/symfony-backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php(130): Symfony\Component\Config\Loader\FileLoader->import('parameters_test...', NULL, false, '/home/sb/symfon...')
#3 /home/sb/symfony-backend/vendor/symfony/symfony/src/Symfony/Component/DependencyInjecti in /home/sb/symfony-backend/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php on line 118
micheleangioni commented 7 years ago

Hi @sebastianbergmann , the same happens to me: Failing Travis build

GrahamCampbell commented 7 years ago

That bug is happening because you are running phpunit instead of vendor/bin/phpunit, so you are getting the global travis provided phpunit.

stelgenhof commented 7 years ago

Also happens to me too: https://travis-ci.org/azuyalabs/yasumi/jobs/194677221 Guess better not rely on the Travis provided phpunit, rather use the Composer-installed version :)

sebastianbergmann commented 7 years ago

If you install PHPUnit via Composer and use the autoloader generated by Composer then you must not invoke PHPUnit using an executable other than vendor/bin/phpunit.

remicollet commented 7 years ago

@sebastianbergmann perhaps it could be possible to redirect from the launcher.

As we have such issue in the Fedora package, we use a workaround.

if (file_exists('./vendor/phpunit/phpunit/phpunit') && file_exists('./vendor/autoload.php')) {
  echo "\n==== Redirecting to composer installed version in vendor/phpunit ====\n\n";
  define ('PHPUNIT_COMPOSER_INSTALL', realpath('./vendor/autoload.php'));
} else {
   // default autoloader
sebastianbergmann commented 7 years ago

Sorry, @remicollet, but I am not convinced that such a workaround would be a good idea. Feel free to convince me in a new ticket :-)

remicollet commented 7 years ago

well... I use "phpunit" global command daily, including in projects which have phpunit in their "require-dev" dependencies without any issue ;)

Will see if I can write something an submit a PR

jeromegamez commented 7 years ago

I don't know if this is a bad practice, but instead of maintaining a global PHPUnit instance, I have prepended bin and vendor/bin to the $PATH variable, which has the benefit of always using the PHPUnit version "meant" for the project I'm currently in (and applies to any dependency, not just PHPUnit).

# notice the missing slashes at the beginning, 
# making the paths relative to the current dir
export PATH="bin:vendor/bin:$PATH"
micheleangioni commented 7 years ago

Thanks @GrahamCampbell to let me notice I was unintentionally using the global phpunit in that repo.

tarlepp commented 7 years ago

@sebastianbergmann yeah actually my dev environment did use global phpunit and not locally installed one and that was the problem.

februml commented 7 years ago

@jeromegamez comment makes me the most sense and don't think it's a bad practice

madmax1111 commented 7 years ago

I am having the same #2432 problem but it is not solved yet. composer.json { "require": { }, "require-dev": { "phpunit/phpunit": "*" }, "autoload": { "psr-0": { "mykidsapi": "" } } }

-------------phpunit.xml--------------

<?xml version="1.0" enoding="UTF-8"?>

./Test/

--------------------Baseball.php--------------

<?php namespace mykidsapi;

class Baseball { public function calc_avg($ab,$hits) { if($ab == 0) { $avg = "0.000"; } else { $avg = $hits/$ab; } return $avg; } }

-----------------BasebalTest.php------------------------

<?php

namespace mykydsapi\Test;

use mykydsapi\Baseball;

class BaseballTest extends \PHPUnit_Framework_TestCase { public function testCalcAvgEquals() { $atbats = 389; $hits = 129; $baseball = new Baseball(); $result = $baseball->calc_avg($atbats,$hits); $expectedresults = $hits/$atbats; $this->assertEquals($expectedresult,$results); } }