<commit_before><?php
/**
 * PHP Image Manipulation & Processing Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * @category   Image
 * @package    Processor
 * @subpackage Adapter_AbstractTest
 * @copyright  Copyright (c) 2012 PHP Image Manipulation & Processing Library
 * @license    http://www.opensource.org/licenses/bsd-license.php
 * @since      Sunday, 28 October 2012
 */
/**
 * @see vfsStream
 */
require_once 'vfsStream/vfsStream.php';
/**
 * @see Image_Processor_Adapter_Gd2
 */
require_once 'Image/Processor/Adapter/Abstract.php';
/**
 * Image processor adapter abstract test class.
 *
 * @category   Image
 * @package    Processor
 * @subpackage Adapter_AbstractTest
 * @copyright  Copyright (c) 2012 PHP Image Manipulation & Processing Library
 * @license    http://www.opensource.org/licenses/bsd-license.php
 */
class Image_Processor_Adapter_AbstractTest extends PHPUnit_Framework_TestCase
{
    /**
     * Tests setting file name with empty file name throws correct exception.
     */
    public function testSetFileNameWithEmptyFileName()
    {
        $abstract = $this->getSutMock();

        $this->setExpectedException(
            'Image_Processor_Adapter_Exception',
            'The file name / location was empty'
        );

        $abstract->setFileName('');
    }

    /**
     * Tests setting file name with unreadable file throws correct exception.
     */
    public function testSetFileNameWithUnreadabelFile()
    {
        $fileName = $this->createTempVfsFile(0622);

        $abstract = $this->getSutMock();

        $this->setExpectedException(
            'Image_Processor_Adapter_Exception',
            "The file name / location '{$fileName}' was not readable"
        );

        $abstract->setFileName($fileName);
    }

    /**
     * Tests set/get file name with existent file.
     */
    public function testSetGetFileName()
    {
        $fileName = $this->createTempVfsFile(0777);

        $abstract = $this->getSutMock(array(), array('_getFileAttributes', '_getImageStatistics'));
        $abstract->expects($this->once())
                 ->method('_getFileAttributes');
        $abstract->expects($this->once())
                 ->method('_getImageStatistics');

        $this->assertInstanceOf(get_class($abstract), $abstract->setFileName($fileName));
        $this->assertEquals($fileName, $abstract->getFileName());
    }

    /**
     * Reurns a mock object of the abstract class.
     *
     * @param  array $arguments
     * @param  array $mockedMethods
     * @return Image_Processor_Adapter_Abstract
     */
    public function getSutMock(array $arguments = array(), $mockedMethods = array())
    {
        srand(time() . rand(1,150111));

        return $this->getMockForAbstractClass(
            'Image_Processor_Adapter_Abstract',
            $arguments,<commit_msg>Amended unit test so that file is unreadable but still writeable.<commit_after><?php
/**
 * PHP Image Manipulation & Processing Library
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/bsd-license.php
 *
 * @category   Image
 * @package    Processor
 * @subpackage Adapter_AbstractTest
 * @copyright  Copyright (c) 2012 PHP Image Manipulation & Processing Library
 * @license    http://www.opensource.org/licenses/bsd-license.php
 * @since      Sunday, 28 October 2012
 */
/**
 * @see vfsStream
 */
require_once 'vfsStream/vfsStream.php';
/**
 * @see Image_Processor_Adapter_Gd2
 */
require_once 'Image/Processor/Adapter/Abstract.php';
/**
 * Image processor adapter abstract test class.
 *
 * @category   Image
 * @package    Processor
 * @subpackage Adapter_AbstractTest
 * @copyright  Copyright (c) 2012 PHP Image Manipulation & Processing Library
 * @license    http://www.opensource.org/licenses/bsd-license.php
 */
class Image_Processor_Adapter_AbstractTest extends PHPUnit_Framework_TestCase
{
    /**
     * Tests setting file name with empty file name throws correct exception.
     */
    public function testSetFileNameWithEmptyFileName()
    {
        $abstract = $this->getSutMock();

        $this->setExpectedException(
            'Image_Processor_Adapter_Exception',
            'The file name / location was empty'
        );

        $abstract->setFileName('');
    }

    /**
     * Tests setting file name with unreadable file throws correct exception.
     */
    public function testSetFileNameWithUnreadabelFile()
    {
        $fileName = $this->createTempVfsFile(0222); // No-one can read, but all write

        $abstract = $this->getSutMock();

        $this->setExpectedException(
            'Image_Processor_Adapter_Exception',
            "The file name / location '{$fileName}' was not readable"
        );

        $abstract->setFileName($fileName);
    }

    /**
     * Tests set/get file name with existent file.
     */
    public function testSetGetFileName()
    {
        $fileName = $this->createTempVfsFile(0777);

        $abstract = $this->getSutMock(array(), array('_getFileAttributes', '_getImageStatistics'));
        $abstract->expects($this->once())
                 ->method('_getFileAttributes');
        $abstract->expects($this->once())
                 ->method('_getImageStatistics');

        $this->assertInstanceOf(get_class($abstract), $abstract->setFileName($fileName));
        $this->assertEquals($fileName, $abstract->getFileName());
    }

    /**
     * Reurns a mock object of the abstract class.
     *
     * @param  array $arguments
     * @param  array $mockedMethods
     * @return Image_Processor_Adapter_Abstract
     */
    public function getSutMock(array $arguments = array(), $mockedMethods = array())
    {
        srand(time() . rand(1, 150111));

        return $this->getMockForAbstractClass(
            'Image_Processor_Adapter_Abstract',
            $arguments,
{'fraction_non_alphanumeric': 0.11510441962117533, 'fraction_numerical': 0.009713453132588635, 'mean_word_length': 2.9225396825396825, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '4815483', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1667, 'n_words': 418}