Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomano committed Dec 4, 2024
1 parent f5cab8c commit 99668b6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 6 deletions.
25 changes: 21 additions & 4 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
Config::$sourcedir = __DIR__ . DIRECTORY_SEPARATOR . 'files';

Utils::$context['css_header'] = [];

Utils::$context['javascript_inline'] = ['defer' => [], 'standard' => []];
Utils::$context['num_errors'] = 0;

Utils::$smcFunc['htmlspecialchars'] = fn(...$params) => htmlspecialchars(...$params);

Utils::$smcFunc['db_query'] = fn(...$params) => new \stdClass();
Utils::$smcFunc['db_fetch_row'] = fn(...$params) => [];
Utils::$smcFunc['db_fetch_assoc'] = fn(...$params) => [];
Expand All @@ -33,8 +32,17 @@
Utils::$smcFunc['db_transaction'] = fn(...$params) => true;
Utils::$smcFunc['db_optimize_table'] = fn(...$params) => 0;
Utils::$smcFunc['db_list_tables'] = fn(...$params) => [];
Utils::$smcFunc['db_get_version'] = fn(...$params) => '';
Utils::$smcFunc['db_create_table'] = fn(...$params) => false;
Utils::$smcFunc['db_get_version'] = fn() => '';
Utils::$smcFunc['db_get_vendor'] = fn() => '';
Utils::$smcFunc['db_add_column'] = fn(...$params) => true;
Utils::$smcFunc['db_add_index'] = fn(...$params) => true;
Utils::$smcFunc['db_change_column'] = fn(...$params) => true;
Utils::$smcFunc['db_create_table'] = fn(...$params) => true;
Utils::$smcFunc['db_table_structure'] = fn(...$params) => [];
Utils::$smcFunc['db_list_columns'] = fn(...$params) => [];
Utils::$smcFunc['db_list_indexes'] = fn(...$params) => [];
Utils::$smcFunc['db_remove_column'] = fn(...$params) => true;
Utils::$smcFunc['db_remove_index'] = fn(...$params) => true;
})->in(__DIR__);

/*
Expand Down Expand Up @@ -243,10 +251,19 @@ function fatal_lang_error(...$params): void
if (! function_exists('log_error')) {
function log_error(...$params): string
{
Utils::$context['num_errors']++;

return '';
}
}

if (! function_exists('display_db_error')) {
function display_db_error(): void
{
echo '<h3>Connection Problems</h3>';
}
}

if (! function_exists('call_integration_hook')) {
function call_integration_hook(string $hook, array $args = []): array
{
Expand Down
59 changes: 57 additions & 2 deletions tests/Unit/DbFuncMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,67 @@
->toBeString();
});

test('get_vendor method', function () {
expect($this->db->get_vendor())
->toBeString();
});

test('add_column method', function () {
expect($this->db->add_column('', []))
->toBeTrue();
});

test('add_index method', function () {
expect($this->db->add_index('', []))
->toBeTrue();
});

test('change_column method', function () {
expect($this->db->change_column('', '', []))
->toBeTrue();
});

test('create_table method', function () {
expect($this->db->create_table('', []))
->toBeFalse();
->toBeTrue();
});

test('table_structure method', function () {
expect($this->db->table_structure('name'))
->toBeArray();
});

test('list_columns method', function () {
expect($this->db->list_columns('name'))
->toBeArray();
});

test('list_indexes method', function () {
expect($this->db->list_indexes('name'))
->toBeArray();
});

test('remove_column method', function () {
expect($this->db->remove_column('', ''))
->toBeTrue();
});

test('remove_index method', function () {
expect($this->db->remove_index('', ''))
->toBeTrue();
});

test('__call not implemented method', function () {
Utils::$smcFunc['db_some_func'] = fn(...$params) => [$params];

expect(Utils::$context['num_errors'])->toBe(0);

$this->db->some_func($this->params);

expect(Utils::$context['num_errors'])->toBe(1);
});

test('__call method', function () {
test('__call unknown method', function () {
expect($this->db->unknown($this->params))
->toBeFalse();
});
8 changes: 8 additions & 0 deletions tests/Unit/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@
test('log method', function () {
expect(ErrorHandler::log('test'))->toBeString();
});

test('displayDbError method', function () {
ob_start();
ErrorHandler::displayDbError();
$result = ob_get_clean();

expect($result)->toContain('Connection Problems');
});

0 comments on commit 99668b6

Please sign in to comment.