HWIOauthbundle with FOSUserbundle Integration error - symfony

Attempted to load class "Curl" from namespace "Buzz\Client". Did you
forget a "use" statement for another namespace? 500 Internal Server
Error - ClassNotFoundException
in app/cache/dev/appDevDebugProjectContainer.php at line 1809 -
protected function getHwiOauth_HttpClientService()
{
$this->services['hwi_oauth.http_client'] = $instance = new \Buzz\Client\Curl();
$instance->setVerifyPeer(false);
$instance->setTimeout(10);

When you asking a question please specify your operating system and versions of frameworks you are using (e.g. symfony 2). Here is an answer for windows and symfony2
1) Delete manually added folders
2) If you don't have composer installed, install it
For windows
For other read this
2) Install HWIOAuthBundle
HWIOAuthBundle readme.md
option i) Using composer
Open the symfony project directory where composer.json resides.
Open command prompt (In Windows: Shift key + Right click => open command window here)
Run this
composer require hwi/oauth-bundle
OR
option ii) Add dependencies to your composer.json (not recomended)
"require": {
// other dependencies will be here //
"hwi/oauth-bundle": "^0.4.0",
"friendsofsymfony/user-bundle": "^1.3"
}
then execute following command
composer install

Related

Codeception Simple Unit Test Not Work To Find My Namespaces

I'm trying a basic UnitTest with Codeception. No frameworks are used.
My working root is as:
tests |
|-unit
|-Test.php
includes|
|-general
|-Custom.php
In Custom.php
<?php
namespace Custom;
class General {
public static function check(){}
}
My test case is:
<?php
use Custom\General;
use PHPUnit\Framework\TestCase;
final class Test extends TestCase
{
public function testPushAndPop(): void
{
General::check();
}
}
I also have in my composer.json:
"autoload": {
"psr-4":{
"Custom\\":"includes/general"
}
},
When I run
php vendor/bin/codecept run unit
...
1) Test: Push and pop
Test tests/unit/Test.php:testPushAndPop
[Error] Class 'DB\General' not found
#1 /var/www/html/prj/tests/unit/Test.php:9
Codeception Simple Unit Test Not Work To Find My Namespaces
This is less about Codeception but how PHP autoloading works in general and what the configuration of autoloading in Composer is in specific:
{
"autoload": {
"psr-4":{
"Custom\\":"includes/general"
}
}
}
Even the path-segment includes/general does map on the file-system path includes/general/ (composer should have told you to add / at the end of the path-segment), the error message
[Error] Class 'DB\General' not found
#1 /var/www/html/prj/tests/unit/Test.php:9
shows that the namespace of Custom\\ in the Composer configuration is different to the namespace of the class that is not found (which is DB\\).
So even the framework you have in use (you have one and that is the testing framework) may load the composer auto-loader (highly likely), its just that the class is not found.
As #Naktibalda already highlighted in a comment, it is just a plain autoloader configuration issue.
You are right, but why? The IDE does not claim any error... (your reaction)
These are two pair of shoes.
Your IDE most likely does not rely on the autoloader and just guesses the file from the file-system.
Depending how well maintained and configured your IDE is, it perhaps should and could have highlighted you that.
On the other hand, PHP can only rely on the autoloader, in your case you delegate the autoloading to composer(1), not to your IDE.
So maybe improve on that end as well, composer is more central for your projects development than the IDE can be.
So a suggestion:
Whenever changing the composer.json file, I suggest to run composer validate --strict to check your status, then follow with a composer update.
Run this automatically before running your tests. You may not want to run composer update, then run composer install before running the test-runner if you have it as a development dependency.
Example to bind this for a single test run command within your composer.json:
{
"scripts": {
"test": [
"#composer --no-plugins --version",
"#composer validate --strict",
"#composer --no-plugins -q install --no-scripts --no-progress",
"codecept run unit"
]
}
}
you then have a single call to run all the important things in your Composer based project:
$ composer test
...
Running unit-tests is a good way to verify the autoload configuration by the way. With the composer test-script you ensure it is always up-to-date when running the test-suite, too.
You don't need an IDE for this technically, which makes it more portable and stable giving you the peace of mind for your composer based project to grow.

howto fix composer.json in forked symfony bundle

I'm trying to install symfony-cmf/routing-auto version 2.0.0-RC1 , it requires jms/metadata:1.5.* which is working under Symfony 2x.
My current project works on Symfony 3.3.x which makes this bundle unable to install, so I made a fork on github, changed req. to jms/metadata:1.6.*
and added one line:
"replace": "symfony-cmf/routing-auto:2.0.0-RC1",
in order to test if it will work and I used in console:
composer require mkoniarz/routing-auto:dev-master
but then I got error:
Reading composer.json of mkoniarz/routing-auto (dev-master) Skipped branch dev-master, Invalid argument supplied for foreach()
What else I should fix to get this fork installed by composer?
PS my composer is up to date.
Did you try to remove the composer.json file ? I'd an similar error, i think it can be resolve your problem.
Or you should to try :
composer require symfony-cmf/routing-auto
always check composer.json:
composer.phar validate
then commit if valid :)
error was in "replace" line:
"replace": "symfony-cmf/routing-auto:2.0.0-RC1",
should be:
"replace": { "symfony-cmf/routing-auto":"2.0.0-RC1" },

Composer.phar update now results in an ErrorException for MonologBundle

symfony/symfony v2.2.0
monolog/monolog v1.4.1
After running composer.phar update yesterday, monolog was updated; running the same command today results in the following error message:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Generating autoload files
[ErrorException]
Warning: constant(): Couldn't find constant Monolog\Logger::DEBUG in [path]\vendor\symfony\monolog-bundle\Symfony\Bundle\MonologBundle\DependencyInjection\MonologExtension.php line 109
The (i think) relevant part of config_dev.yml
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
Did something change that requires additional configuration, or is something else happening ?
Monolog recently switch to PSR-4 compatible autoloading. Possibly, the
version of Composer you're running is too old for that. Please run
composer self-update first and try to update your dependencies again.
Sounds like the update didn't go well - do you have a Logger class in vendor/monolog/monolog/src/Monolog/Logger.php? If not I would suggest deleting the vendor/monolog dir and running composer install to get it back.
I had this same thing, but for Laravel.
I solved it by creating the app/storage folder and all it's sub-folders and files.
I get them by creating a new empty project, and just a copy-paste !
Woking now...
Here is the file structure:
app/storage/cache
app/storage/logs
app/storage/meta
app/storage/sessions
app/storage/views
You can ignore this folder for your repository.

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(),

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