Yii2 Testing error while codeception run command is issued - php

I've got a test suite in yii2 that I would like to run, I have installed composer, codeception, built the test with 'codecept build' and so far so good, everything was smooth as butter until I've issued the command 'codecept run'; it throws an error which by any means I have tried to figured out unfortunately unsuccessfully. I have reinstalled composer, clear the composer cache, rebuilt the project again with codecept build but not success whatsoever.
The error is as follows:
MyApp\tests.functional Tests (4) -----------------------------------------------------------------
- HomeCest: Check open<pre>PHP User Error 'yii\base\ErrorException' with message 'Exception 'yii\base\InvalidParamException' with message 'The file or directory to be published does not exist: /home/user/GIT_MyApp/yii/myapp/vendor/bower/jquery/dist'
in /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php:453
Stack trace:
#0 /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetBundle.php(185): yii\web\AssetManager->publish('/home/angelo/GI...', Array)
#1 /home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php(268): yii\web\AssetBundle->publish(Object(yii\web\AssetManager))
#2
/home/user/GIT_MyApp/yii/vendor/yiisoft/yii2/web/AssetManager.php(239): yii\web\AssetManager->loadBundle('yii\\web\\JqueryA...', Array, true)
.....
.....
The weirdest thing though, is that the same project runs fine in another machine (CENT OS). Mine is Kubuntu 16.04. Could it be the machine?
Could someone please tell me what is happening and why this error keeps on coming?

You have to install fxp/composer-asset-plugin with composer globally:
composer global require "fxp/composer-asset-plugin:~1.3.1"
Like here: https://github.com/yiisoft/yii2-app-basic/blob/2.0.12/.travis.yml#L20

Related

Using PHPUnit in PhpStorm using Docker

I have a very specific configuration that I have to hold until I can start moving feature from my old PHP 5 application to somewhere else.
I'm trying to tie my testing environment with PhpStorm but I cant figure it out. Since I'm not using Composer, I have to specify phpunit.phar path (which is /usr/local/bin/phpunit - a symlink to /usr/local/bin/phpunit.phar). I keep having this error.
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot create phar '/usr/local/bin/phpunit', file extension (or combination) not recognised or the directory does not exist' in /opt/.phpstorm_helpers/phpunit.php:181
Stack trace:
#0 /opt/.phpstorm_helpers/phpunit.php(181): Phar->__construct('/usr/local/bin/...')
#1 /opt/.phpstorm_helpers/phpunit.php(250): IDE_PHPUnit_Loader::init()
#2 {main}
thrown in /opt/.phpstorm_helpers/phpunit.php on line 181
The setup on my Docker is
PHP 5.5.9 with PHPUnit 4.8.9
My remote Docker PHP interpreter works in PhpStorm, and my PHPUnit works when I run test in bash (using docker exec phpunit) - so it seems that the pieces are working, mostly the glue doesn't work.
Here are my settings
I just ran into this problem with composer and the issue is you need to set up a PHPUnit interpreter in PHPStorm with the autoload.php file.
Open Settings > Languages & Frameworks > PHP > Test Frameworks
Click the Plus + icon to add a Remote Interpreter
Select the CLI interpreter previously defined and use existing path mappings
Select Use Composer Autoloader
Path to script should be /path/to/vendor/autoload.php
Check off Default configuration file and set it to /path/to/phpunit.xml
I also needed to have the following section in my docker-compose.yml:
services:
my-api:
# Other contents omitted
environment:
- PHP_IDE_CONFIG=serverName=my-api.company.com
Where my-api.company.com is the server definition name from Settings > Languages & Frameworks > PHP > Servers

Symfony is suddenly failing with "The service "session.storage.metadata_bag" has a dependency on a non-existent parameter"

