Viewed   146 times

I had problems with configuring PhpStorm IDE to use http://symfony.com/doc/current/components/phpunit_bridge.html while working with Symfony 3.3.

I decided to just download phpunit.phar to bin and use it instead.

Symfony 3.4 (and Symfony 4), does not even have phpunit.xml.dist out of the box, so there is a problem with using phpunit.phar easily.

I've installed PHPUnit using flex:

composer req phpunit

That created phpunit.xml.dist and I was able to run tests from command line by:

php bin/phpunit

But again I could not make PhpStorm use it.

So I downloaded phpunit.phar and it can work together with provided phpunit.xml.dist.

Question 1: Is there any way for PhpStorm IDE to use phpunit-bridge?

Question 2: What is the best practice for Symfony 4 (phpunit-bridge or vanilla phpunit.phar)?

 Answers

1

What I usually do is point my phpunit testing framework on PHPStorm to the secret .phpunit directory which was created by the bridge, like:

The location of the "phar" file is:

bin/.phpunit/phpunit-(major).(minor)/phpunit

or in some cases:

vendor/bin/.phpunit/phpunit-(major).(minor)/phpunit

After this, the specified phpunit executable will be called correctly when exeuting unit-tests, but with a --no-configuration option. This can cause autoloading problems (a lot of "class not found" errors), because the autoloader generated by Composer is not specified anywhere.

To fix this, you should have a phpunit.xml file in your project (this is common practice anyway), in which you specify Composer's autoloader, something like this:

<phpunit bootstrap="vendor/autoload.php">

This phpunit.xml should then be specified in the "Default configuration file" option and you should be good to go.


Regarding phpstorm using phpunit-bridge: It's possible as a custom script, but you won't have the nice interface and the possibility to run (and debug) specific tests via PHPStorm interface.

Monday, October 24, 2022
 
3

Try:

$formbuilder = $this->createFormBuilder()
        ->add('name', TextType::class, ['required' => true]])
        ->add('email', EmailType::class, ['equired' => true]]);

if($a==true){
    $formbuilder->add('username', TextType::class, ['required' => true]])
         ->add('password', PasswordType::class, ['required' => true]]);
}

$form = $formbuilder->getForm();

if ($form->isSubmitted() && $form->isValid()) {
        ...
        ...
        ...
}
Wednesday, November 16, 2022
 
4

Upgrade to 3.4.*, because it's the latest LTS version. Updating to version 4 should be done when 4.4 comes out (it will be LTS version).

Try to adjust your configuration like following and run the composer update. Following configuration comes with autowiring. Consider if you want to use that, but I suggest, because it's more comfortable to get your dependencies in services/controllers at constructor by using type hints.

1) Composer.json

"symfony/symfony": "3.4.*",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"twig/twig": "^1.0||^2.0",
"symfony/monolog-bundle": "^3.1.0",

2) app/config/services.yml

services:
    _defaults:
        autowire: true # Automatically injects dependencies in your services
        autoconfigure: true
        public: false
        bind:
            # Nice feature here. Local Binding. Read about it at documentation.


    # makes classes in AppBundle available to be used as services
    AppBundle:
        resource: '../../src/AppBundle/*'
    # exclude directories || files (if service is unused, it will be removed anyway)
        exclude: '../../src/AppBundle/{Entity,Repository,Tests}'
    AppBundleController:
        resource: '../../src/AppBundle/Controller'
        public: true
        tags: ['controller.service_arguments']

3) AppBundle/Resources/config/services.yml

   services:
    _defaults:
        autowire: true
        autoconfigure: true
        public: false
Friday, September 9, 2022
 
cecemel
 
3

Do you use the same server/configuration when working with PhpStorm and Eclipse?

As it was explained in the comments, it has nothing to do with the IDE, but with the web server (Apache) and its configuration.

You can edit .htaccess with any editor, if this virtualhost/directory configuration has AllowOverride All, ModRewrite is enabled and your rewrite rules are correct, it will work just fine.

You need to ensure that your PHP files are served from the correctly configured web server.

Tuesday, August 9, 2022
 
svassr
 
2

You can do that with External Tools functionality.

The idea is to launch your app/script that will open such URL in a web browser.

How it can be done depends on your OS and tools you have got there. This is how it can be implemented on Windows OS (URL will be opened in your default web browser):

After you have create such external tool entry and it's working you can optionally assign custom shortcut. This can be done at Settings/Preferences | Keymap -- look for that entry under External Tools branch:


NOTE: Please note that if selection contains spaces then such search will partially fail as spaces will not be encoded into web safe + character (or %20) -- for such cases you will have to write shell/batch script that would perform such conversion and only then open such final URL.

Friday, November 4, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :