Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sauravs012's avatar

PHP Unit Testing

Error on vendor/bin/phpunit

There was 1 failure:

1) Tests\Unit\MyTest::testUser
Failed asserting that actual size 0 matches expected size 1.

/laravel/tests/Unit/MyTest.php:37

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

My Code

<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Event;
use Illuminate\Auth\Events\Registered;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Log;

class MyTest extends TestCase {

    use RefreshDatabase;

    public function testUser() {
        //Event::fake();
        // Creating Super Sonic Admin to Add Super Admin
        // Beacuse Middle needs Super Sonic Admin To add Super Admin


		$response = $this->post('register', [
            'first_name' => 'John',
            'last_name' => 'Doe',
            'name' => 'jhon2',
            'email' => '[email protected]',
            'confirm_password' => bcrypt($password = 'i-love-laravel'),
            'password' => bcrypt($password = 'i-love-laravel'),
            'role' => '1',
            'verifiedEmail' => true,
            'dob' => '1990/08/23'
        ]);
        // making super sonic admin
        $user = User::where('name', '=', 'jhon2')->get();
        $this->assertCount(1, $user);
        $this->assertEquals('jhon2', $user[0]->name);
        $this->assertEquals('[email protected]', $user[0]->email);
    }
}
0 likes
3 replies
Sergiu17's avatar
'password' => bcrypt($password = 'i-love-laravel'),

you don't have to send a bcrypted password, Laravel does it for you. Also you could assert that status is 201 I guess

$response = $this->post('register', [ // ..

$response->assertStatus(201); // to make sure that user is created
GeordieJackson's avatar

@sauravs012

Your User details aren't the default fields Laravel uses. Have you set the migration with the new fields properly, and have you changed the validation at all?

It's obviously not storing your user in the database so the problem is most likely with your input data.

sauravs012's avatar
sauravs012
OP
Best Answer
Level 2

There was an migration issue. Some migrations was in my custom package. I've moved all in Laravel migration folder. Thanks all for your valuable time

Please or to participate in this conversation.