Can't get Symfony 2 to work with PHPstorm - php

I've installed the symfony plugin to PHPstorm, but when I'm trying to run the project I get the following error
Fatal error: Class 'Doctrine\Tests\Common\Cache\CacheTest' not found in ...
I've checked the path and CacheTest file is in the correct folder. When I run the symfony project from the command line it works just fine.
Is there someway to fix this problem?

What you try is not correct. You execute the php.exe and that is the normal PHP executable. To run your Unit-Tests you need PHPUnit to run.
Go to Preferences -> Languages & Frameworks -> PHP -> PHPUnit and define the phpunit.phar.
When you've done that you create a new configuration to run PHPUnit and you define the configuration which is under app/phpunit.xml.

I figured it out. First of all you need add phpunit.phar as Stony explained in his answer.
After that all I really needed to do was to rename phpunit.xml.dist to phpunit.xml in app/ folder and then just right click it and choose the Run 'phpunit.xml' option. This way the Tests succeed and it doesn't give any errors.
As for running the symfony project you need to add symfony command line tool support to phpstorm. All about that in this link: https://confluence.jetbrains.com/display/PhpStorm/Symfony2+Command+Line+Tool+Integration+-+Symfony+Development+using+PhpStorm
After that you just run it as a command like you would with normal command line. That's also explained in the link.

Try to choose "Use custom autoloader" option in Preferences -> Languages & Frameworks -> PHP -> PHPUnit and specify the path to vendor/autoload.php file.

Related

Undefined class Route in app.blade.php laravel [duplicate]

How can I fix this alert in PhpStorm?
And also how to get autocompletion for Route and other Facades?
Check the Laracasts walkthrough
1) Go to: https://github.com/barryvdh/laravel-ide-helper
2) Click on the gist
Generated version for L5: https://gist.github.com/barryvdh/5227822
3) Click on "Raw" to get the current version (as of June 22, 2016 it is):
https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php
4) Make sure you're in your root directory (this is mine)
cd /var/www/html/project
5) Download the gist:
wget https://gist.githubusercontent.com/barryvdh/5227822/raw/4d4b0ca26055fa4753b38edeb94fad2396c497c0/_ide_helper.php
6) Add "_ide_helper.php" to the .gitignore file
sudo nano .gitignore
Add "_ide_helper.php" on a new line at the bottom
7) Download the .gitignore and _ide_helper.php files into PhpStorm
This is what my PhpStorm project directory looks like afterwards:
8) After the files are downloaded into PhpStorm, the "Undefined class" error will disappear and autocompletion will now work. Might need to restart it.
There is greate IDE support for Laravel shipped from Baryvdh:
https://github.com/barryvdh/laravel-ide-helper
after you install it you just call in the console:
php artisan ide-helper:generate
which generate alll facede shortcuts in _ide_helper.php file (which you have to exclude from git)
There is also something special for PhpStorm:
php artisan ide-helper:meta
which will give Laravel container context for example:
$foo = app(Foo::class);
PhpStorm will know that the $foo variable is type of Foo class.
I know this is an old thread, but it is still relevant. For me, I decided to add the following to my routes/web.php since I don't want to have to worry about regenerating meta data for the app.
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
Edit: The above does not add any overhead to PHP as the use simply acts as a reference for PHP.
I solved this problem simply by installing the Laravel idea plugin.
Use the following link:
https://laravel-idea.com/
You can install it on your phpstorm.
Its good feature is that you can use it for 30 days for free and pay the amount after satisfaction.

Add symfony console to PhpStorm

I'm trying to add the symfony2 console to phpStorm (v10.0.3) but I'm getting an error like this:
But it's working in the console
Symfony console is correct and php path is too, because I can create bundle like "php app\console generate:bundle"
Anyone know why PhpStorm is returning error?
Try defining the parameters properly.
Path to Symfony -> path to 'app/console'
Path to PHP executable -> click dropdown and select the proper PHP executable location (full path to the executable PHP - in your case php.exe). If you are not sure then type where php.exe to get the exact location of the exe file.
Symfony component version -> Select your Symfony version (version 2.x or 3.x)
Hope this helps.

Not able to run codecoverage with PhpStorm

I am trying to run unit test in PhpStorm with codecoverage.
It throws me a error msg saying interpreter is missing. How to install the interpreter!
Also how to configure in order to run my tests with code coverage.
Steps to do:
1. Set interpreter and language level.
File -> Settings -> Languages & Frameworks -> PHP
Select your PHP version. Then click button with ... (three dotes), then add interpreter.
https://www.jetbrains.com/phpstorm/help/interpreters.html
2. Add PHPUnit to project.
File -> Settings -> Languages & Frameworks -> PHPUnit
a) Load form include path
To add this you must set where PHPUnit library is installed. Then add using External Libraries in Project.
To specify path use green + button.
b) Use custom autoloader
Use this option when you install PHPUnit via composer. In Path to script field specify autoload file.
https://www.jetbrains.com/phpstorm/help/phpunit.html
3. Configure tests
In the top right corner use Select Run/Debug Configuration menu
And click Edit Configurations. Select green + button to add PHPUnit.
Define name of the configuration and directory with tests. Additionally you can add some PHPUnit arguments in Test Runner options field.
https://www.jetbrains.com/phpstorm/help/run-debug-configuration-phpunit.html
Annotation 1 - Configure bootstrap
Tests sometimes needs to use a bootstrap file which set environments, loads configs etc. To set this file go to:
File -> Settings -> Languages & Frameworks -> PHPUnit
and select the bootstrap file in Default bootstrap file field.
https://www.jetbrains.com/phpstorm/help/phpunit.html - in Bootstrap file section.
Annotation 2 - Run tests with code coverage
To run with coverage you must install Xdebug PHP extension. You should read the Xdebug installation guide.
After this actions use a icon
to run with coverage.
https://www.jetbrains.com/phpstorm/help/code-coverage.html

