<commit_before><?php namespace Codesleeve\Stapler\File\Image;

use PHPUnit_Framework_TestCase;
use Codesleeve\Stapler\File\UploadedFile;
use Codesleeve\Stapler\Style;
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Mockery as m;

class ResizerTest extends PHPUnit_Framework_TestCase
{
	/**
	 * Setup method.
	 *
	 * @return void
	 */
	public function setUp()
	{
	}

	/**
	 * Teardown method.
	 *
	 * @return void
	 */
	public function tearDown()
	{
		m::close();
	}

	/**
	 * Test the resize crop method.
	 *
	 * @test
	 * @return void
	 */
	public function it_should_be_able_to_resize_and_crop_an_image()
	{
		$uploadedFile = $this->buildUploadedFile();
		$originalSize = new Box(600, 400);
		$expectedResize = new Box(768, 512);
		$expectedCropPoint = new Point(128, 0);
		$expectedCropBox = new Box(512, 512);

		$image = $this->buildMockImage($originalSize, $expectedResize, $expectedCropPoint, $expectedCropBox);
		$imageProcessor = $this->buildMockImageProcessor($image);
		$resizer = new Resizer($imageProcessor);

		$style = $this->buildMockStyleObject('thumbnail', '512x512#');
		$file = $resizer->resize($uploadedFile, $style);
	}

	/**
	 * Test resize cropping edge case.
	 *
	 * @test
	 * @return void
	 */
	public function it_should_be_able_to_resize_and_crop_an_edge_case()
	{
		$uploadedFile = $this->buildUploadedFile();
		$originalSize = new Box(1000, 653);
		$expectedResize = new Box(440, 287.32);
		$expectedCropPoint = new Point(0, 21.66);
		$expectedCropBox = new Box(440, 244);

		$image = $this->buildMockImage($originalSize, $expectedResize, $expectedCropPoint, $expectedCropBox);
		$imageProcessor = $this->buildMockImageProcessor($image);
		$resizer = new Resizer($imageProcessor);

		$style = $this->buildMockStyleObject('thumbnail', '440x244#');
		$file = $resizer->resize($uploadedFile, $style);
	}

	/**
	* Helper method to build a mock Stapler UploadedFile object.
	*
	* @return UploadedFile
	*/
	protected function buildUploadedFile()
	{
		$path = __DIR__.'/../../Fixtures/empty.gif';
		$originalName = 'Test.gif';
		$symfonyUploadedFile = new SymfonyUploadedFile($path, $originalName, null, null, null, true);

		return new UploadedFile($symfonyUploadedFile);
	}

	/**<commit_msg>Use realpath for empty.gif.<commit_after><?php namespace Codesleeve\Stapler\File\Image;

use PHPUnit_Framework_TestCase;
use Codesleeve\Stapler\File\UploadedFile;
use Codesleeve\Stapler\Style;
use Symfony\Component\HttpFoundation\File\UploadedFile as SymfonyUploadedFile;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Mockery as m;

class ResizerTest extends PHPUnit_Framework_TestCase
{
	/**
	 * Setup method.
	 *
	 * @return void
	 */
	public function setUp()
	{
	}

	/**
	 * Teardown method.
	 *
	 * @return void
	 */
	public function tearDown()
	{
		m::close();
	}

	/**
	 * Test the resize crop method.
	 *
	 * @test
	 * @return void
	 */
	public function it_should_be_able_to_resize_and_crop_an_image()
	{
		$uploadedFile = $this->buildUploadedFile();
		$originalSize = new Box(600, 400);
		$expectedResize = new Box(768, 512);
		$expectedCropPoint = new Point(128, 0);
		$expectedCropBox = new Box(512, 512);

		$image = $this->buildMockImage($originalSize, $expectedResize, $expectedCropPoint, $expectedCropBox);
		$imageProcessor = $this->buildMockImageProcessor($image);
		$resizer = new Resizer($imageProcessor);

		$style = $this->buildMockStyleObject('thumbnail', '512x512#');
		$file = $resizer->resize($uploadedFile, $style);
	}

	/**
	 * Test resize cropping edge case.
	 *
	 * @test
	 * @return void
	 */
	public function it_should_be_able_to_resize_and_crop_an_edge_case()
	{
		$uploadedFile = $this->buildUploadedFile();
		$originalSize = new Box(1000, 653);
		$expectedResize = new Box(440, 287.32);
		$expectedCropPoint = new Point(0, 21.66);
		$expectedCropBox = new Box(440, 244);

		$image = $this->buildMockImage($originalSize, $expectedResize, $expectedCropPoint, $expectedCropBox);
		$imageProcessor = $this->buildMockImageProcessor($image);
		$resizer = new Resizer($imageProcessor);

		$style = $this->buildMockStyleObject('thumbnail', '440x244#');
		$file = $resizer->resize($uploadedFile, $style);
	}

	/**
	* Helper method to build a mock Stapler UploadedFile object.
	*
	* @return UploadedFile
	*/
	protected function buildUploadedFile()
	{
		$path = realpath(__DIR__ . '/../../Fixtures/empty.gif');
		$originalName = 'Test.gif';
		$symfonyUploadedFile = new SymfonyUploadedFile($path, $originalName, null, null, null, true);

		return new UploadedFile($symfonyUploadedFile);
	}

	/**
{'fraction_non_alphanumeric': 0.14155844155844155, 'fraction_numerical': 0.025974025974025976, 'mean_word_length': 4.747512437810945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '1686810', 'n_tokens_mistral': 1769, 'n_tokens_neox': 1570, 'n_words': 322}