2709 search results for Doctrine

Hey Shaun T. That config only works when working on PHPUnit, you need to specify your test database in your test doctrine.yaml file. ``` // config/packages/test/doctrine.yaml doctrine: dbal: url: '%env(resolve:DATABASE_URL)%_test' ``` Cheers! ...
MolloKhan
MolloKhan
Read Full Comment
In my app I am using Doctrine Blameable Extension, so it sets the current user when creating a post on the createdBy field. How can I handle this when running my tests? ...
93 lines | src/Controller/QuestionController.php
// ... lines 1 - 6
use Doctrine\ORM\EntityManagerInterface;
// ... lines 8 - 12
class QuestionController extends AbstractController
{
// ... lines 15 - 35
public function new(EntityManagerInterface $entityManager)
{
// ... lines 38 - 57
$entityManager->persist($question);
$entityManager->flush();
return new Response(sprintf(
'Well hallo! The shiny new question is id #%d, slug: %s',
$question->getId(),
$question->getSlug()
));
}
// ... lines 67 - 91
}
See Code Block in Script
64 lines | src/Controller/QuestionController.php
// ... lines 1 - 10
class QuestionController extends AbstractController
{
// ... lines 13 - 25
public function homepage()
{
// ... line 28
}
// ... line 30
/**
* @Route("/questions/new")
*/
public function new()
{
return new Response('Time for some Doctrine magic!');
}
/**
* @Route("/questions/{slug}", name="app_question_show")
*/
public function show($slug, MarkdownHelper $markdownHelper)
{
// ... lines 44 - 61
}
}
See Code Block in Script
// ... lines 1 - 5
use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
// ... lines 7 - 11
class CheeseListingIsPublishedExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
{
// ... lines 14 - 25
public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, string $operationName = null, array $context = [])
{
// ... line 28
}
// ... lines 30 - 44
}
See Code Block in Script
// ... lines 1 - 6
use App\Service\UploaderHelper;
use Doctrine\ORM\EntityManagerInterface;
// ... line 9
use Symfony\Component\HttpFoundation\File\UploadedFile;
// ... lines 11 - 13
class ArticleReferenceAdminController extends BaseController
{
// ... lines 16 - 19
public function uploadArticleReference(Article $article, Request $request, UploaderHelper $uploaderHelper, EntityManagerInterface $entityManager)
{
/** @var UploadedFile $uploadedFile */
$uploadedFile = $request->files->get('reference');
// ... lines 24 - 37
}
}
See Code Block in Script
imports:
- { resource: config.yml }
#framework:
# validation:
# cache: validator.mapping.cache.apc
# serializer:
# cache: serializer.mapping.cache.apc
#doctrine:
# orm:
# metadata_cache_driver: apc
# result_cache_driver: apc
# query_cache_driver: apc
monolog:
handlers:
main:
type: fingers_crossed
action_level: error
handler: nested
nested:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
console:
type: console
See Code Block in Script
39 lines | app/config/services.yml
// ... lines 1 - 8
services:
// ... lines 10 - 13
AppBundle\Service\MarkdownTransformer:
arguments: ['@markdown.parser', '@doctrine_cache.providers.my_markdown_cache']
AppBundle\Twig\MarkdownExtension:
#arguments: ['@app.markdown_transformer']
AppBundle\Security\LoginFormAuthenticator: ~
AppBundle\Doctrine\HashPasswordListener:
tags:
- { name: doctrine.event_subscriber }
AppBundle\Form\TypeExtension\HelpFormExtension:
tags:
- { name: form.type_extension, extended_type: Symfony\Component\Form\Extension\Core\Type\FormType }
// ... lines 29 - 39
See Code Block in Script
41 lines | src/AppBundle/Form/UserEditForm.php
// ... lines 1 - 6
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
// ... lines 8 - 14
class UserEditForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ... lines 20 - 24
->add('studiedGenuses', EntityType::class, [
'class' => Genus::class,
'multiple' => true,
'expanded' => true,
'choice_label' => 'name',
])
;
}
// ... lines 33 - 39
}
See Code Block in Script
60 lines | src/AppBundle/Form/GenusFormType.php
// ... lines 1 - 7
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
// ... lines 9 - 16
class GenusFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ... lines 22 - 44
->add('genusScientists', EntityType::class, [
'class' => User::class,
'multiple' => true,
'expanded' => true,
])
;
}
// ... lines 52 - 58
}
See Code Block in Script
60 lines | src/AppBundle/Form/GenusFormType.php
// ... lines 1 - 7
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
// ... lines 9 - 16
class GenusFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ... line 22
->add('subFamily', EntityType::class, [
'placeholder' => 'Choose a Sub Family',
'class' => SubFamily::class,
'query_builder' => function(SubFamilyRepository $repo) {
return $repo->createAlphabeticalQueryBuilder();
}
])
// ... lines 30 - 49
;
}
// ... lines 52 - 58
}
See Code Block in Script
50 lines | src/AppBundle/Form/GenusFormType.php
// ... lines 1 - 6
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
// ... lines 8 - 13
class GenusFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ... line 19
->add('subFamily', EntityType::class, [
'placeholder' => 'Choose a Sub Family',
'class' => SubFamily::class,
'query_builder' => function(SubFamilyRepository $repo) {
return $repo->createAlphabeticalQueryBuilder();
}
])
// ... lines 27 - 39
;
}
// ... lines 42 - 48
}
See Code Block in Script
56 lines | src/Controller/ArticleAdminController.php
// ... lines 1 - 5
use Doctrine\ORM\EntityManagerInterface;
// ... lines 7 - 10
class ArticleAdminController extends AbstractController
{
// ... lines 13 - 15
public function new(EntityManagerInterface $em)
{
// ... lines 18 - 45
$em->persist($article);
$em->flush();
return new Response(sprintf(
'Hiya! New Article id: #%d slug: %s',
$article->getId(),
$article->getSlug()
));
}
}
See Code Block in Script
56 lines | src/Controller/ArticleAdminController.php
// ... lines 1 - 5
use Doctrine\ORM\EntityManagerInterface;
// ... lines 7 - 10
class ArticleAdminController extends AbstractController
{
// ... lines 13 - 15
public function new(EntityManagerInterface $em)
{
// ... lines 18 - 40
// publish most articles
if (rand(1, 10) > 2) {
$article->setPublishedAt(new \DateTime(sprintf('-%d days', rand(1, 100))));
}
$em->persist($article);
$em->flush();
// ... lines 48 - 53
}
}
See Code Block in Script
// ... lines 1 - 5
use ApiPlatform\Doctrine\Orm\Extension\QueryItemExtensionInterface;
// ... lines 7 - 11
class DragonTreasureIsPublishedExtension implements QueryCollectionExtensionInterface, QueryItemExtensionInterface
{
// ... lines 14 - 24
public function applyToItem(QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, array $identifiers, Operation $operation = null, array $context = []): void
{
// TODO: Implement applyToItem() method.
}
}
See Code Block in Script
131 lines | src/Entity/User.php
// ... lines 1 - 10
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
// ... lines 12 - 18
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
#[UniqueEntity(fields: ['username'], message: 'It looks like another dragon took your username. ROAR!')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
// ... lines 23 - 129
}
See Code Block in Script
57 lines | src/Controller/VinylController.php
// ... lines 1 - 5
use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
// ... lines 8 - 12
class VinylController extends AbstractController
{
// ... lines 15 - 38
public function browse(VinylMixRepository $mixRepository, string $slug = null): Response
{
// ... lines 41 - 43
$adapter = new QueryAdapter($queryBuilder);
$pagerfanta = Pagerfanta::createForCurrentPageWithMaxPerPage(
$adapter,
1,
9
);
// ... lines 50 - 54
}
}
See Code Block in Script
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
{# this template is used to display Doctrine entity primary keys #}
<span class="fa fa-key"></span> {{ field.formattedValue }}
See Code Block in Script
87 lines | src/Controller/QuestionController.php
// ... lines 1 - 9
use Pagerfanta\Doctrine\ORM\QueryAdapter;
use Pagerfanta\Pagerfanta;
// ... lines 12 - 17
class QuestionController extends AbstractController
{
// ... lines 20 - 32
public function homepage(QuestionRepository $repository)
{
$queryBuilder = $repository->createAskedOrderedByNewestQueryBuilder();
$pagerfanta = new Pagerfanta(new QueryAdapter($queryBuilder));
$pagerfanta->setMaxPerPage(5);
// ... lines 39 - 42
}
// ... lines 44 - 85
}
See Code Block in Script
... with. Here is the link to those chapters - you can read the content now, the videos will be there over the next 2 days: * https://knpuniversity.com/screencast/symfony-doctrine/fixtures * https://knpuniversity.com ...
weaverryan
weaverryan
Read Full Comment