Unable to remove phpstorm background - symfony

I'm using phpStorm for my Symfony2 project, And I'm getting this "not found" message probably for all methods. so I have 2 questions.
1) Why phpStorm can't find my methods?
2) How to remove this annoying background from "not found" methods?
Screenshot is here:
Thank you. :)

Often PhpStorm cannot guess the type. You can help it by using typehints:
public function indexAction(Request $request);
phpdocblocks:
/**
* #param Request $request
*
* #return Response
*/
public function indexAction(Request $request) {return new Response('');}
and inline comments:
/* #var \Symfony\Component\Form\Form $form */
$form = $this->createForm(/* ... */);
For Symfony, there's an excelent plugin you can install and very much improve your experience with PhpStorm and the Symfony framework: http://plugins.jetbrains.com/plugin/7219?pr=phpStorm
It supports all bunch of features, including autocompletion of container services.
As for the "annoying background", look into PhpStorm color settings. You can configure pretty much anything in there, including changing the theme if you don't like the default one.

Related

PhpStorm Symfony routes missing

I have a rather large Symfony 4.4 project that I recently reopened. Going through the code with PhpStorm 2020.3, adding some new functionality and code cleanup.
I get to a couple of Controllers and I'm getting a "Missing Route" error in PhpStorm. However, the routes do exist when I run php bin/console debug:router.
Is there a cache that I haven't cleared to cause PhpStorm to rescan routes?
Output from: php bin/console debug:router
admin_deviceprofile_index GET ANY ANY /admin/deviceprofile/
admin_deviceprofile_show GET ANY ANY /admin/deviceprofile/{deviceprofile_id}/show
admin_deviceprofile_create GET|POST ANY ANY /admin/deviceprofile/create
admin_deviceprofile_edit GET|POST ANY ANY /admin/deviceprofile/{deviceprofile_id}/edit
admin_deviceprofile_delete DELETE ANY ANY /admin/deviceprofile/{deviceprofile_id}/delete
My snippet of the Controller ...
/**
* #Route("/admin/deviceprofile",
* name="admin_deviceprofile_")
*/
class DeviceProfileController extends AbstractController
{
/**
* Lists all Device Profiles.
* #Route("/",
* name="index",
* methods={"GET"})
* #param Request $request
* #return Response
*/
public function index(Request $request): Response
{ ... }
/**
* Creates a new Device Profile entity.
* #Route("/create",
* name="create",
* methods={"GET", "POST"})
* #param Request $request
* #return Response
*/
public function create(Request $request): Response
{
$profile = new DeviceProfile();
$formProfile = $this->createForm(DeviceProfileType::class, $profile);
$formProfile->handleRequest($request);
if ($formProfile->isSubmitted() && $formProfile->isValid()) {
...
return $this->redirectToRoute('admin_deviceprofile_index');
}
return $this->render(...);
}
}
PhpStorm claims the 'admin_deviceprofile_index' is Missing. However, it is not. Also, this same pattern of having a route for the controller is used elsewhere, yet those routes are fine, the problem appears in just a couple of Controllers.
Also, through debugging this 'problem', I moved the controller route partials to the functions themselves, and PhpStorm still did not see the routes properly.
I have also ran php bin/console cache:clear and have done the PhpStorm: File > Invalidate Caches / Restart to no avail.
Anything I could try to clear this up? I loathe seeing "errors" in the code inspection.
Figured out that if you have a PhpStorm #noinspection tag block and a class-level docblock, it will conflict causing the erroneous "Missing Route" message.
Github issue here

Migrate TYPO3 Extbase task to Symfony command

