Skip to content

Commit

Permalink
Added more great Symfony 4.1 features
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Jun 21, 2018
1 parent beb3aa8 commit 87b0e03
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 7 deletions.
4 changes: 3 additions & 1 deletion config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ framework:
# When 'ide' is set to null the file is opened in your web browser.
# See https://symfony.com/doc/current/reference/configuration/framework.html#ide
ide: ~
validation: { enable_annotations: true }
validation:
email_validation_mode: 'html5'
enable_annotations: true
4 changes: 1 addition & 3 deletions config/packages/prod/monolog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ monolog:
type: fingers_crossed
action_level: error
handler: nested
excluded_404s:
# regex: exclude all 404 errors from the logs
- ^/
excluded_http_codes: [404]
nested:
type: stream
path: '%kernel.logs_dir%/%kernel.environment%.log'
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Admin/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function new(Request $request): Response
/**
* Finds and displays a Post entity.
*
* @Route("/{id}", requirements={"id": "\d+"}, methods={"GET"}, name="admin_post_show")
* @Route("/{id<\d+>}", methods={"GET"}, name="admin_post_show")
*/
public function show(Post $post): Response
{
Expand All @@ -130,7 +130,7 @@ public function show(Post $post): Response
/**
* Displays a form to edit an existing Post entity.
*
* @Route("/{id}/edit", requirements={"id": "\d+"}, methods={"GET", "POST"}, name="admin_post_edit")
* @Route("/{id<\d+>}/edit",methods={"GET", "POST"}, name="admin_post_edit")
* @IsGranted("edit", subject="post", message="Posts can only be edited by their authors.")
*/
public function edit(Request $request, Post $post): Response
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BlogController extends AbstractController
/**
* @Route("/", defaults={"page": "1", "_format"="html"}, methods={"GET"}, name="blog_index")
* @Route("/rss.xml", defaults={"page": "1", "_format"="xml"}, methods={"GET"}, name="blog_rss")
* @Route("/page/{page}", defaults={"_format"="html"}, requirements={"page": "[1-9]\d*"}, methods={"GET"}, name="blog_index_paginated")
* @Route("/page/{page<[1-9]\d*>}", defaults={"_format"="html"}, methods={"GET"}, name="blog_index_paginated")
* @Cache(smaxage="10")
*
* NOTE: For standard formats, Symfony will also automatically choose the best
Expand Down
1 change: 1 addition & 0 deletions src/Entity/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Post
*
* @ORM\Column(type="string")
* @Assert\NotBlank(message="post.blank_summary")
* @Assert\Length(max=255)
*/
private $summary;

Expand Down
5 changes: 5 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
Expand Down Expand Up @@ -42,20 +43,24 @@ class User implements UserInterface, \Serializable
* @var string
*
* @ORM\Column(type="string")
* @Assert\NotBlank()
*/
private $fullName;

/**
* @var string
*
* @ORM\Column(type="string", unique=true)
* @Assert\NotBlank()
* @Assert\Length(min=2, max=50)
*/
private $username;

/**
* @var string
*
* @ORM\Column(type="string", unique=true)
* @Assert\Email()
*/
private $email;

Expand Down
13 changes: 13 additions & 0 deletions tests/Controller/BlogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,17 @@ public function testNewComment()

$this->assertSame('Hi, Symfony!', $newComment);
}

public function testAjaxSearch()
{
$client = static::createClient();
$client->xmlHttpRequest('GET', '/en/blog/search', ['q' => 'lorem']);

$results = json_decode($client->getResponse()->getContent(), true);

$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
$this->assertCount(1, $results);
$this->assertSame('Lorem ipsum dolor sit amet consectetur adipiscing elit', $results[0]['title']);
$this->assertSame('Jane Doe', $results[0]['author']);
}
}

0 comments on commit 87b0e03

Please sign in to comment.