PhpStorm is an IDE (Integrated Development Environment) for PHP and web developers, which is engineered by JetBrains. It is not available free of cost. It supports PHP 5.3 and above versions. PhpStorm is built on the IntelliJ IDEA platform, which is written in Java.
JetBrains PhpStorm is an innovative and cross-platform IDE that become popular over the last couple of year. It is perfect for working with Drupal, Symfony, Laravel, WordPress, Zend Framework, Joomla, CakePHP, and other frameworks. PhpStorm 2019.1.3 is the latest version of the PhpStorm.
For example Cakephp uses the same Classname for the basic classes but also for their basic class tests. Another example - Cakephp brings it's own 'AppController' Class which can be overlayed by a users 'AppController' Class. PHPstorm seems to be at a loss wich of those files is the correct one and thus does not get the correct hierarchy. CakeStorm is a PHPStorm plugin for CakePHP developers. I have a CakePHP application running inside a Docker container. The htdocs folder is mapped to a folder in my host, where I use to develop using Eclipse. I'm satisfied with Eclipse, but I'd like to take a look into PHPStorm. The problem I have is I can't debug my project with PHPStorm. Configure PhpStorm to Auto-complete CakePHP Models, Views, and Controllers: After playing around a bit today I finally figured out how to get PhpStorm to auto-complete methods for models and controllers. Here's what you need to do. Removing Multiple Definitions: First, let's tackle the multiple definitions problem that we see below.
All WebStorm features are included into PhpStorm, with full-fledged support for PHP and database support added on the top. PhpStorm helps the developer to understand and change their code by providing editable UML class diagrams for PHP code.
PhpStorm IDE provides code refactoring, auto-completion, on-the-fly error prevention, zero-configuration debugging, and an extended HTML, CSS, and JavaScript editor.
PhpStorm provides tools and code assistance features for working with databases and SQL in your projects. It connects with the database, edit tables and schemas, run queries, and even analyze schema with UML diagram.
Note: PhpStorm is not free of cost. It is available for 30 days free trial.
Key Features of PhpStorm
- Complete development environment
Most PHP developers do not work with PHP only, but they also work with HTML, CSS, JavaScript, and other languages. PhpStorm makes it easy for developers to work with all languages, by providing code completion and syntax highlighting support. - Support multiple PHP Framework
PhpStorm is a perfect choice if you use PHP frameworks. It integrates effectively with lots of framework like Laravel, CakePHP, Symfony2, and Yii - all of these frameworks are also supported by Future Hosting?s PHP Framework application server. - Great version control Integration
PhpStorm provides full support for a large range of version control system, most importantly included - GitHub and Git. Programmers can branch and merge from within the IDE.
Additionally, PhpStorm also includes excellent FTP support that the code can be uploaded to a remote server within a few seconds. - Database Support
PhpStorm provides tools and code assistance features for working with SQL and databases in your projects. It connects with the database, edits table data, executes queries, and even analyzes the schemas with UML diagrams. - Debugging and Testing
Zero-configuration debugging makes it easy to debug the application. PHPUnit supports to develop and run unit tests right from your IDE. Profile the applications with Xdebug and Zend Debugger and check aggregated reports in PhpStorm.
PhpStorm 10
PhpStorm includes a number of new features that make PHP-based application more pleasant. First and foremost feature of PhpStorm is that it offers full support for PHP 7, another exciting new feature is the Docker integration. Developers can easily handle Docker containers from inside the IDE. It is the powerful feature of PhpStorm 10 that makes it easy to build development and deployment environment which can run almost on any Linux server.
Benefits of using PhpStorm
- Projects are scanned quickly and accurately in PhpStorm. We are able to perform auto-compilation based on existing class and functions really fast.
- Excellent project-wide search option.
- Best tracing option for inheritance.
- Search has lots of options and searchable. We can organize the search result according to file, directory, and other several options.
- Excellent built-in comparison tool with syntax highlighting.
- Clear matching brace highlight available.
- Useful alert available, which pop up over the editor to tells us that something might not be configured properly.
System requirements for PhpStorm
- Minimum 2GB RAM
- 4GB recommended
- Window 10/8/7/Vista/XP (64 bit)
- 1024x768 screen resolution.
How to install PhpStorm
Step 1: Download the latest version of JetBrains PhpStorm 2019.1.3 from the following link https://www.jetbrains.com/phpstorm/download/#section=windows for 30 days free trial. You can choose any platform (Window, Linux, and MacOS) as per your need.
Step 2: Once the downloading completes, run the PhpStorm. We will get the wizard where we need to click on Next button.
Step 3: Browse the Destination Folder to install PhpStorm and click on Next.
Step 3: Here, we don't need to do anything, click on Next and move forward. But for creating a shortcut on Desktop check the create Desktop Shortcut as per the system configuration.
Step 4: Select/Enter the start menu folder name for creating the program's shortcut. By default, JetBrains will show. Now click on Install Button and start the extraction of files.
Step 5: Once all the files are extracted successfully, click on the Run PhpStorm checkbox and click on Finish to complete the installation process.
Step 6: A wizard will show to import the PhpStorm setting. Select do not import setting and press OK.
Step 7: Now, accept the term of User Agreement and Continue.
Step 8: Click on Send Usage statistics and move forward.
Step 9: Set the UI theme from here (as per below image), for dark theme select Darcula and for light theme choose Light. We can also skip this step by clicking on Skip Remaining and Set Default.
Step 10: Skip this step for later by clicking on Skip Remaining and Set Default button.
Step 11: For 30 days free trial, select Evaluate for free rather than Activate and click on Evaluate.
Step 12: PhpStorm is successfully installed. Now, create a new project and start work with PhpStorm.
How to create a project in PhpStorm
Step 1: Create a new project with PhpStorm and also provide the location to save.
Step 2: Right click on your project to create a new HTML file. New → HTML, we can also create PHP, JavaScript, and other files here.
Step 3: Write the HTML code and run it on browser.
Step 4: The output of the above program will be-
FeaturesPhpStorm
CakePHP2 comes with unit testing support powered by PHPUnit. In addition to the features offered by PHPUnit, CakePHP offers some additional features to make testing easier. Unit tests in CakePHP rely on a custom test runner which can be run in the browser or using the CakePHP console. More information on unit testing with CakePHP can be found on their website.
One issue with CakePHP unit tests is that they rely on the CakePHP test runner. This means that running them directly from PhpStorm is not supported out of the box. Which does not mean it’s impossible! Let’s see if we can get CakePHP unit tests running from PhpStorm.
Understanding how PhpStorm runs unit tests
Before we can make CakePHP unit tests run in PhpStorm, let’s find out how PhpStorm runs unit tests in the first place. A good way to discover this is by creating a simple project in PhpStorm and adding a unit test run configuration to it. The unit test tab shows us what is happening under the covers.
When scrolling a bit to the right, we can see PhpStorm is invoking a script named ide-phpunit.php which it stores in a temporary location on our system. What’s interesting is that this file is not deleted immediately after the test run, so it can be opened just like any other PHP file. Let’s have a look inside.
The script ide-phpunit.php is a simple wrapper around multiple versions of PHPUnit, returning unit test results to the IDE. It contains several classes, like IDE_PHPUnit_TextUI_Command (extending PHPUnit_TextUI_Command) which is a custom PHPUnit test runner. Since CakePHP uses a similar approach for bootstrapping their unit tests, we may be on to something!
Some of the most interesting lines of code in this file are the following:
What happens here is that PHPUnit is configured in such way that it can report test results to PhpStorm through a custom test result listener and a custom test result printer.
If we scroll to the bottom of this file, we can see the following statement:
IDE_PHPUnit_TextUI_Command::main();
This command kicks off the actual test run. Based on these pointers, let’s craft a custom test runner for PhpStorm which bootstraps CakePHP unit tests!
Creating a CakePHP test runner for PhpStorm
Let’s start by creating a new test runner called IDE_Cake_PHPUnit_TextUI_Command and inheriting from CakePHP’s test runner, CakeTestSuiteCommand. This class will implement two functions: main(), which starts the test runner, and the handleArguments() function which intercepts PHPUnit’s configuration arguments.
Phpstorm Cakephp3
Using some custom argument parsing in the main() function, we can provide CakePHP’s test runner with some additional parameters which are not supported by PHPUnit directly. The loop over the argument values being passed in strips out any command-line switch which starts with –cake- and passes it to CakePHP’s test runner as custom options. Using this approach we can later use a –cake-case=AllTests command-line switch to instruct CakePHP which tests to run.
The handleArguments() function is a blatant copy-paste from the ide-phpunit.php script. It configures PHPUnit to report test results back to PhpStorm using a custom test result listener.
We can save this file in the root of our project and name it cakeunit4phpstorm.php. If you’re interested in the complete source code already, it’s available from here.
Tricking PhpStorm into using a custom test runner
We’re not there yet. There is one major issue we can not solve: PhpStorm always creates a fresh copy of ide-phpunit.php. Hence we can not add our custom test runner code nor invoke it from that script. Hrm, now what?…
Fortunately, test run configurations in PhpStorm provide us with an option to specify PHP interpreter arguments. And PHP has this lovely -f switch which allows us to provide a custom script to run…
Phpstorm Cakephp 設定
If we now run our unit tests, the custom test runner we’ve created is invoked but it’s not yielding the results we expected from it… The reason for that is we’ve removed every association with the ide-phpunit.php script and classes therein. Back to the drawing board.
In the cakeunit4phpstorm.php script, let’s apply a small trick to the arguments being passed from PhpStorm.
The first loop we’re doing is intended to “clean” argument values. We’re interested in keeping all command-line arguments except if it is the path to ide-phpunit.php. Why not, you ask? Well, PHP will get confused if we pass it two scripts to run, hence we’re removing PhpStorm’s generated test runner from the command-line arguments. Note we do store the path to ide-phpunit.php as we want to include it later on.
Before including the original PhpStorm test runner, we want to make sure it’s not invoking itself. The last line of it was IDE_PHPUnit_TextUI_Command::main(), we want to be sure that line is not included by simply commenting it out.
Finally, we include ide-phpunit.php and all classes in there to make use of what is already in the box: a means to communicate test results with PhpStorm.
Using the CakePHP test runner with PhpStorm
Let’s put our new test runner to the test. If you haven’t done so yet, add cakeunit4phpstorm.php to your project root. Its sources are available from https://gist.github.com/4529548.
Next, create a test run configuration for your CakePHP project. Make sure to specify test runner options according to the arguments you would normally use with ./Console/Cake test. These arguments should be in the format –cake{var}={value}.
Some examples:
● Run application test named “Sample”: –cake-case=Sample –cake-app
Phpstorm Cakephp 2
Phpstorm Cakephp
● Run core test named “AllTests”: –cake-case=AllTests –cake-core
Phpstorm Cakephp Autocomplete
Finally, make sure the PHP interpreter options are specified. The value for the -f switch should be the full path to cakeunit4phpstorm.php.
Here’s an example configuration for running all core tests:
We can now run this test configuration and get results from CakePHP unit tests in PhpStorm. We can inspect CakePHP test results right from our IDE.
Enjoy CakePHP with PhpStorm! Step-by-step tutorial is available here.
Develop with pleasure!
– JetBrains Web IDE Team