<commit_before><?php

namespace Papper\Tests\Mapper;

use Papper\Mapper;
use Papper\Tests\TestCaseBase;

class MapperTest extends TestCaseBase
{
	public function testMapper_Should_CreateInstanceOfDestinationClass()
	{
		// arrange
		$map = $this->createMap(Source::className(), Destination::className());
		// act
		$destination = $map->map(new Source()); /** @var Destination $destination */
		// assert
		$this->assertInstanceOf(Destination::className(), $destination);
	}

	public function testMapper_Should_MapPublicProperties()
	{
		// arrange
		$map = $this->createMap(Source::className(), Destination::className());
		// act
		$destination = $map->map(new Source()); /** @var Destination $destination */
		// assert
		$this->assertEquals('Some value', $destination->someValue);
	}

	public function testMapper_Should_MapFromGetter()
	{
		// arrange
		$map = $this->createMap(SourceWithGetter::className(), Destination::className());
		// act
		$destination = $map->map(new SourceWithGetter()); /** @var Destination $destination */
		// assert
		$this->assertEquals('Some value', $destination->someValue);
	}

	public function testMapper_Should_MapToSetter()
	{
		// arrange
		$map = $this->createMap(Source::className(), DestinationWithSetter::className());
		// act
		$destination = $map->map(new Source()); /** @var DestinationWithSetter $destination */
		// assert
		$this->assertEquals('Some value', $destination->getSomeValue());
	}

	public function testMapper_Should_ConstructUsingClosureFactory()
	{
		// arrange
		$map = $this->createMap(Source::className(), DestinationWithConstructor::className());
		$map->constructUsing(function (Source $source){
			return new DestinationWithConstructor($source->someValue);
		});
		// act
		$destination = $map->map(new Source()); /** @var DestinationWithSetter $destination */
		// assert
		$this->assertEquals('Some value', $destination->getSomeValue());
	}

	public function testMapper_Should_RaiseException_When_ConstructNotExpectedDestinationClass()
	{
		$this->setExpectedException('Papper\ConstructedUnexpectedDestinationClass');
		// arrange
		$map = $this->createMap(Source::className(), Destination::className());
		$map->constructUsing(function (Source $source){
			return new DestinationWithConstructor($source->someValue);
		});
		// act
		$map->map(new Source()); /** @var DestinationWithSetter $destination */
	}

	private function createMap($sourceClass, $destinationClass)
	{
		return new Mapper($sourceClass, $destinationClass);
	}
}<commit_msg>Cleanup<commit_after><?php

namespace Papper\Tests\Mapper;

use Papper\Mapper;
use Papper\Tests\TestCaseBase;

class MapperTest extends TestCaseBase
{
	public function testMapper_Should_CreateInstanceOfDestinationClass()
	{
		// arrange
		$map = $this->createMap(Source::className(), Destination::className());
		// act
		$destination = $map->map(new Source()); /** @var Destination $destination */
		// assert
		$this->assertInstanceOf(Destination::className(), $destination);
	}

	public function testMapper_Should_MapPublicProperties()
	{
		// arrange
		$map = $this->createMap(Source::className(), Destination::className());
		// act
		$destination = $map->map(new Source()); /** @var Destination $destination */
		// assert
		$this->assertEquals('Some value', $destination->someValue);
	}

	public function testMapper_Should_MapFromGetter()
	{
		// arrange
		$map = $this->createMap(SourceWithGetter::className(), Destination::className());
		// act
		$destination = $map->map(new SourceWithGetter()); /** @var Destination $destination */
		// assert
		$this->assertEquals('Some value', $destination->someValue);
	}

	public function testMapper_Should_MapToSetter()
	{
		// arrange
		$map = $this->createMap(Source::className(), DestinationWithSetter::className());
		// act
		$destination = $map->map(new Source()); /** @var DestinationWithSetter $destination */
		// assert
		$this->assertEquals('Some value', $destination->getSomeValue());
	}

	public function testMapper_Should_ConstructUsingClosureFactory()
	{
		// arrange
		$map = $this->createMap(Source::className(), DestinationWithConstructor::className());
		$map->constructUsing(function (Source $source){
			return new DestinationWithConstructor($source->someValue);
		});
		// act
		$destination = $map->map(new Source()); /** @var DestinationWithSetter $destination */
		// assert
		$this->assertEquals('Some value', $destination->getSomeValue());
	}

	public function testMapper_Should_RaiseException_When_ConstructNotExpectedDestinationClass()
	{
		$this->setExpectedException('Papper\ConstructedUnexpectedDestinationClass');
		// arrange
		$map = $this->createMap(Source::className(), Destination::className());
		$map->constructUsing(function (Source $source){
			return new DestinationWithConstructor($source->someValue);
		});
		// act
		$map->map(new Source());
	}

	private function createMap($sourceClass, $destinationClass)
	{
		return new Mapper($sourceClass, $destinationClass);
	}
}
{'fraction_non_alphanumeric': 0.15713425647200482, 'fraction_numerical': 0.0, 'mean_word_length': 5.523560209424084, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, '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': '5924134', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1402, 'n_words': 265}