Solucionado (ver solução)
Solucionado
(ver solução)
4
respostas

Erro execução phpUnit

Ao instalar o PHPUnit obtive estes warnings. Vi no google que ocorrem devido a versão do PHP 7.4, mas no site do autor ele diz q há suporte para a versão. Observação: Estes erros ocorreram com meu código, então executei o do prof e o erro se repetiu.

Alguma luz?

C:\Alura_TDD_PHP_prof>vendor\bin\phpunit --version
PHPUnit 8.0.0 by Sebastian Bergmann and contributors.


C:\Alura_TDD_PHP_prof>phpunit test
PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277
PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285
PHPUnit 3.7.21 by Sebastian Bergmann.

Class 'test' could not be found in 'test.php'.

C:\Alura_TDD_PHP_prof>phpunit tests
PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277
PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285
PHP Fatal error:  Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php:11
Stack trace:
#0 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(92): include_once()
#1 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(76): PHPUnit_Util_Fileloader::load('C:\\Alura_TDD_PH...')
#2 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(355): PHPUnit_Util_Fileloader::checkAndLoad('C:\\Alura_TDD_PH...')
#3 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('C:\\Alura_TDD_PH...')
#4 C:\xampp\php\pear\PHPUnit\Runner\BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#5 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(149): PHPUnit_Runner_BaseTestRunner->getTest('tests', '', Array)
#6 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#7 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
#8 {main}
  thrown in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php on line 11

Fatal error: Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php:11
Stack trace:
#0 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(92): include_once()
#1 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(76): PHPUnit_Util_Fileloader::load('C:\\Alura_TDD_PH...')
#2 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(355): PHPUnit_Util_Fileloader::checkAndLoad('C:\\Alura_TDD_PH...')
#3 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('C:\\Alura_TDD_PH...')
#4 C:\xampp\php\pear\PHPUnit\Runner\BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#5 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(149): PHPUnit_Runner_BaseTestRunner->getTest('tests', '', Array)
#6 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#7 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
#8 {main}
  thrown in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php on line 11

C:\Alura_TDD_PHP_prof>php --version
PHP 7.4.2 (cli) (built: Jan 21 2020 17:52:43) ( ZTS Visual C++ 2017 x64 )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
4 respostas

Olá, Fabiana.

Atualizar o PHPUnit para a versão 9 (mais recente) provavelmente vai resolver.

Basta atualizar o require do seu composer.json para algo como:

"phpunit/phpunit": ">9.0"

E depois executar composer update

Bom dia Vinícius, grata pelo retorno. Em minha primeira tentativa com meu código, já era a versão 9 e ocorreu o mesmo erro, por isto tentei executar seu código. Alguma ideia de como resolver?

C:\Alura_TDD_PHP_prof>vendor\bin\phpunit --versionPHPUnit 9.1.2 by Sebastian Bergmann and contributors.

C:\Alura_TDD_PHP_prof>phpunit tests
PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 277PHP Warning:  "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in C:\xampp\php\pear\PHPUnit\TextUI\Command.php on line 285
PHP Fatal error:  Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php:11
Stack trace:
#0 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(92): include_once()
#1 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(76): PHPUnit_Util_Fileloader::load('C:\\Alura_TDD_PH...')
#2 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(355): PHPUnit_Util_Fileloader::checkAndLoad('C:\\Alura_TDD_PH...')
#3 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('C:\\Alura_TDD_PH...')
#4 C:\xampp\php\pear\PHPUnit\Runner\BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#5 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(149): PHPUnit_Runner_BaseTestRunner->getTest('tests', '', Array)
#6 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#7 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
#8 {main}
  thrown in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php on line 11

Fatal error: Uncaught Error: Class 'PHPUnit\Framework\TestCase' not found in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php:11
HP_
prof\tests\Service\AvaliadorTest.php:11
Stack trace:                                                                               ura_TDD_PH...')
#0 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(92): include_once()                       dLoad('C:\\Alura_TDD_PH...')
#1 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(76): PHPUnit_Util_Fileloader::load('C:\\AlTestFile('C:\\Alura_TDD_PH...')
ura                                                                                        dTestFiles(Array)
_TDD_PH...')                                                                               t('tests', '', Array)
#2 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(355): PHPUnit_Util_Fileloader::checkAnue)
dLo
ad('C:\\Alura_TDD_PH...')
#1 C:\xampp\php\pear\PHPUnit\Util\Fileloader.php(76): PHPUnit_Util_Fileloader::load('C:\\Alura_TDD_PH...')
#2 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(355): PHPUnit_Util_Fileloader::checkAndLoad('C:\\Alura_TDD_PH...')
#3 C:\xampp\php\pear\PHPUnit\Framework\TestSuite.php(416): PHPUnit_Framework_TestSuite->addTestFile('C:\\Alura_TDD_PH...')
#4 C:\xampp\php\pear\PHPUnit\Runner\BaseTestRunner.php(96): PHPUnit_Framework_TestSuite->addTestFiles(Array)
#5 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(149): PHPUnit_Runner_BaseTestRunner->getTest('tests', '', Array)
#6 C:\xampp\php\pear\PHPUnit\TextUI\Command.php(129): PHPUnit_TextUI_Command->run(Array, true)
#7 C:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
#8 {main}
  thrown in C:\Alura_TDD_PHP_prof\tests\Service\AvaliadorTest.php on line 11

C:\Alura_TDD_PHP_prof>
solução!

Fabiana, eu não tinha reparado...

Você executa vendor\bin\phpunit --version pra obter a versão, mas executa phpunit para rodar os testes.

Aparentemente você tem uma versão antiga do PHPUnit instalada globalmente na sua máquina.

Execute os testes com vendor\bin\phpunit tests e me diz se funciona.

Vinícius, muito obrigada, era isso! Eu nunca iria descobrir sozinha. Quanto mais aprendo, mais percebo que tenho muito a aprender. Go on...