I'm trying to migrate the extension pb_social to TYPO3 10 LTS but I'm stuck in the migration of the scheduler task that updates TYPO3 data from the social feeds.
I learned how to register a Symfony Console Command with the Services.yaml file so I can execute the command.
The problem is that the pb_social extension relies on Extbase same as its actual updateFeedDataCommand command.
So I tried to create a new command in the Symfony style and in its method execute() I instantiated:
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
/** #var PBSocialCommandController $controller */
$controller = $objectManager->get(PBSocialCommandController::class);
I already updated the properties of pb_social methods to use the new #TYPO3\CMS\Extbase\Annotation\Inject but still the injections seems not to work.
E.g. with:
/**
* #var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* #TYPO3\CMS\Extbase\Annotation\Inject
*/
protected $configurationManager;
$this->configurationManager is null when used.
What could be the problem?
Soved using Method Injection
/**
* #param ConfigurationManager $configurationManager
*/
public function injectConfigurationManager(ConfigurationManager $configurationManager)
{
$this->configurationManager = $configurationManager;
}

I cant generate URL with router service when JMSI18nRoutingBundle is in use - Symfony 2.7

$this->getServiceContainer()->get('router')->getGenerator()->generate('ting_user_reset_password', array(), UrlGeneratorInterface::ABSOLUTE_URL);
When I try to generate a URL with the router service using the route name ting_user_reset_password an exception occurs because with JMSI18nRoutingBundle the route name doesnt exist.
/**
* #Route("/reset-password", name="ting_user_reset_password")
* #Template()
*/
public function resetPasswordAction(){
}
JMSI18nRoutingBundle create the following routes:
us_US_RG_ting_user_reset_password
de_DE_RG_ting_user_reset_password
es_ES_RG_ting_user_reset_password
...
If you disable JMSI18nRoutingBundle for this route, the router service works fine:
/**
* #Route("/reset-password", name="ting_user_reset_password", options={"i18n" = false})
* #Template()
*/
public function resetPasswordAction(){
}
How can I get the URL using the router service by specifying the name of the route?
Thank you.
I have made many tests and the correct way to generate urls when the bundle "JMSI18nRoutingBundle" is used, is as follows :
$this->getServiceContainer()->get('router')->generate('ting_user_reset_password', array(), UrlGeneratorInterface::ABSOLUTE_URL);
without getGenerator()->
thats working fine to me.

Testing Symfony2 emails with Behat 3

