nothingworksinc / ticketbeast

Back to the lesson videos:
https://course.testdrivenlaravel.com/lessons
552 stars 11 forks source link

Search #82

Open vpratfr opened 6 years ago

vpratfr commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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.');
            }
        });