Skip to content

Commit

Permalink
Merge pull request #34 from Runroom/hotfix/new-packages-versions
Browse files Browse the repository at this point in the history
Update to Sonata RC release
  • Loading branch information
jordisala1991 committed Aug 30, 2021
2 parents 2229e25 + 9a0c752 commit 28f9504
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 100 deletions.
14 changes: 7 additions & 7 deletions composer.json
Expand Up @@ -25,12 +25,12 @@
"gedmo/doctrine-extensions": "^3.0",
"hubspot/hubspot-php": "^3.1",
"knplabs/doctrine-behaviors": "^2.0.6",
"runroom-packages/form-handler-bundle": "^0.12",
"runroom-packages/render-event-bundle": "^0.12",
"runroom-packages/sortable-behavior-bundle": "^0.12",
"sonata-project/admin-bundle": "^3.103 || ^4.0@dev",
"runroom-packages/form-handler-bundle": "^0.13",
"runroom-packages/render-event-bundle": "^0.13",
"runroom-packages/sortable-behavior-bundle": "^0.13",
"sonata-project/admin-bundle": "^3.103 || ^4.0@rc",
"sonata-project/doctrine-extensions": "^1.13",
"sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@dev",
"sonata-project/doctrine-orm-admin-bundle": "^3.34 || ^4.0@rc",
"sonata-project/media-bundle": "^3.32 || ^4.0@dev",
"symfony/config": "^4.4 || ^5.3",
"symfony/dependency-injection": "^4.4 || ^5.3",
Expand Down Expand Up @@ -59,8 +59,8 @@
"phpstan/phpstan-symfony": "^0.12",
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.16",
"psalm/plugin-symfony": "^2.0",
"runroom-packages/testing": "^0.12",
"psalm/plugin-symfony": "^3.0",
"runroom-packages/testing": "^0.13",
"symfony/phpunit-bridge": "^5.3",
"vimeo/psalm": "^4.0",
"weirdan/doctrine-psalm-plugin": "^1.0",
Expand Down
16 changes: 4 additions & 12 deletions src/BasicEntities/Admin/BookAdmin.php
Expand Up @@ -48,15 +48,11 @@ protected function configureListFields(ListMapper $list): void
'sort_parent_association_mappings' => [['fieldName' => 'translations']],
])
->add('category')
->add('publish', null, [
'editable' => true,
])
->add('publish', null, ['editable' => true])
->add('_action', 'actions', [
'actions' => [
'delete' => [],
'move' => [
'template' => '@RunroomSortableBehavior/sort.html.twig',
],
'move' => ['template' => '@RunroomSortableBehavior/sort.html.twig'],
],
]);
}
Expand All @@ -68,17 +64,13 @@ protected function configureFormFields(FormMapper $form): void
'label' => false,
'fields' => [
'title' => [],
'slug' => [
'display' => false,
],
'slug' => ['display' => false],
'description' => [
'field_type' => CKEditorType::class,
'required' => false,
],
],
'constraints' => [
new Assert\Valid(),
],
'constraints' => [new Assert\Valid()],
])
->add('category')
->add('picture', MediaType::class, [
Expand Down
8 changes: 2 additions & 6 deletions src/BasicEntities/Admin/CategoryAdmin.php
Expand Up @@ -41,9 +41,7 @@ protected function configureListFields(ListMapper $list): void
])
->add('books')
->add('_action', 'actions', [
'actions' => [
'delete' => [],
],
'actions' => ['delete' => []],
]);
}

Expand All @@ -55,9 +53,7 @@ protected function configureFormFields(FormMapper $form): void
'fields' => [
'name' => [],
],
'constraints' => [
new Assert\Valid(),
],
'constraints' => [new Assert\Valid()],
])
->add('books');
}
Expand Down
14 changes: 2 additions & 12 deletions src/BasicEntities/Service/BookService.php
Expand Up @@ -28,21 +28,11 @@ public function __construct(BookRepository $repository)

