`FeatureContext` context class not found and can not be used. - symfony

I'm new with symfony2 and i wnat to test my app using behat but when I followed the official install in this link http://docs.behat.org/en/latest/cookbooks/1.symfony2_integration.html#installing-and-enabling-symfony2-extension
i got this error :
[Behat\Behat\Context\Exception\ContextNotFoundException]
FeatureContext context class not found and can not be used.
it was just after the first line and when i ran the bin/behat command.

When using the Symfony2Extension, you are responsible for handling the autoloading. Make sure the FeatureContext class can be autoloaded by changing your composer.json autoload configuration and running composer dump-autoload.

Related

symfony fatal error after removing bundle

I created a bundle named UserBundle and when I needed to remove it I did this exacly :
Unregister the Bundle in the AppKernel
Remove Bundle Configuration
2.1 Remove Bundle Routing
2.2 Remove Bundle Configuration
Remove the Bundle from the Filesystem
3.1 Remove Bundle Assets
Remove Integration in other Bundles
but when I try to exec soms command this is what I Get :
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in #UserBundle/Resources/config/s
ervices.yml (which is being imported from "C:\xampp\htdocs\MT\app/config\config.yml"). Make sure the "UserBundle/Resources/config/services.yml" bundle is correctly registered an
d loaded in the application kernel class. If the bundle is registered, make sure the bundle path "#UserBundle/Resources/config/services.yml" is not empty.
[InvalidArgumentException]
Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
[RuntimeException]
An error occurred when executing the ""cache:clear --no-warmup"" command:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? in #UserBundle/Resources/config/services.yml (which is being imported from "C:\xampp\htdocs\MT\app/config\config.yml").
Make sure the "UserBundle/Resources/config/services.yml" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "#UserBundle/Resources/config/services.yml" is not empty.
When I Refresh the server 'http://127.0.0.1/mt/web/' I get :
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Bundle "UserBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?' in C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php:198 Stack trace: #0 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php(232): Symfony\Component\HttpKernel\Kernel->getBundle('UserBundle', false) #1 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Config\FileLocator.php(51): Symfony\Component\HttpKernel\Kernel->locateResource('#UserBundle/Res...', NULL, false) #2 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php(147): Symfony\Component\HttpKernel\Config\FileLocator->locate('#UserBundle/Res...', 'C:\xampp\htdocs...', false) #3 C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php(101): Symfony\Component\Config\Loader\FileLoader-> in C:\xampp\htdocs\MT\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php on line 179
In C:\xampp\htdocs\MT\app\config\config.yml you may have something like:
imports:
- { resource: #UserBundle/Resources/config/services.yml }
and possibly a configuration section related to the user bundle, i.e.
user_bundle:
...
You have to manually remove both to make everything working again.
Can you check if you use this bundle in app/config/service.yml
If it's not working, try to search with your IDE (integrated development environment) your bundle inside your project. If you find some results, just remove them.
Clear the cache
Try to clear cache manually by removing those folders : "var\cache\dev" and "var\cache\prod" for Symfony 3.x or "app\cache\dev" and "app\cache\prod" for Symfony 2.x .

How to call Doctrine CacheProvider function in Laravel 4 Controller

I have seen some useful functions like the following in
vendor/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php of laravel 4 installation.
public function flushAll()
{
return $this->doFlush();
}
How can I call this function from my controller.
This question was asked in Laravel Forum and here also, but no response!
Luckily I have derived solution for my question.
The Composer vendor have a class autoload map file which have an array with all class names with their namespace.
This file will be updated in all instance of composer install or composer update which will be prepeded by composer dump-autoload command.
If I am making a class somewhere, I have to execute the php artisan dump-autoload command to properly auto-load them.
So here in vendor/composer/autoload_classmap.php, we have reference to all vendor classes including Symfony and Doctrine.
And the entry for the Doctrine Cache Provider will be,
'Doctrine\\Common\\Cache\\CacheProvider' => $vendorDir . '/doctrine/cache/lib/Doctrine/Common/Cache/CacheProvider.php'
Here I can see which file it is, and what will be the namespace.
Now we can call functions by using the namespace,
use Doctrine\Common\Cache\CacheProvider as DoctrineCache;
DoctrineCache::flushAll();
And also we can add this in providers array with app.php

How to install mmoreramerino/GearmanBundle with Symfony 2.1.x?

I am pretty new to Symfony 2 and brand new to Gearman.
I am looking for a bundle to integrate Symfony 2 with Gearman.
mmoreramerino's bundle seems to be the most popular bundle according to packagist. Unfortunately something seems to be broken, the autoloader does not find the bundle.
Fatal error: Class 'Mmoreramerino\GearmanBundle\MmoreramerinoGearmanBundle' not found in ...
I tried switching to "dev-development" as I got from the issues that it was fixed in this branch, but it did not work for me as well.
Question: How can I install this bundle using Symfony 2.1.x?
Question 2: Are there any working & documented alternatives?
Edit In case someone else comes across this question: Here is how I got it up and running!
Install gearman, libgearman, the PECL extension for PHP (use recent versions!)
check that gearman shows up in phpinfo() (both cli and webserver version)
start gearmand in terminal 1 using "gearmand --verbose INFO" (you will see workers & clients connect to gearman - or not ;-))
start in terminal 2 reverse_worker.php from the gearman php extension example directory
start in terminal 3 reverse_client.php from the gearman php extension example directory
If this is working, you are ready for Symfony: install mmoreramerino/GearmanBundle using "dev-development"
copy dev.base.yml from the bundle to app/config/gearman/dev.yml
Now add TestWorker.php to your bundle as outlined in the documentation
enable the testWorker by using the console script "php app/console gearman:job:execute MmoreramerinoGearmanBundleWorkerstestWorker~test"
now you are able to send jobs to the listening testWorker in a Symfony controller (or somewhere else in Symfony). I had to specify the server though I am using the default host/port.
$gearman = $this->get('gearman');
$gearman->setServer('127.0.0.1',4730);
$gearman->doNormalJob('MmoreramerinoGearmanBundleWorkerstestWorker~test');
To install the bundle, you need to add the following line to composer.json
"Mmoreramerino/GearmanBundle": "dev-development"
and run composer update;
Then register it in app/AppKernel.php (it seems you have already done this)
new Mmoreramerino\GearmanBundle\MmoreramerinoGearmanBundle(),

