0

I have the following test :

class AdminPanelTest extends TestCase
{
    public function photoUpload()
    {
        $user = new App\User;
        $user->username = "testUser";
        $user->email = "[email protected]";
        $user->password = bcrypt("testUser");
        $user->photo_url = "abc.jpg";
        $user->save();

        $test = App\User::where('username','=','testUser');
        $this->assertEquals($test,'testUser');
        $this->assertCount(1,$test);
    }
}

The result says that 'testUser' does not match expected type "object"..

The user is added to the database.

Am I missing something ?

1
  • 1
    yea you are missing the part about how you have to name test methods or use annotations via phpunit. Commented Jun 26, 2016 at 17:50

1 Answer 1

1

Rename your function to begin with "test"

public function testPhotoUpload()

App\User::where('username','=','testUser') is returning an Object, but you're expecting it to return just a username string 'testUser' so it's failing your tests.

I'm unfamiliar with your App\User class, but just guessing from convention, it's probably going to have a property named something like username

In that case, then I would expect your test to pass if you compared those values instead, i.e. the expected string literal 'testUser' and the object property $test->username

Also, assertEquals by convention wants you to put your expected value as the first parameter, and the actual value as the second parameter.

$this->assertEquals('testUser', $test->username);
Sign up to request clarification or add additional context in comments.

1 Comment

Ok yeah i got that one, I have updated the question, Please have a look.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.