<commit_before><?php

namespace Rhubarb\Stem\Tests\unit\Collections;

use Rhubarb\Stem\Collections\RepositoryCollection;
use Rhubarb\Stem\Exceptions\BatchUpdateNotPossibleException;
use Rhubarb\Stem\Exceptions\SortNotValidException;
use Rhubarb\Stem\Filters\Equals;
use Rhubarb\Stem\Filters\GreaterThan;
use Rhubarb\Stem\Repositories\MySql\MySql;
use Rhubarb\Stem\Tests\unit\Fixtures\Company;
use Rhubarb\Stem\Tests\unit\Repositories\MySql\MySqlTestCase;

class CollectionMySqlTest extends MySqlTestCase
{
    public function testBatchUpdate()
    {
        MySql::executeStatement("TRUNCATE TABLE tblCompany");

        $company = new Company();
        $company->CompanyName = "GCD";
        $company->Active = true;
        $company->save();

        $company = new Company();
        $company->CompanyName = "Unit Design";
        $company->Active = true;
        $company->save();

        $company = new Company();
        $company->CompanyName = "Goats Boats";
        $company->Active = true;
        $company->save();

        Company::find()->batchUpdate(["CompanyName" => "Test Company"]);

        $lastStatement = MySql::getPreviousStatement();

        $this->assertContains("SET `CompanyName` =", $lastStatement);
        $this->assertContains("`Active` =", $lastStatement);

        $count = MySql::returnSingleValue("SELECT COUNT(*) FROM tblCompany WHERE CompanyName = 'Test Company'");

        $this->assertEquals(3, $count);

        try {
            Company::find(new GreaterThan(
                "CompanyIDSquared",
                0,
                true
            ))->batchUpdate(["CompanyName" => "Test Company 2"]);

            $this->fail("Batch update shouldn't have been allowed if not filtered by the repository.");<commit_msg>fix for updated sql calls, not tested<commit_after><?php

namespace Rhubarb\Stem\Tests\unit\Collections;

use Rhubarb\Stem\Collections\RepositoryCollection;
use Rhubarb\Stem\Exceptions\BatchUpdateNotPossibleException;
use Rhubarb\Stem\Exceptions\SortNotValidException;
use Rhubarb\Stem\Filters\Equals;
use Rhubarb\Stem\Filters\GreaterThan;
use Rhubarb\Stem\Repositories\MySql\MySql;
use Rhubarb\Stem\Tests\unit\Fixtures\Company;
use Rhubarb\Stem\Tests\unit\Repositories\MySql\MySqlTestCase;

class CollectionMySqlTest extends MySqlTestCase
{
    public function testBatchUpdate()
    {
        MySql::executeStatement("TRUNCATE TABLE tblCompany");

        $company = new Company();
        $company->CompanyName = "GCD";
        $company->Active = true;
        $company->save();

        $company = new Company();
        $company->CompanyName = "Unit Design";
        $company->Active = true;
        $company->save();

        $company = new Company();
        $company->CompanyName = "Goats Boats";
        $company->Active = true;
        $company->save();

        Company::find()->batchUpdate(["CompanyName" => "Test Company"]);

        $lastStatement = MySql::getPreviousStatement();

        $this->assertContains("SET `Company`.`CompanyName` =", $lastStatement);
        $this->assertContains("`Active` =", $lastStatement);

        $count = MySql::returnSingleValue("SELECT COUNT(*) FROM tblCompany WHERE CompanyName = 'Test Company'");

        $this->assertEquals(3, $count);

        try {
            Company::find(new GreaterThan(
                "CompanyIDSquared",
                0,
                true
            ))->batchUpdate(["CompanyName" => "Test Company 2"]);

            $this->fail("Batch update shouldn't have been allowed if not filtered by the repository.");
{'fraction_non_alphanumeric': 0.13329583802024747, 'fraction_numerical': 0.001687289088863892, 'mean_word_length': 3.0885057471264368, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '4661428', 'n_tokens_mistral': 1031, 'n_tokens_neox': 996, 'n_words': 201}