Issue with basic assertSet() following upgrade to v2

What seems to be the problem:

I’ve upgraded to the latest Livewire (v1 to v2). The site works as expected in the browser and all looks good. However, my tests are failing for a reason they should not be. Very basic assertions of default component values are failing with

Failed asserting that null is true.

Steps to Reproduce:

I have a simple Livewire Component that has a public property $type that is set to ‘info’ as a default.

If I run the following basic test, I get the above error:

                ->assertSet('type', 'info');

However, if I change the test as follows:

$comp = Livewire::test('users.send-notification-all');
$this->assertTrue($comp->type === 'info');


$comp = Livewire::test('users.send-notification-all');
$this->assertEquals('info', $comp->get('type'));

The test passes.

Also if I change as per upgrade guide:

                ->assertPayloadSet('type', 'info');

I still get the failure.

When it fails I don’t get any errors in my logs and as mentioned above the component works as expected in the browser. Any idea where to start in debugging this? I’m running Laravel v8.8.0, PHP 7.3.11.

Are you using the latest version of Livewire: Yes

Do you have any screenshots or code examples:

Just out of curiosity I updated my test to:

                ->assertNotSet('type', 'info');

And bizarrely I get the following failure!!

Failed asserting that ‘info’ is not equal to ‘info’.

And also:

                ->assertSet('type', 'not info');

I get:

Failed asserting that two strings are equal.
Expected :‘not info’
Actual :‘info’

Any ideas?

This issue keeps getting weirder.

If I update my Livewire component so that $type defaults to ‘information’

and then update my test to be:

                ->assertSet('type', 'information');

The test passes, what am I missing?

After sleeping on this I believe I have realised the root of the issue. I want to check that $type has a string value of 'info'. However, because there is a function of the same name info(), this is being called by the assertSet() function and info() returns null

If I check in the logs I am also getting the following entry:

[2020-10-12 07:06:35] testing.INFO: info

I will investigate further and try to raise a PR with a fix later this morning.

Submitted PR 1802