To generate my Symfony Entities I have some Doctrine schemas. E.g at
src/Numbers/Bundle/NumbersBundle/config/doctrine/Numbers.orm.yml
[UPDATE: also tried this with the same problem...
src/Numbers/Bundle/NumbersBundle/Resources/config/doctrine/Number.orm.yml ]
and I'm running:
php bin/console doctrine:generate:entities Numbers/Bundle/NumbersBundle
which gives
Generating entities for namespace "Numbers\Bundle\NumbersBundle"
[RuntimeException]
Namespace "Numbers\Bundle\NumbersBundle" does not contain any mapped entities.
If it helps the YML is:
# src/Numbers/Bundle/NumbersBundle/Resources/config/doctrine/Numbers.orm.yml
Numbers\Bundle\NumbersBundle\Entity\Number:
type: entity
table: numbers
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
value:
type: integer
unique: true
name:
type: string
length: 255
unique: true
Any suggestions what the problem might be or how you can debug this to see what bin/console doctrine:generate:entities is doing?
UPDATE
For what it's worth with -vvv I get this (doesn't seem to help much though):
php bin/console -vvv doctrine:generate:entities Numbers\Bundle\NumbersBundle
Generating entities for namespace "NumbersBundleNumbersBundle"
[RuntimeException]
Namespace "NumbersBundleNumbersBundle" does not contain any mapped entities.
Exception trace:
() at /Users/snowcrash/numbers/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:103
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getNamespaceMetadata() at /Users/snowcrash/numbers/vendor/doctrine/doctrine-bundle/Command/GenerateEntitiesDoctrineCommand.php:109
Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() at /Users/snowcrash/numbers/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:255
Symfony\Component\Console\Command\Command->run() at /Users/snowcrash/numbers/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:846
Symfony\Component\Console\Application->doRunCommand() at /Users/snowcrash/numbers/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:191
Symfony\Component\Console\Application->doRun() at /Users/snowcrash/numbers/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/snowcrash/numbers/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:122
Symfony\Component\Console\Application->run() at /Users/snowcrash/numbers/bin/console:28
doctrine:generate:entities [--path PATH] [--no-backup] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> <name>
UPDATE 2
Now with a simpler Namespace:
# src/NumbersBundle/Resources/config/doctrine/Number.orm.yml
NumberBundle\Entity\Number:
type: entity
table: numbers
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
value:
type: integer
unique: true
name:
type: string
length: 255
unique: true
php bin/console doctrine:generate:entities NumbersBundle
Generating entities for namespace "NumbersBundle"
[RuntimeException]
Namespace "NumbersBundle" does not contain any mapped entities.
with the file at
src/NumbersBundle/Resources/config/doctrine/Number.orm.yml
and specifying the Entity:
php bin/console doctrine:generate:entities NumbersBundle:Number
[Doctrine\ORM\ORMException]
Unknown Entity namespace alias 'NumbersBundle'.
Related
I'm developing a Symfony 5.1 project under DDD, so I'm changing a bit all the default folders.
I have 2 bundles inside src folder and at the moment I only have entities inside one of them.
I generated the Entity User and its repository with the command make:user and then moved the files and changed namespaces, routes, configs, etc
When I run php bin/console make:migration I get an error "No mapping information to process"
$ run php bin/console make:migration -v
In NoMappingFound.php line 13:
[Doctrine\Migrations\Provider\Exception\NoMappingFound]
No mapping information to process
The folders are:
src
|-- Smartlink
|-- UserBundle/SmartlinkUserBundle.php
|-- Application
|-- Domain
| |-- Entity/User.php
| |-- interfaces/UserRepository.php
|-- Infrastructure
|-- Repository/MysqlUserRepository.php
The configuration is:
// composer.json
"autoload": {
"psr-4": {
"UserBundle\\": "src/Smartlink/UserBundle",
"SmartlinkBundle\\": "src/Smartlink/SmartlinkBundle",
"App\\": "src/"
}
},
===============================================
// config/bundles.php
return [
...
UserBundle\SmartlinkUserBundle::class => ['all' => true],
SmartlinkBundle\SmartlinkSmartlinkBundle::class => ['all' => true],
];
===============================================
// config/services.yaml
services:
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
UserBundle\:
resource: '../src/Smartlink/UserBundle/'
exclude:
- '../src/Smartlink/UserBundle/Domain/Entity/'
SmartlinkBundle\:
resource: '../src/Smartlink/SmartlinkBundle/'
exclude:
- '../src/Smartlink/SmartlinkBundle/Domain/Entity/'
App\:
resource: '../src/'
exclude:
- '../src/DependencyInjection/'
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
- '../src/Smartlink/'
===============================================
// config/routes/annotations.yaml
userbundle_controllers:
resource: ../../src/Smartlink/UserBundle/Infrastructure/Controller
type: annotation
smartlinkbundle_controllers:
resource: ../../src/Smartlink/SmartlinkBundle/Infrastructure/Controller
type: annotation
controllers:
resource: ../../src/Controller/
type: annotation
kernel:
resource: ../../src/Kernel.php
type: annotation
===============================================
// config/packages/doctrine.yaml
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
SmartlinkUserBundle:
is_bundle: true
type: annotation
dir: 'Domain/Entity'
alias: user_bundle
SmartlinkSmartlinkBundle:
is_bundle: true
type: annotation
dir: 'Domain/Entity'
alias: smartlink_bundle
The UserRepository is the same that generated the make:user command except for the namespace, which is changed to namespace UserBundle\Infrastructure\Repository; and the name that is changed to MysqlUserRepository that implements the interface UserRepository
And the entity User is
namespace UserBundle\Domain\Entity;
use UserBundle\Infrastructure\Repository\MysqlUserRepository;
/**
* #ORM\Entity(repositoryClass=MysqlUserRepository::class)
*/
class User implements UserInterface
{
...
I've been searching and all I have found is about symfony 2 and symfony 4, I tried the same that worked for the people who was asking, but still can't generate the migration of the bundles. what am I missing?
Edit: I changed some configurations and solved the UserBundle is not found or is not active but the main migration problem remains
Finally I found an answer, the solution is in the file config/packages/doctrine.yaml
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
SmartlinkUserBundle:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Smartlink/UserBundle/Domain/Entity' # 'Domain/Entity'
prefix: 'UserBundle\Domain\Entity'
alias: UserBundle
SmartlinkSmartlinkBundle:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Smartlink/SmartlinkBundle/Domain/Entity'
prefix: 'SmartlinkBundle\Domain\Entity'
alias: SmartlinkBundle
The fix is setting in_bundle to false
the dir: was wrong, so I had to fix it
and I added the prefix, without the prefix there was an error.
And now it works.
How it is possible through dotenv select different entity path with same name of entities.
Originally, We had application in Symfony 3 for people meetings on events of our organization. Then we decided to offer this application to our partners.
One of the partners asked us to customize the application for them with their data and specifications. We basically created a new instance of Symfony application with copy of database tables (with different prefix), changes in Entities to reflect new db table names, and some translation text changes.
It seems that other partners will follow this trend of customized instances.
Therefore, I am trying to update core application to Symfony 4 and I am trying to use multiple Entity Managers and dotenv to differentiate between partners database tables, as described bellow.
In a nutshell, I am trying to use multiple Entity Manager to switch db table names by prefix.
.env
###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=oci8://user:pass#127.0.0.1:1521/XE
EM_TYPE=OpenAccess
###< doctrine/doctrine-bundle ###
Only in security.yaml working env good
security:
encoders:
App\Entity\%env(EM_TYPE)%\Osoba:
providers:
our_db_provider:
entity:
class: App\Entity\%env(EM_TYPE)%\Osoba
property: username
When i tried get %env(EM_TYPE)% in default_entity_manager, then give error You have requested a non-existent service "doctrine.orm.%env(EM_TYPE)%_entity_manager". doctrine.yaml
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
default_connection: '%env(EM_TYPE)%'
connections:
MeetingTool:
driver: 'oci8'
charset: UTF8
schema_filter: /^MT_/
url: '%env(resolve:DATABASE_URL)%'
OpenAccess:
driver: 'oci8'
charset: UTF8
schema_filter: /^OA6_/
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
default_entity_manager: '%env(EM_TYPE)%'
entity_managers:
MeetingTool:
connection: MeetingTool
mappings:
Main:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/MeetingTool'
prefix: 'App\Entity\MeetingTool'
alias: App2
OpenAccess:
connection: OpenAccess
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity/OpenAccess'
prefix: 'App\Entity\OpenAccess'
alias: OpenAccess
and biggest problem is use, how i targeting right entity here? for example loginController.php
<?php
namespace App\Controller;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\OpenAccess\LogPrihlaseni;
//use App\Entity\MeetingTool\LogPrihlaseni;
class LoginController extends AbstractController {
private $entityManager;
public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}
public function logPrihlaseni() {
$log = new LogPrihlaseni();
I want to use AWS macro Transform::Include with some dynamic parameters for my file.
Resources:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
TestMacroVariable:
Default: 2
Type: Number
Location: !Sub "s3://${InstallBucketName}/test.yaml"
test.yaml:
DataAutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
LaunchConfigurationName:
Ref: DataLaunchConfiguration
MinSize: '1'
MaxSize: '100'
DesiredCapacity:
Ref: TestMacroVariable
...
After calling: aws cloudformation describe-stack-events --stack-name $stack
I get:
"ResourceStatusReason": "The value of parameter TestMacroVariable
under transform Include must resolve to a string, number, boolean or a
list of any of these.. Rollback requested by user."
When I try to do it this way:
Resources:
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
TestMacroVariable: 2
Location: !Sub "s3://${InstallBucketName}/test.yaml"
I get:
"ResourceStatusReason": "Template format error: Unresolved resource
dependencies [TestMacroVariable] in the Resources block of the
template"
Error is the same when I don't provide TestMacroVariable at all.
Tried with different types: String, Number, Boolean, List - none of them work.
As i know you cannot have anything other than Location key in the Parameters section of the AWS::Include. Check here AWS DOC
As an alternative, you can pass in the whole S3 path as a parameter and reference it in Location:
Parameters:
MyS3Path:
Type: String
Default: 's3://my-cf-templates/my-include.yaml'
...
'Fn::Transform':
Name: 'AWS::Include'
Parameters:
Location: !Ref MyS3Path
Building on what #BatteryAcid Said you can refer the parameters in your Cloudformation template directly from your file using Sub function:
In your CF template :
Parameters:
TableName:
Type: String
Description: Table Name of the Dynamo DB Users table
Default: 'Users'
In the file you are including:
"Resource": [
{
"Fn::Sub": [
"arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}",
{
"tableName": {
"Ref": "TableName"
}
}
]
}
Alternatively doesn't have to be a parameter but any resource from your template :
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${QueryTelemtryFunction.Arn}/invocations
I want use postrepgis in doctrine. I have find creof/doctrine2-spatial and I try use it. I have this error :
[Semantical Error] line 0, col 15 near 'ST_Contains(v.geopoint': Error: Class 'ST_Contains' is not defined.
I don't know why, I have read the documentation, I have try many differents configurations but alltimes same problem.
My config.yml
doctrine:
dbal:
driver: pdo_pgsql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
types:
geometry: CrEOF\Spatial\DBAL\Types\GeometryType
point: CrEOF\Spatial\DBAL\Types\Geometry\PointType
polygon: CrEOF\Spatial\DBAL\Types\Geometry\PolygonType
linestring: CrEOF\Spatial\DBAL\Types\Geometry\LineStringType
mapping_types:
_text: string
orm:
auto_generate_proxy_classes: "%kernel.debug%"
#naming_strategy: doctrine.orm.naming_strategy.underscore
entity_managers:
default:
dql:
numeric_functions:
ST_Contains: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains
Contains: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STContains
st_area: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STArea
st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\GeomFromText
st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STIntersects
st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STBuffer
point: CrEOF\Spatial\ORM\Query\AST\Functions\PostgreSql\STPoint
auto_mapping: true
And my repository
public function findPointIn(){
$queryBuilder = $this->_em->createQueryBuilder();
$queryBuilder = $queryBuilder->select('v')
->where(
$queryBuilder->expr()->eq(
sprintf("ST_Contains(v.geopoint , v.geopoint)"),
$queryBuilder->expr()->literal(true)
)
);
return $queryBuilder->getQuery()->getResult();
}
According to documentation, your numeric_functions names in config.yml must be lowercase. Change to:
numeric_functions:
st_contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
st_area: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area
st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects
st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer
point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point
I am using codeception for testing in laravel 5.2.
Here is my codeception.yml file:
actor: Tester
paths:
tests: tests_codecept
log: tests_codecept/_output
data: tests_codecept/_data
support: tests_codecept/_support
envs: tests_codecept/_envs
settings:
bootstrap: _bootstrap.php
colors: false
memory_limit: 1024M
extensions:
enabled:
- Codeception\Extension\RunFailed
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=kartice_test'
user: '*******'
password: '*******'
dump: tests_codecept/_data/dump.sql
populate: true
cleanup: true
reconnect: true
and here is functional.suite.yml file:
class_name: FunctionalTester
modules:
enabled:
# add framework module here
- \Helper\Functional
- Asserts
- Laravel5:
environment_file: .env.testing
- Db
here is my test method:
public function provera_dodavanja_novog_klijenta(FunctionalTester $I)
{
$this->authenticate($I);
$I->amOnPage('/kancelarija/komitenti/create');
$I->see('Kreiranje novog komitenta');
$I->fillField('input[name=komitent_code]', 'kom1');
$I->fillField('input[name=komitent_name]', 'Komitent 1');
$I->click('btnSave');
$I->seeInDatabase('komitenti', ['code' => 'kom1', 'name' => 'Komitent 1']);
$I->see('Komitent Komitent 1 je uspešno kreiran.');
}
Running functional test fails with message:
Step I see in database "komitenti",{"code":"kom1","name":"Komitent 1"}
Fail No matching records found for criteria {"code":"kom1","name":"Komitent 1"} in table komitenti
Failed asserting that 0 is greater than 0.
What I am doing wrong?
I have seen question Codeception seeInDatabase() doesn't work for me but this didn't helpe me.
You should probably useseeRecord method instead of seeInDatabase. I don't know why but for me first one was working and second one - not.
I use gulp tdd and when testing forms come across this error.
Please check:
You added this to Requests
<YourFormRequest>use App\Http\Requests\<YourFormRequest>;
Ensure the Model for your table is mass assignable
protected $fillable = ['tableField1', 'tableField2']