I upgraded from Symfony 3.1.5 to 3.2.0 yesterday morning and everything was fine up until an hour or so ago.
Now Symfony throws the following exception upon any type of access, including console commands:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service "session.storage.metadata_bag" has a dependency on a
non-existent parameter "session.metadata.storage_key".
I have tried the following:
Backed out my most recent changes
Deleted var/cache/*
Here is the exception trace:
Exception trace:
() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:100
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/EnvPlaceholderParameterBag.php:56
Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag->get() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:217
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveString() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:187
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBag.php:177
Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->resolveValue() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/ResolveParameterPlaceHoldersPass.php:39
Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass->process() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:120
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:565
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:484
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:116
Symfony\Component\HttpKernel\Kernel->boot() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Volumes/Data01/Projects/Beck/WWUI/site/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
Symfony\Component\Console\Application->run() at /Volumes/Data01/Projects/Beck/WWUI/site/bin/console:29
As you can see, it's part of Symfony, and not my code.
I am at a loss.
Has anybody else seen this?
Suggestions?
Edit 1:
Based on Dagon's suggestion that I check session.xml, and seeing that it appears correct, I decided to replace the
<argument>%session.metadata.storage_key%</argument>
tag with
<argument>_sf2_meta</argument>
in session.xml. This resulted in a new, similar error:
[Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]
The service
"64e3c91c625381e3c2c0184cf9ea0c6d5353986d77aa111949ca6fb8b17a8f07_2"
has a dependency on a non-existent parameter "validator.mapping.
cache.prefix".
This isn't really an answer per-se, but is is a fix.
I renamed vendor to vendor-HOLD and then ran composer install. Problem gone.
I did a diff on the old and new session.xml files and found that the definition of the parameter was different. The version causing the error contained:
<parameter string="session.metadata.storage_key">_sf2_meta</parameter>
The newly installed version contained:
<parameter key="session.metadata.storage_key">_sf2_meta</parameter>
instead. Obviously other files were incorrect, as well, based on the experimental edit I did to session.xml. No clue as to what happened, but it's nice that composer install fixed it. Oh, and yes, I deleted vendor-HOLD afterwards.

Artisan CronJob - There are no commands defined in the "xyz" namespace

I am having a bit of a strange problem with an artisan command I have setup.
The command is:
cd /var/sites/p/mydomain.co.uk/public_html/ && /usr/bin/php-5.4 artisan property:import
This command works perfectly when run via ssh or on a local machine, but fails to run when set as a CronJob and returns the following error in the Laravel log file.
[2014-06-17 13:50:06] production.ERROR: exception 'InvalidArgumentException' with message 'There are no commands defined in the "property" namespace.' in /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php:514
Stack trace:
#0 /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(548): Symfony\Component\Console\Application->findNamespace('property')
#1 /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(188): Symfony\Component\Console\Application->find('property:import')
#2 /var/sites/p/mydomain.co.uk/public_html/vendor/symfony/console/Symfony/Component/Console/Application.php(121): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 /var/sites/p/mydomain.co.uk/public_html/artisan(58): Symfony\Component\Console\Application->run()
#4 {main} [] []
I am rather stuck and have no idea why the "property" namespace would not be found when being run as a cron. When running the exact same command via ssh, it works perfectly, when running on a local machine, it works perfectly.
Would there be anything in artisan that is causing it not to load the app/start/artisan.php file when run as a cronjob at all?
Any help would be greatly appreciated. If you need any further details, let me know and I will provide what I can.
Thanks,
Joe
After a long time of checking and speaking with the hosting provider it turned out that running /usr/bin/php-5.4 was running the cgi version of php, changing this to /usr/bin/php-5.4-cli fixed the issue.
This would of course very depending on your hosting providers setup.

PHP / Composer cannot redeclare

I was happily working away in my development environment and suddenly I started getting the following error:
PHP Fatal error: Cannot redeclare composerRequire7a368ac394ae1d2e857becf2a235ebaa() (previously declared in [APP_ROOT]/vendor/composer/autoload_real.php:56) in [APP_ROOT]/vendor/composer/autoload_real.php on line 59
I haven't made any changes to speak of in composer dependencies (although I think I did do a composer update somewhere in that timeframe but no changes to the dependencies/packages used so nothing big should have changed.
Notably, when I checkout the repo on my laptop I do NOT get this error but if I git clone a clean repo and then composer install on my main development machine I DO get this error. So I'm assuming it must have some machine-specific origin but I'm running out of ideas on what that might be.
Any help would be greatly appreciated.
Note: I'm running PHP 5.3.28 on OSX; my app uses namespacing and is PSR0 compliant
Also of note is that I'm running PHPUnit 4.0.17 and the error is triggered at the very first stages of trying to run a unit test (it doesn't matter WHICH unit test). Here's the stack trace:
0.0009 636648 1. {main}() [APP_BASE]/vendor/phpunit/phpunit/phpunit:0
0.0465 1423664 2. PHPUnit_TextUI_Command::main() [APP_BASE]/vendor/phpunit/phpunit/phpunit:54
0.0465 1424280 3. PHPUnit_TextUI_Command->run() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:132
0.0465 1424280 4. PHPUnit_TextUI_Command->handleArguments() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:141
0.0674 2123344 5. PHPUnit_TextUI_Command->handleBootstrap() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:638
0.0681 2139872 6. PHPUnit_Util_Fileloader::checkAndLoad() [APP_BASE]/vendor/phpunit/phpunit/src/TextUI/Command.php:808
0.0681 2140008 7. PHPUnit_Util_Fileloader::load() [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:77
0.0774 2144176 8. include_once('[APP_BASE]/tests/test-loader.php') [APP_BASE]/vendor/phpunit/phpunit/src/Util/Fileloader.php:93
0.0775 2146736 9. include('[APP_BASE]/vendor/autoload.php') [APP_BASE]/tests/test-loader.php:2
Delete composer.lock and vendor/ and run composer update again.
I had this problem when I made a copy of an existing project directory and tried to run phpunit on the new directory. Finally figured out that when I executed phpunit, it was running out of the old directory. I ran this:
which phpunit
And saw that it was running from my composer vendor directory:
/home/vagrant/Code/MYOLDPROJECT/api/vendor/bin/phpunit
I ran phpunit from the new directory and the problem disappeared:
/home/vagrant/Code/mynewproject/api/vendor/bin/phpunit

Trouble with ZFTool: Module (ZFTool) could not be initialized

ZFTool is the maintenance tool for Zend Framework applications. There are several ways to install it. I use it from a PHAR file.
$ mkdir -p /usr/lib/ZendFramework/zftool
$ cd /usr/lib/ZendFramework/zftool
$ wget http://packages.zendframework.com/zftool.phar
$ ln -s /usr/lib/ZendFramework/zftool/zftool.phar /usr/bin/zf
$ chmod 755 /usr/bin/zf
It works, when I execute the tool outside of a ZF application. But now I tried this whithin an application and get this error:
root#devvm:/usr/lib/ZendFramework/test# cd /path/to/application/ root#devvm:/path/to/application# zf PHP Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (ZFTool) could not be initialized.' in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php:175 Stack trace:
#0 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(149): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('ZFTool')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 /path/to/application/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php( in /path/to/application/vendor/zendframework/zendframework/library/Zend/ModuleManager/ModuleManager.php on line 175
Why does it happen? How to avoid this behavior?
It appears you need to install zftool into your project. user2900416 kind of hinted at this, but I think it is more correct to install zftool using composer like so for each project:
composer.phar require zendframework/zftool:dev-master
This solved it for me. It is discussed in an issue here: https://github.com/zendframework/ZFTool/issues/51
Check the case of the module.php file:
Make sure your **M**odule.php file is written with a capital M otherwise the file may not be found. This took me a day to bug test so I really hope I save someone the same trouble!
I got the same problem. This is what I did to fix it with 2 steps:
(1) Download ZFTool zipball as suggested by manual installation at http://framework.zend.com/manual/2.1/en/modules/zendtool.introduction.html.
(2) Unzip the zipball under your application's module/ directory with directory name as ZFTool/.
Then, the Module(ZFTool) has been installed in your application and can be initialized by either invoking
"zftool.phar create module ModuleName"
or
"zf.php create module ModuleName" where zf.php is in the zipball.
It looks REALLY stupid to copy the ZFTool module inside each application but I have spent days in trying to find a better one without any luck.n Hope someone can propose one.

Categories