Symfony 3 Form Unit Test createMock undefined - phpunit

I'm using symfony 3 and PhpUnit 5.6.4. I'm testing my form with http://symfony.com/doc/master/form/unit_testing.html
My code is here but when I run phpunit I get:
Testing Test Suite
PHP Fatal error: Call to undefined method Tests\AnnBundle\Form\Type\AnnTypeTest::createMock() in /media/mpf/mmf/tests/AnnBundle/Form/Type/AnnTypeTest.php on line 26
PHP Stack trace:
PHP 1. {main}() /media/mpf/mmf/vendor/symfony/phpunit-bridge/bin/.phpunit/phpunit-4.8/phpunit:0
Thanks.

Related

How can we run the unit tests of civicrm from script?

I execute this commande line to run a unit tests :
hatem.hadrich#pc_Hatem_Hadrich:/projet/tools$ php /scripts/phpunit CRM_AllTests
I have this error when i run a unit test from my local instance and i can not find a way to resolve it anyone can help me to fix this bug.
PHP Fatal error: Class 'CiviTestSuite' not found in /projet/../civicrm/tests/phpunit/CRM/AllTests.php on line 39
PHP Stack trace:
PHP 1. {main}() /usr/local/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/local/bin/phpunit:569
PHP 3. PHPUnit_TextUI_Command->run()
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:115
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest()
phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:137
PHP 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass()
phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php:65
PHP 6. PHPUnit_Runner_StandardTestSuiteLoader->load()
phar:///usr/local/bin/phpunit/phpunit/Runner/BaseTestRunner.php:124
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() phar:///usr/local/bin/phpunit/phpunit/Runner/StandardTestSuiteLoader.php:39
PHP 8. PHPUnit_Util_Fileloader::load() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:38
PHP 9. include_once() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:56
i have find a way to fix this bug, you must require_one for the bootstrap file inside CiviTest :
define('DRUPAL_ROOT', '/path_to_project');
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

Laravel Homestead new project error

