In my composer.json, I added doctrine-fixtures-bundle in require-dev as recommended in the documentation
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3",
...
},
I created a new symfony benchmark environment, but I cannot access the fixtures :
$ APP_ENV=benchmark php bin/console doctrine:fixtures:load
You may be looking for a command provided by the "DoctrineFixturesBundle" which is currently not installed. Try running "composer require doctrine/doctrine-fixtures-bundle --dev"
Fixtures is available in dev. How to make it also accessible in benchmark environment ?
I don't think adding fixtures in require to composer.json is a good idea : it's not safe.
You should not define this library as a dev dependency then. Move it from the require-dev to the require section and reinstall vendors with Composer.
It's "not safe" as in you could potentially load the fixtures on production and erase your database. If you are afraid you could do so, you can load this bundle for the benchmark environment only, eg.:
// config/bundles.php
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'benchmark' => true],
Related
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.
After running composer update , I keep having the error below:
Warning: Ambiguous class resolution,
"Doctrine\ORM\Persisters\Entity\BasicEntityPersister" was found in
both "$baseDir .
'/engine/Library/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php"
and
"/var/www/html/shop5/vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php",
the first will be used. Warning: Ambiguous class resolution,
"Doctrine\Common\Proxy\AbstractProxyFactory" was found in both
"$baseDir .
'/engine/Library/Doctrine/Common/Proxy/AbstractProxyFactory.php" and
"/var/www/html/shop5/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php",
the first will be used.
I have tried to run the following commands but none of them works:
composer dump-autoload -o
composer clearcache
Any idea how to fix this issue ?
Thank you
[shopware5 - php7.0]
This is the normal behavior of Shopware.
The Doctrine library uses the final class statement quite often and in order to get it to work with the Shopware attribute system the classes were replaced through the composer autoloading. You can find the changed files in shopware/engine/Library/Doctrine/Common
FYI: This is the reason why Shopware only works when the composer autoloading is optimized.
composer dump-autoload --optimize
Otherwiese you will encounter random errors from invalid or wrong entities.
To get rid of these warning you should add files with ambiguous classes to exclude-from-classmap in your composer.json:
"autoload": {
...
"exclude-from-classmap": [
...
"vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php",
"vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php"
]
},
Then dump-autoload will ignore these files.
This is the reason why Shopware only works when the composer autoloading is optimized.
I didn't investigate how this is done in Shopware, but this also could be fixed/improved. For composer more precise definitions for namespaces have a precedence. So if you have this in your autoload:
"autoload": {
"psr-0": {
"somevendor\\somepackage\\": "vendor/somevendor/somepackage/",
"somevendor\\somepackage\\db\\": "overrides/somevendor/somepackage/db/"
}
},
And if you request for somevendor\somepackage\db\Entity class, the composer will first search in overrides/somevendor/somepackage/db/Entity.php and only if it can't find it, it will try vendor/somevendor/somepackage/db/Entity.php. This is because definition for somevendor\somepackage\db namespace is more precise than for somevendor\somepackage.
So if you want to override 3rd-party classes in this way, you should define more precise namespaces than 3rd-party library do.
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" },
I need to generate Excel files, I did a search and phpexcel seems to be good and stable. I'd like to know:
* how to integrate it into my project given that it's a symfony2.0 project
* if I can do all what I do normally on excel file through this php library (cells colors, adding lists ...)
Thanks,
If you are using composer, and since PHPExcel is registered with Packagist, then this is simply a matter of adding PHPExcel to your composer.json config, for example:
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
...
"phpoffice/phpexcel": "~1.8.0",
This is from a Symfony 2.4 configuration, but should work equally well for any version of Symfony.
Run $ php composer.phar update to grab the package and it should then be autoloaded into your project. You can then use PHPExcel immediately, say in a controller:
<?php
namespace SomeProject\SomeBundle\Controller;
use PHPExcel;
Or just reference \PHPExcel directly from within your code.
Update:
Note that composer found it's way into Symfony from around version 2.0.4, and was used as an alternative to the old deps and deps.lock files until the deps approach was deprecated from 2.1.
If you're still using deps, you can append this to your deps file:
[PHPExcel]
git=git://github.com/PHPOffice/PHPExcel.git
target=phpexcel
and run php bin/vendors install. This will put the PHPExcel in vendors/phpexcel.
Register PHPExcel with the registerPrefixes array in app/autoload.php and it should be available to your project as described above.
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
'PHPExcel' => __DIR__.'/../vendor/phpexcel/Classes'
));
basically i have this composer.json file:
{
"name": "phpunit/phpunit",
"require": {
"phpunit/phpunit": "3.8.*#dev"
},
"authors": [
{
"name": "Sebastian Bergmann",
"email": "sebastian#phpunit.de"
}
]
}
and when I go to run "composer install" i get the following error:
Loading composer repositories with package information
Installing dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for phpunit/phpunit 3.8.*#dev -> satisfiable by phpunit/phpunit[3.8.x-dev].
- phpunit/phpunit 3.8.x-dev requires phpunit/php-code-coverage 1.3.*#dev -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
I have no clue as to what that means? Thanks
Before actually answering your question:
You have called your project phpunit/phpunit and you have a require on phpunit/phpunit. That is a circular dependency. You should call your project something else.
Also, I doubt that you are "Sebastian Bergmann" so you should change the name of the author and email address in your composer file.
Ok, for you actual question, Composer by default won't install dev packages. You need to explicitly tell it to install dev packages by putting
"minimum-stability": "dev"
in your root composer.json file for your project, or change the require for PHPUnit to not use the dev package e.g.
"require": {
"phpunit/phpunit": "3.8.*"
},
Unless you are actively debugging an issue in another package, it's unlikely that you actually want to use a dev version of that package. You almost always want an actual tagged version.