public function getBooksViewModel(): BooksViewModel
{
$books = $this->repository->findBy(['publish' => true], ['position' => 'ASC']);

$model = new BooksViewModel();
$model->setBooks($books);

return $model;
return new BooksViewModel($this->repository->findBy(['publish' => true], ['position' => 'ASC']));
}

public function getBookViewModel(string $slug): BookViewModel
{
$book = $this->repository->findBySlug($slug);

$model = new BookViewModel();
$model->setBook($book);

return $model;
return new BookViewModel($this->repository->findBySlug($slug));
}
}
6 changes: 3 additions & 3 deletions src/BasicEntities/ViewModel/BookViewModel.php
Expand Up @@ -17,14 +17,14 @@

class BookViewModel
{
private ?Book $book = null;
private Book $book;

public function setBook(Book $book): void
public function __construct(Book $book)
{
$this->book = $book;
}

public function getBook(): ?Book
public function getBook(): Book
{
return $this->book;
}
Expand Down
10 changes: 5 additions & 5 deletions src/BasicEntities/ViewModel/BooksViewModel.php
Expand Up @@ -17,17 +17,17 @@

class BooksViewModel
{
/** @var Book[]|null */
private ?array $books = null;
/** @var Book[] */
private array $books;

/** @param Book[] $books */
public function setBooks(array $books): void
public function __construct(array $books)
{
$this->books = $books;
}

/** @return Book[]|null */
public function getBooks(): ?array
/** @return Book[] */
public function getBooks(): array
{
return $this->books;
}
Expand Down
24 changes: 6 additions & 18 deletions src/Forms/Admin/ContactAdmin.php
Expand Up @@ -41,9 +41,7 @@ protected function configureRoutes(RouteCollectionInterface $collection): void
protected function configureShowFields(ShowMapper $show): void
{
$show
->add('date', null, [
'format' => 'd/m/Y h:i',
])
->add('date', null, ['format' => 'd/m/Y h:i'])
->add('name')
->add('email')
->add('phone')
Expand Down Expand Up @@ -72,32 +70,24 @@ protected function configureShowFields(ShowMapper $show): void
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$filter
->add('date', DateRangeFilter::class, [
'field_type' => DateTimeRangePickerType::class,
])
->add('date', DateRangeFilter::class, ['field_type' => DateTimeRangePickerType::class])
->add('name')
->add('email')
->add('subject', null, [
'field_type' => ChoiceType::class,
'field_options' => [
'choices' => Contact::$subjectChoices,
],
'field_options' => ['choices' => Contact::$subjectChoices],
])
->add('newsletter')
->add('status', null, [
'field_type' => ChoiceType::class,
'field_options' => [
'choices' => Contact::$statusChoices,
],
'field_options' => ['choices' => Contact::$statusChoices],
]);
}

protected function configureListFields(ListMapper $list): void
{
$list
->add('date', null, [
'format' => 'd/m/Y h:i',
])
->add('date', null, ['format' => 'd/m/Y h:i'])
->addIdentifier('name')
->add('email', 'email')
->add('subject', 'choice', [
Expand All @@ -112,9 +102,7 @@ protected function configureListFields(ListMapper $list): void
'template' => '@Samples/Forms/sonata/contact-status.html.twig',
])
->add('_action', 'actions', [
'actions' => [
'delete' => [],
],
'actions' => ['delete' => []],
]);
}
}
18 changes: 4 additions & 14 deletions src/Forms/Controller/ContactController.php
Expand Up @@ -45,16 +45,11 @@ public function contact(): Response

if ($model->formIsValid()) {
return new RedirectResponse(
$this->router->generate('runroom_samples.forms.contact', [
'_fragment' => 'form',
])
$this->router->generate('runroom_samples.forms.contact', ['_fragment' => 'form'])
);
}

return $this->renderer->renderResponse(
'@RunroomSamples/Forms/contact.html.twig',
$model
);
return $this->renderer->renderResponse('@RunroomSamples/Forms/contact.html.twig', $model);
}

public function contactAjax(): Response
Expand Down Expand Up @@ -82,15 +77,10 @@ public function contactHubspot(): Response

