sauravs012
1 month ago
227
3
Laravel

PHP Unit Testing

Posted 1 month ago by sauravs012

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' => 'j[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);
    }
}

Please sign in or create an account to participate in this conversation.