<commit_before><?php

namespace Finalist\TweeterCoreBundle\Tests\Service;

use Symfony\Bundle\FrameworkBundle\Tests\TestCase;

use Finalist\TweeterCoreBundle\Service\TweetService;

class TweetServiceTest extends TestCase {

    use \Finalist\TweeterCoreBundle\Tests\MockCreator;
    
    /** @var Finalist\TweeterCoreBundle\Service\TweetService */
    private $subject;
    
    private $tweetRepositoryMock;
    private $tweeterRepositoryMock;
    
    public function setUp() {
        $this->tweetRepositoryMock = $this->createTweetRepositoryMock();
        $this->tweeterRepositoryMock = $this->createTweeterRepositoryMock();
        
        $this->subject = new TweetService($this->tweetRepositoryMock, $this->tweeterRepositoryMock);
    }
    
    public function testGetRecentTweets() {
        $tweetMocks = [
            $this->createTweetMock(),
            $this->createTweetMock()
        ];
        
        $this->tweetRepositoryMock->expects($this->once())
                ->method('findMostRecent')
                ->with($this->isType('int'))
                ->will($this->returnValue($tweetMocks));
        
        $this->assertSame($tweetMocks, $this->subject->getRecentTweets());
    }
    
    /** @expectedException \Finalist\TweeterCoreBundle\Exception\DomainException */
    public function testGetRecentTweetsForTweeterNotFoundThrowsException() {
        $this->tweeterRepositoryMock->expects($this->once())
                ->method('findByName')
                ->with($this->identicalTo('timmy tweeter'))
                ->will($this->returnValue(null));
        
        $this->subject->getRecentTweetsForTweeter('<NAME>');
    }

    public function testGetRecentTweetsForTweeter() {
        $tweeterMock = $this->createTweeterMock();
        
        $tweetMocks = [
            $this->createTweetMock(),
            $this->createTweetMock()
        ];

        $this->tweeterRepositoryMock->expects($this->once())
                ->method('findByName')
                ->with($this->identicalTo('<NAME>'))
                ->will($this->returnValue($tweeterMock));
        
        $this->tweetRepositoryMock->expects($this->once())
                ->method('findByTweeter')
                ->with($this->identicalTo($tweeterMock))
                ->will($this->returnValue($tweetMocks));
        
        $this->assertSame($tweetMocks, $this->subject->getRecentTweetsForTweeter('<NAME>'));
    }
    
    public function testCreateTweetForNewTweeter() {
        $this->tweeterRepositoryMock->expects($this->once())
                ->method('findByName')
                ->with($this->identicalTo('timmy tweeter'))
                ->will($this->returnValue(null));
        
        $this->tweetRepositoryMock->expects($this->once())
                ->method('add')
                ->with($this->isiNstanceOf('Finalist\TweeterCoreBundle\Entity\Tweet'));

        $this->tweeterRepositoryMock->expects($this->once())
                ->method('add')
                ->with($this->isInstanceOf('\Finalist\TweeterCoreBundle\Entity\Tweeter'));
        
        $tweet = $this->subject->createTweet('<NAME>', 'my first tweet');
        $this->assertInstanceOf('Finalist\TweeterCoreBundle\Entity\Tweet', $tweet);
        $this->assertSame('<NAME>', $tweet->getTweeter()->getName());
        $this->assertSame('my first tweet', $tweet->getText());
        $this->assertGreaterThan(time() - 2, $tweet->getTimestamp());
        $this->assertLessThanOrEqual(time(), $tweet->getTimestamp());
    }
}<commit_msg>added comment to assertion<commit_after><?php

namespace Finalist\TweeterCoreBundle\Tests\Service;

use Symfony\Bundle\FrameworkBundle\Tests\TestCase;

use Finalist\TweeterCoreBundle\Service\TweetService;

class TweetServiceTest extends TestCase {

    use \Finalist\TweeterCoreBundle\Tests\MockCreator;
    
    /** @var Finalist\TweeterCoreBundle\Service\TweetService */
    private $subject;
    
    private $tweetRepositoryMock;
    private $tweeterRepositoryMock;
    
    public function setUp() {
        $this->tweetRepositoryMock = $this->createTweetRepositoryMock();
        $this->tweeterRepositoryMock = $this->createTweeterRepositoryMock();
        
        $this->subject = new TweetService($this->tweetRepositoryMock, $this->tweeterRepositoryMock);
    }
    
    public function testGetRecentTweets() {
        $tweetMocks = [
            $this->createTweetMock(),
            $this->createTweetMock()
        ];
        
        $this->tweetRepositoryMock->expects($this->once())
                ->method('findMostRecent')
                ->with($this->isType('int'))
                ->will($this->returnValue($tweetMocks));
        
        $this->assertSame($tweetMocks, $this->subject->getRecentTweets());
    }
    
    /** @expectedException \Finalist\TweeterCoreBundle\Exception\DomainException */
    public function testGetRecentTweetsForTweeterNotFoundThrowsException() {
        $this->tweeterRepositoryMock->expects($this->once())
                ->method('findByName')
                ->with($this->identicalTo('<NAME>'))
                ->will($this->returnValue(null));
        
        $this->subject->getRecentTweetsForTweeter('<NAME>');
    }

    public function testGetRecentTweetsForTweeter() {
        $tweeterMock = $this->createTweeterMock();
        
        $tweetMocks = [
            $this->createTweetMock(),
            $this->createTweetMock()
        ];

        $this->tweeterRepositoryMock->expects($this->once())
                ->method('findByName')
                ->with($this->identicalTo('<NAME>'))
                ->will($this->returnValue($tweeterMock));
        
        $this->tweetRepositoryMock->expects($this->once())
                ->method('findByTweeter')
                ->with($this->identicalTo($tweeterMock))
                ->will($this->returnValue($tweetMocks));
        
        $this->assertSame($tweetMocks, $this->subject->getRecentTweetsForTweeter('<NAME>'));
    }
    
    public function testCreateTweetForNewTweeter() {
        $this->tweeterRepositoryMock->expects($this->once())
                ->method('findByName')
                ->with($this->identicalTo('<NAME>'))
                ->will($this->returnValue(null));
        
        $this->tweetRepositoryMock->expects($this->once())
                ->method('add')
                ->with($this->isiNstanceOf('Finalist\TweeterCoreBundle\Entity\Tweet'));

        $this->tweeterRepositoryMock->expects($this->once())
                ->method('add')
                ->with($this->isInstanceOf('\Finalist\TweeterCoreBundle\Entity\Tweeter'));
        
        $tweet = $this->subject->createTweet('<NAME>', 'my first tweet');
        $this->assertInstanceOf('Finalist\TweeterCoreBundle\Entity\Tweet', $tweet);
        $this->assertSame('tim<NAME>er', $tweet->getTweeter()->getName());
        $this->assertSame('my first tweet', $tweet->getText());
        $this->assertGreaterThan(time() - 2, $tweet->getTimestamp(), 'tweet is no more than 2 seconds old');
        $this->assertLessThanOrEqual(time(), $tweet->getTimestamp(), 'tweet timestamp cannot be in the future');
    }
}
{'fraction_non_alphanumeric': 0.15505177721802407, 'fraction_numerical': 0.00041981528127623844, 'mean_word_length': 2.61873417721519, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 183, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '532507', 'n_tokens_mistral': 2097, 'n_tokens_neox': 2040, 'n_words': 227}