<commit_before><?php

namespace {  
    // This allow us to configure the behavior of the "global mock"  
    $mockTmpFile = false;   
    $mockFopen = false;  
}  

namespace eXorus\PhpMimeMailParser {

use eXorus\PhpMimeMailParser\Parser;
use eXorus\PhpMimeMailParser\Attachment;
use eXorus\PhpMimeMailParser\Exception;

function tmpfile() {  
    global $mockTmpFile;  
    if (isset($mockTmpFile) && $mockTmpFile === true) {  
        return false;  
    } else {  
        return call_user_func_array('\tmpfile', func_get_args());  
    }  
} 

function fopen() {  
    global $mockFopen;  
    if (isset($mockFopen) && $mockFopen === true) {  
        return false;  
    } else {  
        return call_user_func_array('\fopen', func_get_args());  
    }  
} 

/**
 * ExceptionTest of php-mime-mail-parser
 *
 * Fully Tested Mailparse Extension Wrapper for PHP 5.3+
 *
 */

class ExceptionTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()  
    {  
        global $mockTmpFile;  
        $mockTmpFile = false;  

        global $mockFopen;  
        $mockFopen = false; 
    }  

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage setPath() or setText() or setStream() must be called before retrieving email headers.
     */
    public function testGetHeader()
    {
		$Parser = new Parser();
		$Parser->getHeader('test');
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Invalid type specified for getMessageBody(). "type" can either be text or html.
     */
    public function testgetMessageBody()
    {
		$Parser = new Parser();
		$Parser->getMessageBody('azerty');
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage setStream() expects parameter stream to be resource.
     */
    public function testSetStream()
    {
        $Parser = new Parser();
        $Parser->setStream('azerty');
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.
     */
    public function testSetStreamWithoutTmpPermissions()
    {
        global $mockTmpFile;  
        $mockTmpFile = true;  

        $file = __DIR__.'/mails/m0001';

        $Parser = new Parser();
        $Parser->setStream(fopen($file, 'r'));
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.
     */
    public function testGetAttachmentStreamWithoutTmpPermissions()
    {

        $file = __DIR__.'/mails/m0001';

        $Parser = new Parser();
        $Parser->setStream(fopen($file, 'r'));

        global $mockTmpFile;  
        $mockTmpFile = true;  

        $attachments = $Parser->getAttachments();
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage setStream() expects parameter stream to be stream resource.
     */
    public function testSetStreamResource()
    {
        $c = mysql_connect();
        $Parser = new Parser();
        $Parser->setStream($c);
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Could not write attachments. Your directory may be unwritable by PHP.
     */
    public function testSaveAttachmentsWithoutPermissions()
    {
        $mid = 'm0001';
        $file = __DIR__.'/mails/'.$mid;
        $attach_dir = __DIR__.'/mails/attach_'.$mid.'/';
        $attach_url = 'http://www.company.com/attachments/'.$mid.'/';

        $Parser = new Parser();
        $Parser->setStream(fopen($file, 'r'));

        global $mockFopen;  
        $mockFopen = true;  

        $Parser->saveAttachments($attach_dir, $attach_url);
    }
    
}
}<commit_msg>Update ExceptionTest.php<commit_after><?php

namespace {  
    // This allow us to configure the behavior of the "global mock"  
    $mockTmpFile = false;   
    $mockFopen = false;  
}  

namespace eXorus\PhpMimeMailParser {

use eXorus\PhpMimeMailParser\Parser;
use eXorus\PhpMimeMailParser\Attachment;
use eXorus\PhpMimeMailParser\Exception;

function tmpfile() {  
    global $mockTmpFile;  
    if (isset($mockTmpFile) && $mockTmpFile === true) {  
        return false;  
    } else {  
        return call_user_func_array('\tmpfile', func_get_args());  
    }  
} 

function fopen() {  
    global $mockFopen;  
    if (isset($mockFopen) && $mockFopen === true) {  
        return false;  
    } else {  
        return call_user_func_array('\fopen', func_get_args());  
    }  
} 

/**
 * ExceptionTest of php-mime-mail-parser
 *
 * Fully Tested Mailparse Extension Wrapper for PHP 5.3+
 *
 */

class ExceptionTest extends \PHPUnit_Framework_TestCase
{
    public function setUp()  
    {  
        global $mockTmpFile;  
        $mockTmpFile = false;  

        global $mockFopen;  
        $mockFopen = false; 
    }  

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage setPath() or setText() or setStream() must be called before retrieving email headers.
     */
    public function testGetHeader()
    {
		$Parser = new Parser();
		$Parser->getHeader('test');
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Invalid type specified for getMessageBody(). "type" can either be text or html.
     */
    public function testgetMessageBody()
    {
		$Parser = new Parser();
		$Parser->getMessageBody('azerty');
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage setStream() expects parameter stream to be resource.
     */
    public function testSetStream()
    {
        $Parser = new Parser();
        $Parser->setStream('azerty');
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.
     */
    public function testSetStreamWithoutTmpPermissions()
    {
        global $mockTmpFile;  
        $mockTmpFile = true;  

        $file = __DIR__.'/mails/m0001';

        $Parser = new Parser();
        $Parser->setStream(fopen($file, 'r'));
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Could not create temporary files for attachments. Your tmp directory may be unwritable by PHP.
     */
    public function testGetAttachmentStreamWithoutTmpPermissions()
    {

        $file = __DIR__.'/mails/m0001';

        $Parser = new Parser();
        $Parser->setStream(fopen($file, 'r'));

        global $mockTmpFile;  
        $mockTmpFile = true;  

        $attachments = $Parser->getAttachments();
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage setStream() expects parameter stream to be stream resource.
     */
    public function testSetStreamResource()
    {
        $c = socket_create(AF_UNIX, SOCK_STREAM, 0);
        $Parser = new Parser();
        $Parser->setStream($c);
    }

    /**
     * @expectedException        Exception
     * @expectedExceptionMessage Could not write attachments. Your directory may be unwritable by PHP.
     */
    public function testSaveAttachmentsWithoutPermissions()
    {
        $mid = 'm0001';
        $file = __DIR__.'/mails/'.$mid;
        $attach_dir = __DIR__.'/mails/attach_'.$mid.'/';
        $attach_url = 'http://www.company.com/attachments/'.$mid.'/';

        $Parser = new Parser();
        $Parser->setStream(fopen($file, 'r'));

        global $mockFopen;  
        $mockFopen = true;  

        $Parser->saveAttachments($attach_dir, $attach_url);
    }
    
}
}

{'fraction_non_alphanumeric': 0.1146604337099078, 'fraction_numerical': 0.003765744708479418, 'mean_word_length': 2.4079646017699115, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5135982', 'n_tokens_mistral': 2329, 'n_tokens_neox': 2260, 'n_words': 527}