<commit_before><?php
namespace App\Test\TestCase\Command;

use Cake\TestSuite\ConsoleIntegrationTestTrait;
use Cake\TestSuite\TestCase;
use Cake\ORM\TableRegistry;
use Cake\Console\Command;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;

class FixHashesCommandTest extends TestCase
{
    use ConsoleIntegrationTestTrait;

    public $fixtures = [
        'app.sentences',
        'app.reindex_flags',
        'app.transcriptions',
        'app.contributions',
        'app.tags',
        'app.tags_sentences',
        'app.users',
        'app.users_languages',
    ];

    const TESTDIR = TMP . 'fix_hashes_tests' . DS;

    public static function setUpBeforeClass() {
        mkdir(self::TESTDIR, 0755, true);
    }

    public static function tearDownAfterClass() {
        $folder = new Folder(self::TESTDIR);
        $folder->delete();
    }

    public function setUp() {
        parent::setUp();
        $this->UseCommandRunner();
        $this->Sentences = TableRegistry::getTableLocator()->get('Sentences');
        $this->Contributions = TableRegistry::getTableLocator()->get('Contributions');
    }

    public function testExecute_completeDatabase() {
        $this->exec('fix_hashes Sentences');
        $this->assertOutputContains(
            sprintf('%u rows checked', $this->Sentences->find()->count())
        );
        $this->assertOutputContains('8 rows changed');

        $hash = $this->Sentences->get(3)->hash;
        $modified = $this->Sentences->get(3)->modified;
        $this->assertEquals("2hfhma4\0\0\0\0\0\0\0\0\0", $hash);
        $this->assertEquals("2014-04-15 00:33:18", $modified);<commit_msg>Make creation of temporary test directory more robust<commit_after><?php
namespace App\Test\TestCase\Command;

use Cake\TestSuite\ConsoleIntegrationTestTrait;
use Cake\TestSuite\TestCase;
use Cake\ORM\TableRegistry;
use Cake\Console\Command;
use Cake\Filesystem\Folder;
use Cake\Filesystem\File;

class FixHashesCommandTest extends TestCase
{
    use ConsoleIntegrationTestTrait;

    public $fixtures = [
        'app.sentences',
        'app.reindex_flags',
        'app.transcriptions',
        'app.contributions',
        'app.tags',
        'app.tags_sentences',
        'app.users',
        'app.users_languages',
    ];

    const TESTDIR = TMP . 'fix_hashes_tests' . DS;

    public static function setUpBeforeClass() {
        new Folder(self::TESTDIR, true, 0755);
    }

    public static function tearDownAfterClass() {
        $folder = new Folder(self::TESTDIR);
        $folder->delete();
    }

    public function setUp() {
        parent::setUp();
        $this->UseCommandRunner();
        $this->Sentences = TableRegistry::getTableLocator()->get('Sentences');
        $this->Contributions = TableRegistry::getTableLocator()->get('Contributions');
    }

    public function testExecute_completeDatabase() {
        $this->exec('fix_hashes Sentences');
        $this->assertOutputContains(
            sprintf('%u rows checked', $this->Sentences->find()->count())
        );
        $this->assertOutputContains('8 rows changed');

        $hash = $this->Sentences->get(3)->hash;
        $modified = $this->Sentences->get(3)->modified;
        $this->assertEquals("2hfhma4\0\0\0\0\0\0\0\0\0", $hash);
        $this->assertEquals("2014-04-15 00:33:18", $modified);
{'fraction_non_alphanumeric': 0.1470322386260922, 'fraction_numerical': 0.019282916541126845, 'mean_word_length': 3.043848964677223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '4619304', 'n_tokens_mistral': 1049, 'n_tokens_neox': 991, 'n_words': 171}