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

[V3] Return null on IntSynth when null is passed in #6478

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Mechanisms/HandleComponents/Synthesizers/IntSynth.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static function matchByType($type) {
}

static function hydrateFromType($type, $value) {
if ($value === '') return null;
if ($value === '' || $value === null) return null;

return (int) $value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Livewire\Mechanisms\HandleComponents\Synthesizers\Tests;

use Livewire\Component;
use Livewire\Livewire;

class IntSynthUnitTest extends \Tests\TestCase
{
/**
* @test
*/
public function null_value_hydrated_returns_null()
{
Livewire::test(ComponentWithNullableInt::class)
->set('intField', null)
->assertSet('intField', null, true); // Use strict mode
}
}

class ComponentWithNullableInt extends Component
{
public ?int $intField = null;


public function render()
{
return view('null-view');
}
}