<commit_before><?php

namespace Test\Synapse\Mapper;

use Synapse\TestHelper\MapperTestCase;
use Synapse\User\UserEntity;
use ReflectionClass;

class AbstractMapperTest extends MapperTestCase
{
    public function setUp()
    {
        parent::setUp();

        $this->mapper = new Mapper($this->mockAdapter);
    }

    public function createPrototype()
    {
        return new UserEntity();
    }

    public function createEntity()
    {
        return new UserEntity([
            'id'       => 100,
            'email'    => '<EMAIL>',
            'password' => 'password',
        ]);
    }

    public function capturingSqlStrings()
    {
        $this->mapper->setSqlFactory($this->mockSqlFactory);
    }

    public function testGetPrototypeReturnsCloneOfPrototype()
    {
        $prototype = $this->createPrototype();

        $this->mapper->setPrototype($prototype);

        // Assert that the given prototype and the retrieved one are not references to the same object
        $this->assertNotSame($prototype, $this->mapper->getPrototype());

        // Demonstrate that a clone was provided by comparing the array copies
        $this->assertEquals(
            $prototype->getArrayCopy(),
            $this->mapper->getPrototype()->getArrayCopy()
        );
    }

    /**
     * The AbstractMapper includes a provision for backwards compatibility in getSqlObject, an internal method
     * of the class
     *
     * This method tests the backwards compatibility by making sure that no exception is thrown when no
     * SqlFactory has been set on the mapper
     */
    public function testGetSqlObjectDoesNotThrowExceptionIfSqlFactoryNotSet()
    {
        $this->mapper->findById(1);

        // Perform a dummy assertion so that this test does not appear as "risky"
        $this->assertTrue(true);
    }

    public function testPersistCallsUpdateIfEntityHasId()
    {
        $this->capturingSqlStrings();

        $entity = $this->createEntity();

        $this->mapper->persist($entity);

        $this->assertRegExpOnSqlString('/UPDATE/');
    }

    public function testPersistCallsInsertIfEntityDoesNotHaveId()
    {
        $this->capturingSqlStrings();

        $entity = $this->createEntity()->setId(null);

        $this->mapper->persist($entity);
<commit_msg>Refs #143 - Fix test.<commit_after><?php

namespace Test\Synapse\Mapper;

use Synapse\TestHelper\MapperTestCase;
use Synapse\User\UserEntity;
use ReflectionClass;

class AbstractMapperTest extends MapperTestCase
{
    public function setUp()
    {
        parent::setUp();

        $this->mapper = new Mapper($this->mockAdapter);

        $this->mapper->setSqlFactory($this->mockSqlFactory);
    }

    public function createPrototype()
    {
        return new UserEntity();
    }

    public function createEntity()
    {
        return new UserEntity([
            'id'       => 100,
            'email'    => '<EMAIL>',
            'password' => 'password',
        ]);
    }

    public function testGetPrototypeReturnsCloneOfPrototype()
    {
        $prototype = $this->createPrototype();

        $this->mapper->setPrototype($prototype);

        // Assert that the given prototype and the retrieved one are not references to the same object
        $this->assertNotSame($prototype, $this->mapper->getPrototype());

        // Demonstrate that a clone was provided by comparing the array copies
        $this->assertEquals(
            $prototype->getArrayCopy(),
            $this->mapper->getPrototype()->getArrayCopy()
        );
    }

    /**
     * The AbstractMapper includes a provision for backwards compatibility in getSqlObject, an internal method
     * of the class
     *
     * This method tests the backwards compatibility by making sure that no exception is thrown when no
     * SqlFactory has been set on the mapper
     */
    public function testGetSqlObjectDoesNotThrowExceptionIfSqlFactoryNotSet()
    {
        $this->mapper->findById(1);

        // Perform a dummy assertion so that this test does not appear as "risky"
        $this->assertTrue(true);
    }

    public function testPersistCallsUpdateIfEntityHasId()
    {
        $entity = $this->createEntity();

        $this->mapper->persist($entity);

        $this->assertRegExpOnSqlString('/UPDATE/');
    }

    public function testPersistCallsInsertIfEntityDoesNotHaveId()
    {
        $entity = $this->createEntity()->setId(null);

        $this->mapper->persist($entity);

{'fraction_non_alphanumeric': 0.10914388166741372, 'fraction_numerical': 0.002465262214253698, 'mean_word_length': 2.6284552845528455, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 67, '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': '3394207', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1180, 'n_words': 302}