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

Search #82

Open
vpratfr opened this issue Mar 2, 2018 · 3 comments
Open

Search #82

vpratfr opened this issue Mar 2, 2018 · 3 comments

Comments

@vpratfr
Copy link
Collaborator

vpratfr commented Mar 2, 2018

Hey Adam,

I was wondering if there is any way to search for content.

Today I found myself being hit by "Failed asserting that two objects are equal." with the reason being that the models differ only by their attribute "wasRecentlyCreated".

I know I have seen this in one of the chapters quite some time ago, but no way to find it again :(

Would be nice to get some kind of way to search for text (maybe search inside a generated transcript of the videos).

Code is like that:

$response->assertViewHas('mission', $mission); with $mission being the said model which differs only by this attribute.

@drbyte
Copy link
Collaborator

drbyte commented Mar 2, 2018

@vpratfr wrote:

I know I have seen this in one of the chapters quite some time ago, but no way to find it again :(

I think you're referring to lessons 26 ("4.1") and 27 ("4.2"), and perhaps some related callbacks to lessons 48 and 71?

@nathanheffley
Copy link
Collaborator

Just in case you weren't able to find what you were looking for, you should be able to fix your issue by getting a fresh version of the $mission.

$response->assertViewHas('mission', $mission->fresh());

@vpratfr
Copy link
Collaborator Author

vpratfr commented Mar 12, 2018

Yeah, I found out after a while.

Solved that by macroing the TestResponse class:

    TestResponse::macro('assertViewHasModel',
        function ($key, Model $model) {
            /** @noinspection PhpUndefinedMethodInspection */
            $this->assertViewHas($key);
            if ($model !== null)
            {
                /** @noinspection PhpUndefinedFieldInspection */
                Assert::assertTrue($model->is($this->original->getData()[$key]),
                    'Failed asserting that the view contains the specified model.');
            }
        });

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

No branches or pull requests

3 participants