Run unit test when saving file in PhpStorm

I have set up PhpStorm 5 with PHPUnit, and I'm curious if PhpStorm might have some functionality that will automatically run a unit test when saving a file. Like watchr and guard. I have tried search our beloved www and the PhpStorm docs, but haven't been able to find a solution for it.
As of version 6, PHPStorm has "File Watchers"
Open your project preferences.
Select File Watchers from the left hand list of options.
Click the + symbol at the bottom of the empty right hand panel.
Select <custom>
You will have to set up a command line for PHPUnit, it wont be the integrated testing, but you can have errors output to the console (which is good a good start!)
Various macro options are available to you, so you can include (for example) $FileNameWithoutExtension$Test.php in the arguments passed to your command line.
I personally had to set up two watchers. The first detected modifications to project files, and the second detected changes to test files (the second did not append Test.php to the filename) I also created a new project scope to exclude the tests directories from the first watcher.
You may also want to turn off immediate synchronisation, as this causes PHPUnit to run when PHPStorm auto-saves files.
My other settings are like:
File Type: PHP files (PHP)
Scope: Project excluding tests
Program: /path/to/php
Arguments: /path/to/phpunit --configuration /path/to/phpunit.xml.dist /path/to/tests/$FileNameWithoutExtension$Test.php
Working directory: $FileDir$
Output paths: $FileDir$
No output filters set, syntax error checks enabled, and console showing errors.
PHPUnit watcher named as hot phpunit runner
https://github.com/slavahatnuke/hot-phpunit-runner
You can also have a look at TDDRunner
It is console tool that execute PHPUnit autmaticly on file changes. You can also configure PHPUnit by excuting only one file ot whatever.
/usr/bin/tddrunner --group=test
There's a a German article providing further detail.
In 2017 Jetbrains release a feature that allow auto-run for tests.
It's located in the Run console, therefore it's linked to the run settings, easing the setup of this autorun.
See https://blog.jetbrains.com/phpstorm/2017/07/autorun-phpunit-tests-in-phpstorm-2017-2/

How to enable autocomplete/syntax-highlight for PHP core functions in Eclipse?

I searched a lot, checked many times the neccesary steps, but it still don't work.
My environment is :
Latest eclipse for PHP developer package
Project is newed, not check out directly from SVN
.project has a line
<nature>org.eclipse.php.core.PHPNature</nature>
.buildpath has a line
<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
.settings/org.eclipse.core.resources.prefs
has a line
include_path=0;/projectname
file ensured opened in PHP Editor
Something works:
PHP core function defination displayed when mouse over, and Ctrl+Click will open its defined file, but input 'arr' nothing happens, while a list of array functions expected
Autocomplete does work for internal functios/variables such as class members
But never works for PHP core functions, neither syntax highlighting
Right-Click on your project -> Configure -> Add PHP Support...
Works for me on Eclipse 3.5 / PDT 2.1
For me, nothing worked, except:
Backup and then delete the .db files under: /.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2/
Restart eclipse.
I got this tip from #4 in: http://www.nwiresoftware.com/blogs/nwire/2010/09/five-tips-speeding-eclipse-pdt-and-nwire
As noted before the 'natures' node for php core is listed but this is most insufficient when the project is imported or checked out.
Make a backup of your .project
Remove the 'natures' node children
Close/Re-open eclipse
Right-click project -> Configure -> Add PHP Support
Add back other 'natures' children
The issue is that project will not make the necessary imports because it assumes it already has.
Nothing helped, but this:
In Eclipse:
Go to Window -> Preferences -> General -> Editors -> File Associations
Click Add
Type *.php
Under Associated Editors choose PHP Editor and click Default on the right.
Close and open your php file.
There are 3 .dll files: model.h2.db, model.lock.db and model.trace.db under workspace/.metadata/.plugins/org.eclipse.dltk.core.index.sql.h2
Remove these files and restart Eclipse.
There seem to still be a lot of bugs related to auto-completion for the PHP Development Tools Project (PDT) (See Open Bugs).
One has been entered two days ago: bug 286733 "When using sub namespace completion does not work."
But this is hardly the only one:
"Autocomplete on namespaces failed" (bug 281766)
"[php 5.3] Code assist doesn't provide method completion" (bug 286068)
...
They are all related to the namespace of the PHP code. Could you check if you reproduce the error in a global namespace?
If issue is still exists, follow the following steps:
Remove project from eclipse.
Goto your project folder and remove .Settings folder and .project
file.
Again import php project with different name.
it's work for me.
Right-Click on your project -> Configure -> Convert to PHP Project...
Works for me on Eclipse 4.6 / PDT 5.2

Categories