Skip to content

Commit

Permalink
Added wire:model.boolean as an option to assertPropertyWired and asse…
Browse files Browse the repository at this point in the history
…rtPropertyNotWired (#38)

* added an extra assertions test to check for boolean, added boolean into the CustomLivewireAssertionsMixin.php after the blur entry, and additional line to test-componet-a

* Fix styling

---------

Co-authored-by: Christoph Rumpel <christoph@christoph-rumpel.com>
  • Loading branch information
pikepa and christophrumpel committed Apr 11, 2024
1 parent 20493cf commit 3075093
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.cache
@@ -1 +1,2 @@
{"php":"8.3.4","version":"3.53.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"const":"one","method":"one","property":"one"}},"single_trait_insert_per_statement":true},"hashes":{"src\/CustomLivewireAssertionsMixin.php":"0af451faed1cc2a92aad855976006161","src\/ComponentName.php":"af0dc94880495710238f36e09974f56b","src\/MissingLivewireAssertionsServiceProvider.php":"001e0571136e8126eb93c4ddb1bbb53a","tests\/resources\/views\/livewire-test-component-b.php":"ab1e1d7326d9e0a269a84c239503d679","tests\/resources\/views\/blade-test-component.php":"4b61e7dba267eb48b3fa25a14e0d086b","tests\/resources\/views\/livewire-test-component-a.php":"2ba62faed184d61a5eae8d52def8eb10","tests\/resources\/views\/livewire-test-component-d.php":"5316f158439e7e01c467a5ac16508dd1","tests\/resources\/views\/livewire-test-component-c.php":"b91a9c12dd35893f20ffc42f92bfb68e","tests\/AssertionsTest.php":"5ed1b02e461e7860486c1b7bf247bf0a","tests\/Components\/LivewireTestComponentD.php":"a0a14bddb133c4a7e971b6d3c31d3d0e","tests\/Components\/LivewireTestComponentC.php":"d516104cd3b4eb72826b8a3eef9246fd","tests\/Components\/LivewireTestComponentA.php":"2306729210f9134b92a46d05c71dc566","tests\/Components\/FileDownloadComponent.php":"92f6b79d4253193dc1503a0d84d6ac7e","tests\/Components\/LivewireTestComponentB.php":"7ef74a34799d9cc730a738f40eeb2b40","tests\/TestCase.php":"3e2e658dc76516b56f2c8f83c770cf97","tests\/View\/Components\/Button.php":"ed586764f2469ec4b6a76d0f0d96f6ba"}}
{"php":"8.3.4","version":"3.53.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"const":"one","method":"one","property":"one"}},"single_trait_insert_per_statement":true},"hashes":{"src\/CustomLivewireAssertionsMixin.php":"ab5d5d4a61b0355151090ce647092102","src\/ComponentName.php":"af0dc94880495710238f36e09974f56b","src\/MissingLivewireAssertionsServiceProvider.php":"001e0571136e8126eb93c4ddb1bbb53a","tests\/resources\/views\/livewire-test-component-b.php":"ab1e1d7326d9e0a269a84c239503d679","tests\/resources\/views\/blade-test-component.php":"4b61e7dba267eb48b3fa25a14e0d086b","tests\/resources\/views\/livewire-test-component-a.php":"3b67f76d466d9c252eb3116c5d754d52","tests\/resources\/views\/livewire-test-component-d.php":"5316f158439e7e01c467a5ac16508dd1","tests\/resources\/views\/livewire-test-component-c.php":"b91a9c12dd35893f20ffc42f92bfb68e","tests\/AssertionsTest.php":"1292aaa3fcfb235d81ee35d01e9bf830","tests\/Components\/LivewireTestComponentD.php":"a0a14bddb133c4a7e971b6d3c31d3d0e","tests\/Components\/LivewireTestComponentC.php":"d516104cd3b4eb72826b8a3eef9246fd","tests\/Components\/LivewireTestComponentA.php":"2306729210f9134b92a46d05c71dc566","tests\/Components\/FileDownloadComponent.php":"92f6b79d4253193dc1503a0d84d6ac7e","tests\/Components\/LivewireTestComponentB.php":"7ef74a34799d9cc730a738f40eeb2b40","tests\/TestCase.php":"3e2e658dc76516b56f2c8f83c770cf97","tests\/View\/Components\/Button.php":"ed586764f2469ec4b6a76d0f0d96f6ba"}}

4 changes: 2 additions & 2 deletions src/CustomLivewireAssertionsMixin.php
Expand Up @@ -17,7 +17,7 @@ public function assertPropertyWired(): Closure
{
return function (string $property) {
PHPUnit::assertMatchesRegularExpression(
'/wire:model(\.(defer|live|blur|(lazy|debounce)(\.\d+?(ms|s)|)))*=(?<q>"|\')'.$property.'(\k\'q\')/',
'/wire:model(\.(defer|live|blur|boolean|(lazy|debounce)(\.\d+?(ms|s)|)))*=(?<q>"|\')'.$property.'(\k\'q\')/',
$this->html()
);

Expand All @@ -32,7 +32,7 @@ public function assertPropertyNotWired(): Closure
{
return function (string $property) {
PHPUnit::assertDoesNotMatchRegularExpression(
'/wire:model(\.(live|blur|(lazy|debounce)(\.\d+?(ms|s)|)))*=(?<q>"|\')'.$property.'(\k\'q\')/',
'/wire:model(\.(live|blur|boolean|(lazy|debounce)(\.\d+?(ms|s)|)))*=(?<q>"|\')'.$property.'(\k\'q\')/',
$this->html()
);

Expand Down
4 changes: 3 additions & 1 deletion tests/AssertionsTest.php
Expand Up @@ -17,6 +17,7 @@
Livewire::test(LivewireTestComponentA::class)
->assertPropertyWired('user')
->assertPropertyWired('blur')
->assertPropertyWired('boolean')
->assertPropertyWired('defer')
->assertPropertyWired('lazy')
->assertPropertyWired('live')
Expand All @@ -26,10 +27,11 @@
->assertPropertyWired('singlequote');
});

it('checks if Livewire property is not wired toa field', function () {
it('checks if Livewire property is not wired to a field', function () {
Livewire::test(LivewireTestComponentA::class)
->assertPropertyNotWired('user_not_wired')
->assertPropertyNotWired('blur_not_wired')
->assertPropertyNotWired('boolean_not_wired')
->assertPropertyNotWired('lazy_not_wired')
->assertPropertyNotWired('live_not_wired')
->assertPropertyNotWired('defer_not_wired')
Expand Down
1 change: 1 addition & 0 deletions tests/resources/views/livewire-test-component-a.php
@@ -1,6 +1,7 @@
<div>
<input type="text" wire:model="user" />
<input type="text" wire:model.blur="blur" />
<input type="text" wire:model.boolean="boolean" />
<input type="text" wire:model.lazy="lazy" />
<input type="text" wire:model.live="live" />
<input type="text" wire:model.defer="defer" />
Expand Down

0 comments on commit 3075093

Please sign in to comment.