Skip to content

Commit

Permalink
✅ Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfachLeo committed Jun 26, 2024
1 parent ed251f3 commit 1b7b6e2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 5 deletions.
50 changes: 50 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

it('contains only strings in check config', function () {
foreach (config('audit.checks') as $check) {
expect($check)->toBeString();
}
});

it('contains only checks with execute functions', function () {
foreach (config('audit.checks') as $check) {
$instance = app()->make($check);
expect(get_class($instance))
->toHaveMethod('execute');
}
});

it('contains checks with different names', function () {
foreach (config('audit.checks') as $check) {
$instance = app()->make($check);
expect($instance->execute())->toBeInstanceOf(\Hexafuchs\Audit\Checks\CheckResult::class);
}
});

it('contains no null values', function () {
foreach (config('audit.checks') as $check) {
$instance = app()->make($check);
expect($instance->getName())->not->toBeEmpty()
->and($instance->getGroup())->not->toBeEmpty()
->and($instance->getError())->not->toBeEmpty();
}
});

it('contains different names', function () {
$names = [];
foreach (config('audit.checks') as $check) {
$instance = app()->make($check);
$names[] = $instance->getName();
}
expect(sizeof($names))->toBe(sizeof(array_unique($names)));
});

it('contains different errors', function () {
$errors = [];
foreach (config('audit.checks') as $check) {
$instance = app()->make($check);
$errors[] = $instance->getError()->message;
}

expect(sizeof($errors))->toBe(sizeof(array_unique($errors)));
});
5 changes: 0 additions & 5 deletions tests/ExampleTest.php

This file was deleted.

31 changes: 31 additions & 0 deletions tests/ResultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Hexafuchs\Audit\Facades\Audit;

it('returns check results', function () {
$result = Audit::run();

expect($result->doesntContain(fn ($e) => !($e instanceof \Hexafuchs\Audit\Checks\CheckResult)))->toBeTrue();
});

it('contains enough results', function () {
$result = Audit::run();

expect($result->count() === sizeof(config('audit.checks')))->toBeTrue();
});

it('contains no null group names', function () {
$result = Audit::run();

expect($result->map(fn ($e) => $e->group)->doesntContain(fn ($e) => $e === null))->toBeTrue();
});


it('contains unique names', function () {
$result = Audit::run();
$names = $result->map(fn ($e) => $e->name);

expect($names->count() === $names->unique()->count())->toBeTrue();
});


0 comments on commit 1b7b6e2

Please sign in to comment.