Skip to content
New issue

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

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

Already on GitHub? # to your account

Added support for Laravel 7 custom casts #913

Merged
merged 5 commits into from
Apr 22, 2020
Merged

Added support for Laravel 7 custom casts #913

merged 5 commits into from
Apr 22, 2020

Conversation

belamov
Copy link
Contributor

@belamov belamov commented Apr 11, 2020

this pr adresses #904

the idea of improvement is simple:

now we get cast object as property's return type

we just check if this cast object implements laravel's Illuminate\Contracts\Database\Eloquent\CastsAttributes interface and if so then we return it's get method return type

just had one problem with this: if return type of get metod is not defined, but it has @returns tag, then returned type is not namespaced properly. i couldn't find a way to provide necessary context to DocBlock object. if anyone knows how to do it, that would be really cool to implement

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just had one problem with this: if return type of get metod is not defined, but it has @returns tag, then returned type is not namespaced properly. i couldn't find a way to provide necessary context to DocBlock object. if anyone knows how to do it, that would be really cool to implement

The whole library has this limitations on get*Attribute methods so IMHO nothing which needs to be fixed specifically for this feature (but sure, a general solution would be "nice").

I like the PR, implementation LGTM and 👍 for tests!!


$this->assertSame(0, $tester->getStatusCode());
$this->assertEmpty($tester->getDisplay());
//dd($actualContent);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug stuff 💥

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix


if (version_compare(Application::VERSION, '7.0', '<')) {
$this->markTestSkipped('This test requires Laravel 7.0 or higher');
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, markTestSkipped works through exception bubbling

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found it only in AbstractModelsCommand but it checks for 6 version

if (version_compare(Application::VERSION, '6.0', '<')) {
      $this->markTestSkipped('This test requires Laravel 6.0 or higher');
      return;
}

are you sure i can safely remove it? where is this exception debugging you are talking about?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

markTestSkipped throws a special exception recognized by PHPUnit, that's why a return (read: code afterwards) doesn't execute => https://github.com/sebastianbergmann/phpunit/blob/cb6b2d8cb5865b9576adcd9c595a8b4d005361b3/src/Framework/Assert.php#L2645-L2655

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah but to be honest, i cant see why i can drop this code
parent class check for 6 version, but my test should run only in 7

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can/should be removed in the parent as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, but i don't follow why
travis runs test on multiple laravel versions, how else this test would be skipped without this code?

Copy link
Contributor Author

@belamov belamov Apr 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, you talking only about line 20, we can remove return statement, agreed, thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly; apologies for being not more specific upfront!

@belamov belamov marked this pull request as draft April 11, 2020 14:52
@belamov
Copy link
Contributor Author

belamov commented Apr 12, 2020

refactored tests and added some additional test cases
thanks @mfn for review!

@belamov belamov marked this pull request as ready for review April 12, 2020 13:59
Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing more to add, awesome; hope @barryvdh soon finds time for this!

@barryvdh
Copy link
Owner

Thanks! Unfortunately this has merge conflicts. Would it be possible to fix those, then I'll merge this.

@belamov
Copy link
Contributor Author

belamov commented Apr 22, 2020

done, replaced my code with @mfn's

@barryvdh barryvdh merged commit cfa9a81 into barryvdh:master Apr 22, 2020
@barryvdh
Copy link
Owner

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants