I am trying to configure the bundle from : https://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html
and when I try to run the command :
$ php bin/console doctrine:fixtures:load
getting error:
In LoadDataFixturesDoctrineCommand.php line 95:
Could not find any fixture services to load.
You need to update (app/config/services.yml)
services:
resource: '../../src/DataFixtures/*'
https://symfony.com/doc/master/bundles/DoctrineFixturesBundle/index.html
Other problem is here in to the above tutorial
// src/DataFixtures/AppFixtures.php
namespace App\DataFixtures;
name space should be :
namespace DataFixtures;
Related
I am getting a lot of errors related to phpunit like
Class MyTest extends unknown class PHPUnit\Framework\TestCase
or
Call to an undefined method MyTest::assertFalse().
I am on Symfony 6 and use the docker image of phpstan
My Dockerfile:
FROM ghcr.io/phpstan/phpstan:1-php8.1
RUN composer global require phpstan/phpstan-phpunit phpstan/phpstan-doctrine phpstan/phpstan-symfony
My config:
parameters:
symfony:
containerXmlPath: /app/var/cache/dev/App_KernelDevDebugContainer.xml
scanDirectories:
- /app/vendor/bin/.phpunit/phpunit-9.5-0/vendor/
scanFiles:
- /app/vendor/bin/.phpunit/phpunit-9.5-0/vendor/autoload.php
includes:
- /composer/vendor/phpstan/phpstan-symfony/extension.neon
- /composer/vendor/phpstan/phpstan-symfony/rules.neon
- /composer/vendor/phpstan/phpstan-phpunit/extension.neon
- /composer/vendor/phpstan/phpstan-phpunit/rules.neon
What did I miss?
Try this instead of scanFiles:
bootstrapFiles:
- /app/vendor/bin/.phpunit/phpunit-9.5-0/vendor/autoload.php
I want to create a new entity in my ORO platform application by using the make:entity command from the MakerBundle.
I expect it to create an entity in my bundle Acme\Bundle\TestBundle which I set in my config_dev.yml by using:
maker:
root_namespace: 'Acme\Bundle\TestBundle'
So I execute
bin/console make:entity Test
which returns
! [NOTE] It looks like your app may be using a namespace other than "Acme\Bundle\TestBundle".
!
! To configure this and make your life easier, see:
! https://symfony.com/doc/current/bundles/SymfonyMakerBundle/index.html#configuration
created: src/Acme/Bundle/TestBundle/Entity/Test.php
created: src/Acme/Bundle/TestBundle/Repository/TestRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the
<info>Acme\Bundle\TestBundle\Entity\Test</info> class uses a different format. If you would like
this command to generate the properties & getter/setter methods, add your mapping configuration, and then
re-run this command with the <info>--regenerate</info> flag.
I've tried to run the command once again, which works. But obviously this is not the way how it's meant to work. So how can I fix this mapping error?
I started with the standard Symfony 5 project by using Symfony new myapp.
I add the config file in config/packages/dev/maker.yaml
maker:
root_namespace: 'App\Core'
To generate the entity in the src/Core folder, I got the following error:
➜ symfony console make:entity Post
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
[ERROR] Only annotation mapping is supported by make:entity, but the <info>App\Core\Entity\Post</info> class uses
a different format. If you would like this command to generate the properties & getter/setter methods, add your
mapping configuration, and then re-run this command with the <info>--regenerate</info> flag.
To avoid showing the error in the console, I install the patch created by vklux / maker-bundle-force-annotation
Step 1: install package
composer require cweagans/composer-patches
Step 2: apply the patch in composer.json
{
// {...} composer.json content
"extra": {
"patches": {
"symfony/maker-bundle": {
"Provide flag to force annotation in make entity command": "https://raw.githubusercontent.com/vklux/maker-bundle-force-annotation/master/maker-force-annotation-flag.patch"
}
}
}
}
Step 3: composer update
composer update
Step 4: try make:entity with the additional command option
➜ symfony console make:entity Post --force-annotation
created: src/Core/Entity/Post.php
created: src/Core/Repository/PostRepository.php
Entity generated! Now let's add some fields!
You can always add more fields later manually or by re-running this command.
New property name (press <return> to stop adding fields):
>
✅ 🚀 👍 Everything works fine now.
It's a bug in the doctrine version please try this version good luck
composer req doctrine/doctrine-bundle:2.2
I found a solution to create new entities with Symfony maker using doctrine/doctrine-bundle version higher than 2.2.4
These steps worked for me with:
"doctrine/doctrine-bundle": "^2.7"
PHP 8.1 (I migrate from php 7.4 in my case)
STEP 1: replace type: annotation by type: attribute inside doctrine.yaml
STEP 2: Enter entity root with namespace:
symfony console make:entity App\Entity\test
I have a symfony 3.3 application deployed to a shared hosting, when accessing any url of the application i got this error:
[2018-01-17 21:54:24] request.CRITICAL: Uncaught PHP Exception
Symfony\Component\Config\Exception\FileLoaderLoadException:
"[Semantical Error] The annotation
"#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route" in class
AppBundle\Controller\ConventionAccommodationController does not exist,
or could not be auto-loaded in
/usr/home/convenciones.bookingarea.com/web/src/AppBundle/Controller/
(which is being imported from
"/usr/home/convenciones.bookingarea.com/web/app/config/routing.yml").
Make sure annotations are enabled." at
/usr/home/convenciones.bookingarea.com/web/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php
line 168 {"exception":"[object]
(Symfony\Component\Config\Exception\FileLoaderLoadException(code:
0): [Semantical Error] The annotation
\"#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route\" in
class AppBundle\Controller\ConventionAccommodationController does
not exist, or could not be auto-loaded in
/usr/home/convenciones.bookingarea.com/web/src/AppBundle/Controller/
(which is being imported from
\"/usr/home/convenciones.bookingarea.com/web/app/config/routing.yml\").
Make sure annotations are enabled. at
/usr/home/convenciones.bookingarea.com/web/vendor/symfony/symfony/src/Symfony/Component/Config/Loader/FileLoader.php:168,
Doctrine\Common\Annotations\AnnotationException(code: 0):
[Semantical Error] The annotation
\"#Sensio\Bundle\FrameworkExtraBundle\Configuration\Route\" in
class AppBundle\Controller\ConventionAccommodationController does
not exist, or could not be auto-loaded. at
/usr/home/convenciones.bookingarea.com/web/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php:54)"}
[]
Be aware that i am not able to execute composer.phar in the shared machine so i have to launch install and dump-autoload commands at my local machine and rsync vendor and var/bootstrap.php.cache of my machine with the production server directory.
This code and configuration works without problems in local develop machines and a staging server at Rackspace but throws the FileLoaderLoadException in the shared hosting for production.
I have disabled opcache and apc in the production server to discard php accelerator issues. That change do not solve the issue.
#app/config/routing.yml
app:
resource: '#AppBundle/Controller/'
type: annotation
#src/AppBundle/Controller/ConventionAccommodationController
<?php
namespace AppBundle\Controller;
use AppBundle\Entity\Sala;
use AppBundle\Entity\Hotel;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
.....
$ ls vendor/sensio/framework-extra-bundle/Configuration/
Cache.php Method.php Security.php
ConfigurationAnnotation.php ParamConverter.php Template.php
ConfigurationInterface.php Route.php
thanks a lot any clue welcomed.
I have just managed to solve this with composer clearcache followed by composer update.
I tried to install OSExcelBundle (https://github.com/ouardisoft/OSExcelBundle) on Symfony 2.1 by following the README :
Add this line to the require option in your composer.json file: "os/excel-bundle": "dev-master"
OK
Add autoloader for PHPExcel in app/autoloader.php : require __DIR__.'/../vendor/os/php-excel/PHPExcel/PHPExcel.php'; There is no app/autoloader.php in symfony 2.1 - I tried to add the line in app/autoload.php - without success.
This works : php composer.phar install
But without step 2 this does not work : I get this error message :
You have requested a non-existent service "os.excel"
If someone can give me a hint would be nice ...
Edit :
I added this line in AppKernel : new OS\ExcelBundle\OSExcelBundle(),
and so the bundle seems to be taken in account.
Nevertheless now I get this error :
Fatal error: Class 'PHPExcel_IOFactory' not found in ..\vendor\os\excel-bundle\OS\ExcelBundle\Excel\Excel.php on line 29
So I really need to know where I can declare PHPExcel !
I installed an other bundle : ExcelBundle
This one no problem to install (???)
And !!! : it resolves my problem with the other bundle - because it made PHPExcel available
So I can go on ...
I learn Symfony 2. I would like have example with SonataAdminBundle. I found:
http://sonata-project.org/bundles/news/2-0/doc/reference/installation.html
but this haven't first point.
i found:
[SonataAdminBundle]
git=http://github.com/sonata-project/SonataAdminBundle.git
target=/bundles/Sonata/AdminBundle
[SonataBlockBundle]
git=http://github.com/sonata-project/SonataBlockBundle.git
target=/bundles/Sonata/BlockBundle
[SonataCacheBundle]
git=http://github.com/sonata-project/SonataCacheBundle.git
target=/bundles/Sonata/CacheBundle
[SonatajQueryBundle]
git=http://github.com/sonata-project/SonatajQueryBundle.git
target=/bundles/Sonata/jQueryBundle
[SonataDoctrineORMAdminBundle]
git=http://github.com/sonata-project/SonataDoctrineORMAdminBundle.git
target=/bundles/Sonata/DoctrineORMAdminBundle
[KnpMenuBundle]
git=http://github.com/KnpLabs/KnpMenuBundle.git
target=/bundles/Knp/Bundle/MenuBundle
[KnpMenu]
git=http://github.com/KnpLabs/KnpMenu.git
target=/knp/menu
[Exporter]
git=http://github.com/sonata-project/exporter.git
target=/exporter
[SonataNewsBundle]
git=http://github.com/sonata-project/SonataNewsBundle.git
target=/bundles/Sonata/NewsBundle
and run bin/install vendors. . Install is correct. Id added line to AppKernel and autoload, and if i run:
php app/console sonata:easy-extends:generate SonataNewsBundle
i have error:
[InvalidArgumentException]
Bundle "ApplicationSonataNewsBundle" does not exist or it is not
enabled.
So i added:
new Application\Sonata\NewsBundle\ApplicationSonataNewsBundle(),
and run
php app/console sonata:easy-extends:generate SonataNewsBundle
then i have error:
PHP Fatal error: Class
'Application\Sonata\NewsBundle\ApplicationSonataNewsBundle' not found
in /home/lanox06/Projects/sym2/app/AppKernel.php on line 29
How can i make this? I would like testing these application.
You should move the ./app/Application folder from ./app to the ./src directory.
An other solution is to add the --dest=src option like this :
php app/console sonata:easy-extends:generate --dest=src SonataNewsBundle