Skip to content

Commit

Permalink
Fixes #13: Cookie value is readen correctly
Browse files Browse the repository at this point in the history
Added test to avoid future regression: the number of pending tweets is tested
  • Loading branch information
alexislefebvre committed Dec 12, 2015
1 parent 98607ed commit 2ad96f8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
12 changes: 7 additions & 5 deletions Controller/DefaultController.php
Expand Up @@ -12,19 +12,20 @@ class DefaultController extends Controller
private $tweetRepository;

/**
* @param Request $request
* @param string|null $firstTweetId
*
* @return \Symfony\Component\HttpFoundation\Response $response $response
*/
public function indexAction($firstTweetId = null)
public function indexAction(Request $request, $firstTweetId = null)
{
$this->tweetRepository = $this->getDoctrine()
->getRepository('AsyncTweetsBundle:Tweet');

$tweets = $this->tweetRepository
->getWithUsersAndMedias($firstTweetId);

$variables = $this->getVariables($tweets, $firstTweetId);
$variables = $this->getVariables($request, $tweets, $firstTweetId);

$response = $this->render(
'AsyncTweetsBundle:Default:index.html.twig',
Expand All @@ -42,20 +43,21 @@ public function indexAction($firstTweetId = null)
}

/**
* @param Request $request
* @param Tweets[] $tweets
* @param integer $firstTweetId
*
* @return array $vars
*/
private function getVariables($tweets, $firstTweetId)
private function getVariables(Request $request, $tweets, $firstTweetId)
{
$vars = array(
'first' => $firstTweetId,
'previous' => null,
'next' => null,
'number' => 0,
'cookieId' => $this->getLastTweetIdFromCookie($request),
# No cookie by default
'cookieId' => null,
'cookie' => null,
);

Expand Down Expand Up @@ -152,7 +154,7 @@ public function deleteLessThanAction(Request $request)
{
$lastTweetId = $this->getLastTweetIdFromCookie($request);

if ($lastTweetId) {
if (! is_null($lastTweetId)) {
$count = $this->getDoctrine()
->getRepository('AsyncTweetsBundle:Tweet')
->deleteAndHideTweetsLessThanId($lastTweetId);
Expand Down
33 changes: 29 additions & 4 deletions Tests/Controller/DefaultControllerTest.php
Expand Up @@ -56,7 +56,8 @@ public function testTweets($path = null)
# <title>
$this->assertContains(
'Home timeline - since 49664 - AsyncTweets',
$crawler->filter('title')->text()
$crawler->filter('title')->text(),
$crawler->filter('html')->text()
);

# 2 navigation blocks
Expand All @@ -82,8 +83,6 @@ public function testTweets($path = null)
)->count()
);

# TODO: Hashtags

# Images
$this->assertSame(
1,
Expand Down Expand Up @@ -241,7 +240,33 @@ public function testTweetsPages()
'main.container > div.tweets > div.media > blockquote.media-body'
)->count()
);


// Number of pending tweets
$this->assertContains(
'3 pending tweets',
$crawler->filter('main.container > div.navigation')
->first()->filter('div.alert-info')->text()
);

// Go to first page
$path = '/';

$crawler = $this->client->request('GET', $path);

// Tweet
$this->assertSame(
5,
$crawler->filter(
'main.container > div.tweets > div.media > blockquote.media-body'
)->count()
);

// Number of pending tweets
$this->assertContains(
'3 pending tweets',
$crawler->filter('main.container > div.navigation')
->first()->filter('div.alert-info')->text()
);
}

public function testCookie()
Expand Down

1 comment on commit 2ad96f8

@alexislefebvre
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage of ! is_null($lastTweetId) was suggested by Scrutinizer CI.

Please sign in to comment.