I followed the Behat 2.5 docs to test mails. After a few tweaks to match Behat 3 I have ended with the following code (I have removed non-relevant parts):
public function getSymfonyProfile()
{
$driver = $this->mink->getSession()->getDriver();
if (!$driver instanceof KernelDriver) {
// Throw exception
}
$profile = $driver->getClient()->getProfile();
if (false === $profile) {
// Throw exception
}
return $profile;
}
/**
* #Then I should get an email with subject :subject on :email
*/
public function iShouldGetAnEmail($subject, $email)
{
$profile = $this->getSymfonyProfile();
$collector = $profile->getCollector('swiftmailer');
foreach ($collector->getMessages() as $message) {
// Assert email
}
// Throw an error if something went wrong
}
When I run this test, it throws the following error:
exception 'LogicException' with message 'Missing default data in Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector' in vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php:93
Stack trace:
#0 vendor/symfony/swiftmailer-bundle/Symfony/Bundle/SwiftmailerBundle/DataCollector/MessageDataCollector.php(122): Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector->getMailerData('default')
#1 features/bootstrap/FeatureContext.php(107): Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector->getMessages()
My profiler is configured as follows:
# app/config/config_test.yml
framework:
test: ~
profiler:
enabled: true
collect: true
It seems that the Profile is correctly loaded and the MessageDataCollector from Swiftmailer does exist, but it is not doing its work as expected. Any clue to solve this?
Maybe the issue you have has been fixed as I do not have this anymore (I'm using Behat v3.0.15, BrowserKit driver 1.3.* and Symfony v2.6.6).
I managed to reproduce your error but only when I forgot to enable profiler data collecting:
profiler:
collect: false
Once this problem solved (the configuration you provided solving the problem for me) I managed to check emails in my Behat tests.
Two solutions for this:
Solution #1: Intercepting redirects globally
If it does not break all your other tests you can do so by configuring your web profiler as follows:
web_profiler:
intercept_redirects: true
Solution #2: Preventing client to follow redirections temporarily
For my part, intercepting redirections globally in the configuration broke most of my other functional tests. I therefore use this method instead.
As preventing redirections allows mainly to check data in the data collectors I decided to use a tag #collect on each scenario requiring redirect interception. I then used #BeforeScenario and #AfterScenario to enable this behaviour only for those scenarios:
/**
* Follow client redirection once
*
* #Then /^(?:|I )follow the redirection$/
*/
public function followRedirect()
{
$this->getDriver()->getClient()->followRedirect();
}
/**
* Restore the automatic following of redirections
*
* #param BeforeScenarioScope $scope
*
* #BeforeScenario #collect
*/
public static function disableFollowRedirects(BeforeScenarioScope $scope)
{
$context = $scope->getEnvironment()->getContext(get_class());
$context->getDriver()->getClient()->followRedirects(false);
}
/**
* Restore the automatic following of redirections
*
* #param AfterScenarioScope $scope
*
* #AfterScenario #collect
*/
public static function restoreFollowRedirects(AfterScenarioScope $scope)
{
$context = $scope->getEnvironment()->getContext(get_class());
$context->getDriver()->getClient()->followRedirects(true);
}
It's not the answer your are looking for, but I'm pretty sure it will suits your needs (perhaps more).
If I can suggest, try using Mailcatcher with this bundle: https://packagist.org/packages/alexandresalome/mailcatcher
You'll be able to easily tests if emails are sent, what's their subject, follow a link in the body, and so on...
Many steps are included with this bundle.

Behat+symfony2 access container parameters set in custom extension

(I'm going to explain situation, incase someone knows of a better way to accomplice what I want to do).
Using Symfony2 + Behat + Symfony2Extension + Mink +
We have an application with multiple urls that will be visited during scenarios.
I do understand that you use the parameters sent in from the FeatureContext __construct method, but what I'm trying to do is set up the urls in the behat.yml file so that we can use them in our custom Context to visit the urls.
Looking at how the extensions work I have setup the dependency injection as follows:
class Extension implements ExtensionInterface
{
/**
* Loads a specific configuration.
*
* #param array $config Extension configuration hash (from behat.yml)
* #param ContainerBuilder $container ContainerBuilder instance
*/
public function load(array $config, ContainerBuilder $container)
{
$container->setParameter('url_one', $config['url_one']);
$container->setParameter('url_two', $config['url_two']);
}
/**
* Setups configuration for current extension.
*
* #param ArrayNodeDefinition $builder
*/
public function getConfig(ArrayNodeDefinition $builder)
{
$builder->
children()->
scalarNode('one_url')->
isRequired()->
end()->
scalarNode('two_url')->
isRequired()->
end()->
end();
}
code continues....
And my behat.yml looks like this:
default:
extensions:
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~
Behat\Symfony2Extension\Extension: ~
Acme\AcmeExtension\Extension:
url_one: 'http://example1.com'
url_two: 'http:/example2.com'
Now in my FeatureContext.php class I would like to do the following:
$url = $kernel->getContainer()->getParameter('url_one');
But this is not working, it is returning parameters from my Symfony2 application, which is expected since I have symfony2extension enabled. But I can not access the parameters or services from the extension class.
(Please note that if I'm in the Extension class in the load method and I call the parameter I just set it returns it, so I know it is set, but it must be set to a different container?)
First off is this possible? And if so what should I do to make it work.
Many thanks for any help.
Obviously, $kernel->getContainer() returns you container of the Symfony2 app kernel. Those kernel and container are not shared with Behat. Behat has its own container instance, which it uses to manage own services. Which means that extension is setting parameters inside Behat container, but you are attempting to access your app kernel container. That's why you have different results.
Now, the question is, how would you pass some value from your extension to context class. Answer is context initialiser. Check out:
https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/services/core.xml#L43-L47
https://github.com/Behat/MinkExtension/blob/master/src/Behat/MinkExtension/Context/Initializer/MinkAwareInitializer.php#L26-L77

Resources