<commit_before><?php

namespace Quibble\Tests;

use Quibble\Sqlite\Adapter;
use Quibble\Query\DeleteException;
use Quibble\Query\Buildable;
use PDO;

/**
 * Deletion
 */
class DeleteTest
{
    public function __wakeup()
    {
        $this->pdo = new class(':memory:') extends Adapter {
            use Buildable;
        };
        $this->pdo->exec(<<<EOT
DROP TABLE IF EXISTS test;
CREATE TABLE test (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    foo VARCHAR(255) NOT NULL
);
INSERT INTO test (foo) VALUES ('bar'), ('baz'), ('buzz');

EOT
        );
    }

    /**
     * delete should delete a row {?}
     */
    public function testDelete()
    {
        $res = $this->pdo->deleteFrom('test')
            ->where(['id' => 1])
            ->execute();
        yield assert($res === true);
    }
    
    /**
     * delete should return false if nothing was deleted {?}
     */
    public function testNoDelete(Adapter &$db = null)
    {
        $res = $this->pdo->deleteFrom('test')
            ->where(['id' => 12345])
            ->execute();
        yield assert($res === false);
    }
    
    /**
     * delete should throw an exception if nothing was deleted {?}
     */
    public function testNoDeleteWithException(Adapter &$db = null)
    {
        $e = null;
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        try {
            $this->pdo->deleteFrom('test')
                ->where(['id' => 12345])
                ->execute();
        } catch (DeleteException $e) {
        }
        yield assert($e instanceof DeleteException);
    }
}
<commit_msg>fix delete test<commit_after><?php

namespace Quibble\Tests;

use Quibble\Sqlite\Adapter;
use Quibble\Query\DeleteException;
use Quibble\Query\Buildable;
use PDO;

/**
 * Deletion
 */
class DeleteTest
{
    public function __wakeup()
    {
        $this->pdo = new class(':memory:') extends Adapter {
            use Buildable;
        };
        $this->pdo->exec(<<<EOT
DROP TABLE IF EXISTS test;
CREATE TABLE test (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    foo VARCHAR(255) NOT NULL
);
INSERT INTO test (foo) VALUES ('bar'), ('baz'), ('buzz');

EOT
        );
    }

    /**
     * delete should delete a row {?}
     */
    public function testDelete()
    {
        $res = $this->pdo->deleteFrom('test')
            ->where('id = ?', 1)
            ->execute();
        yield assert($res === true);
    }
    
    /**
     * delete should return false if nothing was deleted {?}
     */
    public function testNoDelete()
    {
        $res = $this->pdo->deleteFrom('test')
            ->where('id = ?', 12345)
            ->execute();
        yield assert($res === false);
    }
    
    /**
     * delete should throw an exception if nothing was deleted {?}
     */
    public function testNoDeleteWithException()
    {
        $e = null;
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        try {
            $this->pdo->deleteFrom('test')
                ->where('id = ?', 12345)
                ->execute();
        } catch (DeleteException $e) {
        }
        yield assert($e instanceof DeleteException);
    }
}

{'fraction_non_alphanumeric': 0.1488621997471555, 'fraction_numerical': 0.008849557522123894, 'mean_word_length': 2.008555133079848, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 40, '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': '6160682', 'n_tokens_mistral': 1010, 'n_tokens_neox': 965, 'n_words': 234}