if ($model->formIsValid()) {
return new RedirectResponse(
$this->router->generate('runroom_samples.forms.hubspot', [
'_fragment' => 'form',
])
$this->router->generate('runroom_samples.forms.hubspot', ['_fragment' => 'form'])
);
}

return $this->renderer->renderResponse(
'@RunroomSamples/Forms/contact-hubspot.html.twig',
$model
);
return $this->renderer->renderResponse('@RunroomSamples/Forms/contact-hubspot.html.twig', $model);
}
}
4 changes: 1 addition & 3 deletions src/Forms/Form/ContactEventHandler.php
Expand Up @@ -53,8 +53,6 @@ public function onContactSuccess(GenericEvent $event): void

public static function getSubscribedEvents(): array
{
return [
'form.contact_form.event.success' => 'onContactSuccess',
];
return ['form.contact_form.event.success' => 'onContactSuccess'];
}
}
4 changes: 1 addition & 3 deletions src/Forms/Form/ContactHubspotEventHandler.php
Expand Up @@ -76,9 +76,7 @@ public function onContactSuccess(GenericEvent $event): void

public static function getSubscribedEvents(): array
{
return [
'form.contact_hubspot_form.event.success' => 'onContactSuccess',
];
return ['form.contact_hubspot_form.event.success' => 'onContactSuccess'];
}

/** @param array{ fields: array{name: string, value: mixed}[], legalConsentOptions: array{consent: array{consentToProcess: mixed, text: string} } } $data */
Expand Down
12 changes: 3 additions & 9 deletions src/Forms/Form/Type/ContactFormType.php
Expand Up @@ -89,17 +89,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
])
->add('comment', TextareaType::class, [
'constraints' => [
new Assert\NotBlank(['message' => 'not_blank']),
],
])
->add('newsletter', CheckboxType::class, [
'required' => false,
'constraints' => [new Assert\NotBlank(['message' => 'not_blank'])],
])
->add('newsletter', CheckboxType::class, ['required' => false])
->add('privacyPolicy', CheckboxType::class, [
'constraints' => [
new Assert\IsTrue(['message' => 'privacy_policy']),
],
'constraints' => [new Assert\IsTrue(['message' => 'privacy_policy'])],
])
->add('send', SubmitType::class);
}
Expand Down
8 changes: 2 additions & 6 deletions src/Forms/Form/Type/ContactHubspotFormType.php
Expand Up @@ -50,14 +50,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
],
])
->add('comment', TextareaType::class, [
'constraints' => [
new Assert\NotBlank(['message' => 'not_blank']),
],
'constraints' => [new Assert\NotBlank(['message' => 'not_blank'])],
])
->add('privacyPolicy', CheckboxType::class, [
'constraints' => [
new Assert\IsTrue(['message' => 'privacy_policy']),
],
'constraints' => [new Assert\IsTrue(['message' => 'privacy_policy'])],
])
->add('send', SubmitType::class);
}
Expand Down
5 changes: 3 additions & 2 deletions tests/BasicEntities/Unit/BookControllerTest.php
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Runroom\SamplesBundle\BasicEntities\Controller\BookController;
use Runroom\SamplesBundle\BasicEntities\Entity\Book;
use Runroom\SamplesBundle\BasicEntities\Service\BookService;
use Runroom\SamplesBundle\BasicEntities\ViewModel\BooksViewModel;
use Runroom\SamplesBundle\BasicEntities\ViewModel\BookViewModel;
Expand Down Expand Up @@ -49,7 +50,7 @@ protected function setUp(): void
/** @test */
public function itRenderBooks(): void
{
$model = new BooksViewModel();
$model = new BooksViewModel([]);

$this->service->method('getBooksViewModel')->willReturn($model);

Expand All @@ -61,7 +62,7 @@ public function itRenderBooks(): void
/** @test */
public function itRenderBook(): void
{
$model = new BookViewModel();
$model = new BookViewModel(new Book());

$this->service->method('getBookViewModel')->with('book')->willReturn($model);

Expand Down

0 comments on commit 28f9504

Please sign in to comment.