On my Win8 machine I installed Laravel Homestead box using git. (OracleVM+Vagrant).
Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: newProject.local
to: /home/vagrant/Code/newProject/public
databases:
- homestead
I start the VM using:
cd Homestead
vagrant up
vagrant ssh
And everything works.
If I understand correctly, I still need to create a newProject in my Code/ folder.
cd Code
composer create-project --prefer-dist laravel/laravel newProject
This would work if I where on a lamp server, but instead I get the following error:
You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug
Installing laravel/laravel (v5.2.15)
- Installing laravel/laravel (v5.2.15)
Loading from cache
Created project in newProject
> php -r "copy('.env.example', '.env');"
> php artisan clear-compiled
PHP Warning: require(/home/vagrant/newProject/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/newProject/bootstrap/autoload.php on line 17
PHP Stack trace:
PHP 1. {main}() /home/vagrant/newProject/artisan:0
PHP 2. require() /home/vagrant/newProject/artisan:16
Warning: require(/home/vagrant/newProject/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/newProject/bootstrap/autoload.php on line 17
Call Stack:
0.0001 352008 1. {main}() /home/vagrant/newProject/artisan:0
0.0001 353760 2. require('/home/vagrant/newProject/bootstrap/autoload.php') /home/vagrant/newProject/artisan:16
PHP Fatal error: require(): Failed opening required '/home/vagrant/newProject/bootstrap/../vendor/autoload.php' (include_path='.:/usr/share/php:') in /home/vagrant/newProject/bootstrap/autoload.php on line 17
PHP Stack trace:
PHP 1. {main}() /home/vagrant/newProject/artisan:0
PHP 2. require() /home/vagrant/newProject/artisan:16
Fatal error: require(): Failed opening required '/home/vagrant/newProject/bootstrap/../vendor/autoload.php' (include_path='.:/usr/share/php:') in /home/vagrant/newProject/bootstrap/autoload.php on line 17
Call Stack:
0.0001 352008 1. {main}() /home/vagrant/newProject/artisan:0
0.0001 353760 2. require('/home/vagrant/newProject/bootstrap/autoload.php') /home/vagrant/newProject/artisan:16
Script php artisan clear-compiled handling the pre-update-cmd event returned with an error
[RuntimeException]
Error Output: PHP Warning: require(/home/vagrant/newProject/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/newProject/bootstrap/autoload.php on line 17
PHP Stack trace:
PHP 1. {main}() /home/vagrant/newProject/artisan:0
PHP 2. require() /home/vagrant/newProject/artisan:16
PHP Fatal error: require(): Failed opening required '/home/vagrant/newProject/bootstrap/../vendor/autoload.php' (include_path='.:/usr/share/php:') in /home/vagrant/newProject/bootstrap/autoload.php on line
17
PHP Stack trace:
PHP 1. {main}() /home/vagrant/newProject/artisan:0
PHP 2. require() /home/vagrant/newProject/artisan:16
Any ideas why would that happen?
I tried to cp a working project and still get the required error.
I found similar errors that had something to do with missing dependencies, but shouldn't Homestead deal with that by himself?
Looks like this was a composer problem. I just tried again and it works. More about it on Laravel News: https://laravel-news.com/2016/03/may-need-update-composer-json-file/

Unable to run phpunit since upgrade to Symfony 2.8/3.0

Since upgrading to Symfony 2.8, I get the following error when I run phpunit in the Symfony root:
PHP Fatal error: Class 'PHPUnit_Util_ErrorHandler' not found in /var/www/foo/symfony/vendor/symfony/phpunit-bridge/DeprecationErrorHandler.php on line 40
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP 4. PHPUnit_TextUI_Command->handleArguments() /usr/share/php/PHPUnit/TextUI/Command.php:138
PHP 5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /usr/share/php/PHPUnit/TextUI/Command.php:657
PHP 6. PHPUnit_Util_Configuration->getTestSuite() /usr/share/php/PHPUnit/Util/Configuration.php:789
PHP 7. PHPUnit_Framework_TestSuite->addTestFiles() /usr/share/php/PHPUnit/Util/Configuration.php:873
PHP 8. PHPUnit_Framework_TestSuite->addTestFile() /usr/share/php/PHPUnit/Framework/TestSuite.php:416
PHP 9. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Framework/TestSuite.php:355
PHP 10. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:76
PHP 11. Symfony\Bridge\PhpUnit\DeprecationErrorHandler::Symfony\Bridge\PhpUnit\{closure}() /usr/share/php/PHPUnit/Util/Fileloader.php:92
THE ERROR HANDLER HAS CHANGED!
This also occurs under Symfony 3.0. Should I now be running phpunit in a different manner?
I just ran into this problem using Symfony 2.8.
Just update your local install of phpunit.
Run this.
phpunit --self-update
That should do it.
I was running phpunit version 4.7.*, but Symfony wanted to see phpunit 5.1.3.
You should clear the app/cache/test directory.
You could also make your global phpunit symlink to the one provided by Symfony located in vendor/phpunit/phpunit/phpunit
Update: I'm not sure what this error is referring to, I still get it, but seems to occur when I have a problem with a test. At the least, it's a confusing message.

PhpStorm 7.1.3, XDebug 2.2.3, Symfony 2.4 - WebTestCase not found

I'm getting the following error when attempting to run my own Symfony unit tests in PhpStorm:
/usr/bin/php /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php
PHP Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php on line 8
PHP Stack trace:
PHP 1. {main}() /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php:0
Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php on line 8
Call Stack:
0.0002 234112 1. {main}() /home/kevin/www/src/Blah/MyBundle/Tests/Controller/HomeControllerTest.php:0
Process finished with exit code 255
Some research has informed me that I may have to point PhpStorm/Xdebug to Symfony's bootstrap and/or test suite XML file, but I'm not sure how to do that in PhpStorm. Nothing is jumping out at me in the various config screens. Please help.
Although I'm using IntelliJ IDEA, the configuration is the same, so:
Settings -> PHP -> PHPUnit - there are inputs for bootstrap and config

PhpUnit 3.6.10 + NetBeans 7.1: Good test throws exception

In cmdline everything is OK:
d:\xampp\htdocs\PhpProject1\Tests>phpunit TestStub.php
PHPUnit 3.6.10 by Sebastian Bergmann.
.
Time: 0 seconds, Memory: 2.75Mb
OK (1 test, 1 assertion)
Called in NetBeans7.1:
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:\Program Files (x86)\NetBeans 7.1\php\phpunit\NetBeansSuite.php".' in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:123
Stack trace:
0 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:\Program File...')
1 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 123
I think this is a NetBeans issue.
If I run:
d:\Program Files (x86)\NetBeans 7.1\php\phpunit>phpunit NetBeansSuite.php run=d:\xampp\htdocs\PhpProject1\Tests\TestStub.php
PHPUnit 3.6.10 by Sebastian Bergmann.
.
Time: 0 seconds, Memory: 2.75Mb
OK (1 test, 1 assertion)
It's OK. But if I give the test directory, it fails.
d:\Program Files (x86)\NetBeans 7.1\php\phpunit>phpunit NetBeansSuite.php run=d:\xampp\htdocs\PhpProject1\Tests\
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class "" in "D:\Program Files (x86)\NetBeans 7.1\php\phpunit\NetBea
nsSuite.php".' in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php:123
Stack trace:
0 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(157): PHPUnit_Util_Skeleton_Test->__construct('', 'D:\Program File...')
1 D:\xampp\php\PEAR\PHPUnit\TextUI\Command.php(130): PHPUnit_TextUI_Command->run(Array, true)
2 D:\xampp\php\phpunit(46): PHPUnit_TextUI_Command::main()
3 {main}
thrown in D:\xampp\php\PEAR\PHPUnit\Util\Skeleton\Test.php on line 123
Any temporary solution?
When running PHPUnit against a single file it will always open the file and look for a test case inside of it.
When running it against a directory (what netbeans does) it will only look into files that end in *Test.php (unless something else is specified in the phpunit.xml).
If it can't find any Tests it will try to look into the $TestSuiteName folder and {$TestSuiteName}.php files hence the error message:
Fatal error: Uncaught exception 'PHPUnit_Framework_Exception' with message 'Could not find class ""
as it is looking for a "not named" test suite in the netbeans phpunit harness. The error message is really not helping you out there :)
The general suggestion would be to create a phpunit.xml and point Netbeans to it.
On a more personal note: From the phpunit support in the major IDEs Netbeans does quite a lot of things right and works well for a lot of people so don't let this bump discourage you from using it from the IDE if thats what you want.

Resources