Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial tests for Form module #3

Merged
merged 7 commits into from
Sep 21, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use pest syntax for tests
  • Loading branch information
toddy15 committed Sep 19, 2022
commit cc1e4bec74112b1f3abb1365ffb38471e88c32a0
16 changes: 8 additions & 8 deletions tests/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
use Leaf\Form;

it("supports 11 default rules", function () {
$rules = Form::supportedRules();
expect($rules)->toBeArray();
expect(count($rules))->toBe(11);
expect(Form::supportedRules())
->toBeArray()
->toHaveCount(11);
});

it("has some known default rules", function () {
$rules = Form::supportedRules();
expect(in_array('required', $rules))->toBe(true);
expect(in_array('email', $rules))->toBe(true);
expect(Form::supportedRules())
->toContain('required')
->toContain('email');
});

it("can add a custom rule", function () {
$rules = Form::supportedRules();
$rules_count = count($rules);
expect(in_array('custom_equal_rule', $rules))->toBe(false);
expect($rules)->not()->toContain('custom_equal_rule');

Form::rule("custom_equal_rule", function ($field, $value, $params) {
return $value == $params;
});

$rules = Form::supportedRules();
$new_rules_count = count($rules);
expect(in_array('custom_equal_rule', $rules))->toBe(true);
expect($rules)->toContain('custom_equal_rule');
expect($new_rules_count)->toBe($rules_count + 1);
});

Expand Down