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
Related
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 can't for the life of me get this route to work:
/***
* #Route("/load_base_data/{projectId}", name="load_base_data", methods={"GET"})
* #return Response
*/
public function loadBaseMeasures(int $projectId, DataLoadService $dataLoadService, ApiService $apiService)
{
$response = $apiService->initResponse();
$dataLoadService->generateFiles($projectId);
return new JsonResponse($response);
}
I've tried php bin/console debug:router and it doesn't show up on the list.
I've tried php bin/console cache:clear
This is the only route I'm having trouble with.
Cerad was right, the problem was the /***. Changed to /** and it worked. Thanks!
$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.
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.
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.