<commit_before><?php namespace Larapress\Tests\Services;

use Artisan;
use Input;
use Larapress\Tests\TestCase;
use Log;
use Mail;
use Narrator;
use Sentry;

class NarratorTest extends TestCase
{

    protected $log_message;

    /*
    |--------------------------------------------------------------------------
    | Narrator::sendMail() Tests
    |--------------------------------------------------------------------------
    |
    | Here is where you can test the Narrator::sendMail() method
    |
    */

    /**
     * @expectedException \Larapress\Exceptions\MailException
     * @expectedExceptionMessage foo
     */
    public function test_can_throw_a_mail_exception_with_error_message()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = 'foo';

        Mail::shouldReceive('send')->once()->andReturn(false);

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
    }

    /**
     * @expectedException \Larapress\Exceptions\MailException
     * @expectedExceptionMessage Cannot send message without a sender address
     */
    public function test_can_throw_a_mail_exception_warning_about_missing_sender_address()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = 'foo';

        Mail::shouldReceive('send')->once()->andThrow(
            'Swift_TransportException',
            'Cannot send message without a sender address'
        );

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
    }

    /**
     * @expectedException \Larapress\Exceptions\MailException
     * @expectedExceptionMessage foo
     */
    public function test_can_fall_back_to_the_provided_error_message_on_unknown_swift_transport_exception_messages()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = 'foo';

        Mail::shouldReceive('send')->once()->andThrow(
            'Swift_TransportException',
            'bar'
        );

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
    }

    public function test_can_send_an_email()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = '';

        Log::listen(function($level, $message, $context)
        {
            $this->log_message = $message;
        });

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
        $this->assertEquals('Pretending to mail message to: <EMAIL>', $this->log_message);
    }

    /*
    |--------------------------------------------------------------------------
    | Narrator::resetPassword() Tests
    |--------------------------------------------------------------------------
    |
    | Here is where you can test the Narrator::resetPassword() method
    |
    */

    /**
     * @expectedException \Cartalyst\Sentry\Users\UserNotFoundException
     */
    public function test_can_throw_a_user_not_found_exception()
    {
        Artisan::call('larapress:install');
        Input::merge(array('email' => '<EMAIL>'));

        Narrator::resetPassword();
    }

    public function test_can_send_a_reset_password_email()
    {
        Artisan::call('larapress:install');
        Input::merge(array('email' => '<EMAIL>'));

        Log::listen(function($level, $message, $context)
        {
            $this->log_message = $message;
        });

        Narrator::resetPassword();

        $this->assertEquals('Pretending to mail message to: <EMAIL>', $this->log_message);
    }

}<commit_msg>Fix some tests for php 5.3<commit_after><?php namespace Larapress\Tests\Services;

use Artisan;
use Input;
use Larapress\Tests\TestCase;
use Log;
use Mail;
use Narrator;
use Sentry;

class NarratorTest extends TestCase
{

    protected $log_message;

    /*
    |--------------------------------------------------------------------------
    | Narrator::sendMail() Tests
    |--------------------------------------------------------------------------
    |
    | Here is where you can test the Narrator::sendMail() method
    |
    */

    /**
     * @expectedException \Larapress\Exceptions\MailException
     * @expectedExceptionMessage foo
     */
    public function test_can_throw_a_mail_exception_with_error_message()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = 'foo';

        Mail::shouldReceive('send')->once()->andReturn(false);

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
    }

    /**
     * @expectedException \Larapress\Exceptions\MailException
     * @expectedExceptionMessage Cannot send message without a sender address
     */
    public function test_can_throw_a_mail_exception_warning_about_missing_sender_address()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = 'foo';

        Mail::shouldReceive('send')->once()->andThrow(
            'Swift_TransportException',
            'Cannot send message without a sender address'
        );

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
    }

    /**
     * @expectedException \Larapress\Exceptions\MailException
     * @expectedExceptionMessage foo
     */
    public function test_can_fall_back_to_the_provided_error_message_on_unknown_swift_transport_exception_messages()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = 'foo';

        Mail::shouldReceive('send')->once()->andThrow(
            'Swift_TransportException',
            'bar'
        );

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
    }

    public function test_can_send_an_email()
    {
        $to = array('address' => '<EMAIL>', 'name' => null);
        $subject = 'Test';
        $data = array();
        $view = array();
        $mail_error_message = '';

        $self = $this;

        Log::listen(function($level, $message, $context) use ($self)
        {
            $self->log_message = $message;
        });

        Narrator::sendMail($to, $subject, $data, $view, $mail_error_message);
        $this->assertEquals('Pretending to mail message to: <EMAIL>', $this->log_message);
    }

    /*
    |--------------------------------------------------------------------------
    | Narrator::resetPassword() Tests
    |--------------------------------------------------------------------------
    |
    | Here is where you can test the Narrator::resetPassword() method
    |
    */

    /**
     * @expectedException \Cartalyst\Sentry\Users\UserNotFoundException
     */
    public function test_can_throw_a_user_not_found_exception()
    {
        Artisan::call('larapress:install');
        Input::merge(array('email' => '<EMAIL>'));

        Narrator::resetPassword();
    }

    public function test_can_send_a_reset_password_email()
    {
        Artisan::call('larapress:install');
        Input::merge(array('email' => '<EMAIL>'));

        $self = $this;

        Log::listen(function($level, $message, $context) use ($self)
        {
            $self->log_message = $message;
        });

        Narrator::resetPassword();

        $this->assertEquals('Pretending to mail message to: <EMAIL>', $this->log_message);
    }

}
{'fraction_non_alphanumeric': 0.20923116154532703, 'fraction_numerical': 0.0002550044625780951, 'mean_word_length': 2.0462135922330096, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 63, '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': '124382', 'n_tokens_mistral': 2238, 'n_tokens_neox': 2170, 'n_words': 415}