Unit testing a symfony service class with phpunit

I have a basic class GenericHelper.php in directory Foo/BarBundle/Helper
I registered it as a service in Foo/BarBundle/Resources/config/services.yml:
parameters:
generic_helper.class: Foo\BarBundle\Helper\GenericHelper
services:
generic_helper:
class: %generic_helper.class%
and I'm able to access it in a command by doing the following:
$helper = $this->getContainer()->get('generic_helper');
Now, I'd like to unit test that class with PHPUnit; I have the following code (similar to http://symfony.com/doc/2.0/book/testing.html#unit-tests):
namespace Foo\BarBundle\Tests\Helper;
use Foo\BarBundle\Helper\GenericHelper;
class GenericHelperTest extends \PHPUnit_Framework_TestCase {
public function testSomeMethod() {
$helper = new GenericHelper(); //line 10
$this->assertEquals($helper->someMethod(), SOME_RESULT);
}
}
Running PHPUnit results in the following error:
PHP Fatal error: Class 'Foo\BarBundle\Helper\GenericHelper' not found in /DIR/src/Foo/BarBundle/Tests/Helper/GenericHelperTest.php on line 10
Grepping for 'GenericHelper' only yields a few results:
the Class itself and the Test class
the services.yml file
appDevDebugProjectContainer files in app/cache/dev/, which have all the service getters
Question(s):
Does Symfony prevent PHPUnit from directly constructing a service class?
Is there a way to do this without creating a Symfony Container then accessing the service (as done here: Access Symfony 2 container via Unit test?)? I mean, it's still just a basic class...
Running phpunit with the -c flag pointing to the directory containing the phpunit.xml.dist file solved the issue. Doing this includes bootstrap.php.cache and therefore the autoloading stuff necessary.

How to install a Symfony 2.0 Bundle from Zip file

I tried installing the FixturesBundle as described in http://symfony.com/doc/2.0/bundles/DoctrineFixturesBundle/index.html but my proxy wont let me out.
So I went to https://github.com/doctrine/data-fixtures and download a zip from the latest commit.
I unzipped into the vendor directory and renamed it to doctrine-fixures. I edited the autoload.php and AppKernel.php files as described in the tutorial.
When I run:
php app\console doctrine:fixtures:load
I get the following message:
PHP Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesB
undle' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on
line 20
Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle
' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on line
20
Is there a way to run the installation of bundle pointing it to a zip file?
I´m running Symfony 2.0.9 on Windows 7.
Seems like the doctrine bundle has been moved outside of Symfony scope back to Doctrine.
Please, use https://github.com/doctrine/DoctrineFixturesBundle
I had the same problem and this is how i successfully solved it. I started to download this files data-fixtures and DoctrineFixturesBundle, unzipped both into /vendor/doctrine and created this folder structure:
vendor
- doctrine
- doctrine-fixtures-bundle
- Doctrine
- Bundle
- FixturesBundle
DoctrineFixturesBundle.php
..other files...
vendor
- doctrine
- data-fixtures
- lib
- test
composer.json
..other files...
Then i edited the AppKernel.php and added
public function registerBundles(){
.....
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
.....
}
Edited the composer.json located in the root of the project and added this 2 lines:
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
Mine, now look like this:
{
"autoload": {
"psr-0": {
"": "src/",
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
}
}
}
afterwards execute composer dump-autoload -o to recreate the classmap. All this was thanks to the users Wouter J and nifr that answered my question How to install DoctrineFixturesBundle offline
Happy coding!
Yes, it's true that Doctrine is being moved away from the Symfony namespace (see here).
So if you're using the Symfony standard distribution you download from the website (without using git), and you want to have the FixturesBundle installed manually, you have to download the doctrine-fixtures library from here, extract the zip into
YourProject/vendor/doctrine-fixtures
Download the FixturesBundle from here, and extract it in
YourProject/vendor/bundles/Doctrine/Bundle/FixturesBundle
Then you have to register the library's namespace, do it by adding
'Doctrine\\\\Common\\\\DataFixtures' => \__DIR\__.'/../vendor/doctrine-fixtures/lib',
in your autoload.php.
In addition, you'll have to register the Doctrine's namespace, because some part of your application will be using the DoctrineBundle shipped from the Symfony namespace, but the new downloaded FixturesBundle will be using the new Doctrine's namespace, so to make it work, in your autoload.php add the following line (taking care you do it before the Doctrine namespace, remember that more specific rules go first!)
'Doctrine\\\\Bundle' => \__DIR\__.'/../vendor/bundles',
So all you have to do now is to register the new bundle in your AppKernel.php writing
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

Resources