<commit_before><?php

namespace BotMan\BotMan\tests;

use Mockery as m;
use BotMan\BotMan\BotMan;
use PHPUnit_Framework_TestCase;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Cache\ArrayCache;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Drivers\Tests\FakeDriver;
use BotMan\BotMan\Drivers\Tests\ProxyDriver;
use BotMan\BotMan\Messages\Attachments\Audio;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Attachments\Video;
use BotMan\BotMan\Messages\Attachments\Location;
use BotMan\BotMan\Tests\Fixtures\TestConversation;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
use BotMan\BotMan\Tests\Fixtures\TestDataConversation;

class BotManConversationTest extends PHPUnit_Framework_TestCase
{
    /** @var BotMan */
    private $botman;
    /** @var FakeDriver */
    private $fakeDriver;
    /** @var m\MockInterface */
    private $cache;

    public static function setUpBeforeClass()
    {
        DriverManager::loadDriver(ProxyDriver::class);
    }

    public static function tearDownAfterClass()
    {
        DriverManager::unloadDriver(ProxyDriver::class);
    }

    protected function setUp()
    {
        $this->fakeDriver = new FakeDriver();
        $this->cache = m::mock(ArrayCache::class)->makePartial();
        ProxyDriver::setInstance($this->fakeDriver);
        $this->botman = BotManFactory::create([], $this->cache);
    }

    protected function tearDown()
    {
        ProxyDriver::setInstance(FakeDriver::createInactive());
        m::close();
    }

    /** @test */
    public function it_caches_conversation_for_30_minutes()
    {
        $message = new IncomingMessage('Hello', 'helloman', '#helloworld');

        $this->botman->hears('Hello', function (BotMan $bot) {
            $bot->startConversation(new TestDataConversation());
        });

        $this->cache->shouldReceive('put')
            ->with($message->getConversationIdentifier(), m::any(), 30)
            ->once();

        $this->replyWithFakeMessage('Hello');
    }

    /** @test */
    public function it_caches_conversation_for_custom_amount_of_minutes()
    {
        $this->fakeDriver = new FakeDriver();
        $this->cache = m::mock(ArrayCache::class)->makePartial();
        ProxyDriver::setInstance($this->fakeDriver);
        $this->botman = BotManFactory::create([
            'config' => [
                'conversation_cache_time' => '50'
            ],
        ], $this->cache);

        $message = new IncomingMessage('Hello', 'helloman', '#helloworld');

        $this->botman->hears('Hello', function (BotMan $bot) {
            $bot->startConversation(new TestDataConversation());
        });

        $this->cache->shouldReceive('put')
            ->with($message->getConversationIdentifier(), m::any(), 50)
            ->once();

        $this->replyWithFakeMessage('Hello');
    }

    /** @test */
    public function it_uses_conversation_defined_cache_time()
    {
        $message = new IncomingMessage('Hello', 'helloman', '#helloworld');

        $this->botman->hears('Hello', function (BotMan $bot) {<commit_msg>Apply fixes from StyleCI (#608)<commit_after><?php

namespace BotMan\BotMan\tests;

use Mockery as m;
use BotMan\BotMan\BotMan;
use PHPUnit_Framework_TestCase;
use BotMan\BotMan\BotManFactory;
use BotMan\BotMan\Cache\ArrayCache;
use BotMan\BotMan\Drivers\DriverManager;
use BotMan\BotMan\Drivers\Tests\FakeDriver;
use BotMan\BotMan\Drivers\Tests\ProxyDriver;
use BotMan\BotMan\Messages\Attachments\Audio;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Attachments\Video;
use BotMan\BotMan\Messages\Attachments\Location;
use BotMan\BotMan\Tests\Fixtures\TestConversation;
use BotMan\BotMan\Messages\Incoming\IncomingMessage;
use BotMan\BotMan\Tests\Fixtures\TestDataConversation;

class BotManConversationTest extends PHPUnit_Framework_TestCase
{
    /** @var BotMan */
    private $botman;
    /** @var FakeDriver */
    private $fakeDriver;
    /** @var m\MockInterface */
    private $cache;

    public static function setUpBeforeClass()
    {
        DriverManager::loadDriver(ProxyDriver::class);
    }

    public static function tearDownAfterClass()
    {
        DriverManager::unloadDriver(ProxyDriver::class);
    }

    protected function setUp()
    {
        $this->fakeDriver = new FakeDriver();
        $this->cache = m::mock(ArrayCache::class)->makePartial();
        ProxyDriver::setInstance($this->fakeDriver);
        $this->botman = BotManFactory::create([], $this->cache);
    }

    protected function tearDown()
    {
        ProxyDriver::setInstance(FakeDriver::createInactive());
        m::close();
    }

    /** @test */
    public function it_caches_conversation_for_30_minutes()
    {
        $message = new IncomingMessage('Hello', 'helloman', '#helloworld');

        $this->botman->hears('Hello', function (BotMan $bot) {
            $bot->startConversation(new TestDataConversation());
        });

        $this->cache->shouldReceive('put')
            ->with($message->getConversationIdentifier(), m::any(), 30)
            ->once();

        $this->replyWithFakeMessage('Hello');
    }

    /** @test */
    public function it_caches_conversation_for_custom_amount_of_minutes()
    {
        $this->fakeDriver = new FakeDriver();
        $this->cache = m::mock(ArrayCache::class)->makePartial();
        ProxyDriver::setInstance($this->fakeDriver);
        $this->botman = BotManFactory::create([
            'config' => [
                'conversation_cache_time' => '50',
            ],
        ], $this->cache);

        $message = new IncomingMessage('Hello', 'helloman', '#helloworld');

        $this->botman->hears('Hello', function (BotMan $bot) {
            $bot->startConversation(new TestDataConversation());
        });

        $this->cache->shouldReceive('put')
            ->with($message->getConversationIdentifier(), m::any(), 50)
            ->once();

        $this->replyWithFakeMessage('Hello');
    }

    /** @test */
    public function it_uses_conversation_defined_cache_time()
    {
        $message = new IncomingMessage('Hello', 'helloman', '#helloworld');

        $this->botman->hears('Hello', function (BotMan $bot) {
{'fraction_non_alphanumeric': 0.145044319097502, 'fraction_numerical': 0.0030620467365028202, 'mean_word_length': 3.2477754962354553, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 71, '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': '3846484', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1822, 'n_words': 294}