<commit_before><?php
namespace SpotTest;
use SpotTest\Entity\Legacy;

/**
 * @package Spot
 */
class FieldAlias extends \PHPUnit_Framework_TestCase
{
    public static $legacyTable;

    public static function setupBeforeClass()
    {
        self::$legacyTable = new \SpotTest\Entity\Legacy();
        foreach (['Legacy', 'PolymorphicComment'] as $entity) {
            test_spot_mapper('SpotTest\Entity\\' . $entity)->migrate();
        }
    }

    public static function tearDownAfterClass()
    {
        foreach (['Legacy', 'PolymorphicComment'] as $entity) {
            test_spot_mapper('\SpotTest\Entity\\' . $entity)->dropTable();
        }
    }

    public function testLegacySelectFieldsAreAliases()
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $query = $mapper->select()->noQuote()->where(['number' => 2, 'name' => 'legacy_crud']);
        $this->assertEquals("SELECT * FROM test_legacy  WHERE test_legacy." . self::$legacyTable->getNumberFieldColumnName() ." = ? AND test_legacy." . self::$legacyTable->getNameFieldColumnName() . " = ?", $query->toSql());
    }

    // Ordering
    public function testLegacyOrderBy()
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $query = $mapper->select()->noQuote()->where(['number' => 2])->order(['date_created' => 'ASC']);
        $this->assertContains("ORDER BY test_legacy." . self::$legacyTable->getDateCreatedColumnName() . " ASC", $query->toSql());
    }

    // Grouping
    public function testLegacyGroupBy()
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $query = $mapper->select()->noQuote()->where(['name' => 'test_group'])->group(['id']);
        $this->assertEquals("SELECT * FROM test_legacy  WHERE test_legacy." . self::$legacyTable->getNameFieldColumnName() . " = ? GROUP BY test_legacy." . self::$legacyTable->getIdFieldColumnName(), $query->toSql());
    }

    // Insert
    public function testLegacyInsert()
    {
        $legacy = new Legacy();
        $legacy->name = 'Something Here';
        $legacy->number = 5;

        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $mapper->save($legacy);
        return $legacy;
    }

    /**
     * @depends testLegacyInsert
     */
    public function testLegacyUpdate(Legacy $legacy)
    {
        $legacy->name = 'Something ELSE Here';
        $legacy->number = 6;

        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $mapper->save($legacy);
    }

    /**
     * @depends testLegacyInsert
     */
    public function testLegacyEntityFieldMapping(Legacy $legacy)
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $savedLegacyItem = $mapper->first();

        $this->assertEquals($legacy->name, $savedLegacyItem->name);
        $this->assertEquals($legacy->number, $savedLegacyItem->number);
    }
<commit_msg>Add test for toArray with field mappings<commit_after><?php
namespace SpotTest;
use SpotTest\Entity\Legacy;

/**
 * @package Spot
 */
class FieldAlias extends \PHPUnit_Framework_TestCase
{
    public static $legacyTable;

    public static function setupBeforeClass()
    {
        self::$legacyTable = new \SpotTest\Entity\Legacy();
        foreach (['Legacy', 'PolymorphicComment'] as $entity) {
            test_spot_mapper('SpotTest\Entity\\' . $entity)->migrate();
        }
    }

    public static function tearDownAfterClass()
    {
        foreach (['Legacy', 'PolymorphicComment'] as $entity) {
            test_spot_mapper('\SpotTest\Entity\\' . $entity)->dropTable();
        }
    }

    public function testLegacySelectFieldsAreAliases()
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $query = $mapper->select()->noQuote()->where(['number' => 2, 'name' => 'legacy_crud']);
        $this->assertEquals("SELECT * FROM test_legacy  WHERE test_legacy." . self::$legacyTable->getNumberFieldColumnName() ." = ? AND test_legacy." . self::$legacyTable->getNameFieldColumnName() . " = ?", $query->toSql());
    }

    // Ordering
    public function testLegacyOrderBy()
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $query = $mapper->select()->noQuote()->where(['number' => 2])->order(['date_created' => 'ASC']);
        $this->assertContains("ORDER BY test_legacy." . self::$legacyTable->getDateCreatedColumnName() . " ASC", $query->toSql());
    }

    // Grouping
    public function testLegacyGroupBy()
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $query = $mapper->select()->noQuote()->where(['name' => 'test_group'])->group(['id']);
        $this->assertEquals("SELECT * FROM test_legacy  WHERE test_legacy." . self::$legacyTable->getNameFieldColumnName() . " = ? GROUP BY test_legacy." . self::$legacyTable->getIdFieldColumnName(), $query->toSql());
    }

    // Insert
    public function testLegacyInsert()
    {
        $legacy = new Legacy();
        $legacy->name = 'Something Here';
        $legacy->number = 5;

        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $mapper->save($legacy);
        return $legacy;
    }

    /**
     * @depends testLegacyInsert
     */
    public function testLegacyEntityToArrayUsesFieldMappings(Legacy $legacy)
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $savedLegacyItem = $mapper->first();
        $data = $savedLegacyItem->toArray();

        $this->assertEquals($data['name'], 'Something Here');
        $this->assertEquals($data['number'], 5);
    }

    /**
     * @depends testLegacyInsert
     */
    public function testLegacyUpdate(Legacy $legacy)
    {
        $legacy->name = 'Something ELSE Here';
        $legacy->number = 6;

        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $mapper->save($legacy);
    }

    /**
     * @depends testLegacyInsert
     */
    public function testLegacyEntityFieldMapping(Legacy $legacy)
    {
        $mapper = test_spot_mapper('SpotTest\Entity\Legacy');
        $savedLegacyItem = $mapper->first();

        $this->assertEquals($legacy->name, $savedLegacyItem->name);
        $this->assertEquals($legacy->number, $savedLegacyItem->number);
    }

{'fraction_non_alphanumeric': 0.16268174474959612, 'fraction_numerical': 0.0014539579967689823, 'mean_word_length': 3.0464052287581698, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, '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': '1639016', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1894, 'n_words': 305}