HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/tests/Unit/MyAccountTest.php
<?php

namespace Tests\Unit;

use App\Addresses\Models\Address;
use App\MyAccount\MyAccountController;
use App\Users\SiteUser;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Http\Response;
use Tests\TestCase;

class MyAccountTest extends TestCase
{
    use DatabaseTransactions; //Automatically rolls back database actions after tests

    /**
     * @group MyAccount
     * @test
     */
    public function customerCreationTest()
    {
        //This test actually is a feature test. Since the register controller does not use services, we cannot hook into them in such services.
        //Hooking into services etc is considered to be unit testing. Posting to urls etc is considered to be feature testing.
        //Unit tests tend to break less often then feature tests

        /** @var SiteUser $user */
        $user = factory(SiteUser::class)->make();
        $address = factory(Address::class)->make();
        $password = '1l1k37r41n5';

        $this->assertDatabaseMissing((new SiteUser())->getTable(), [
            'email' => $user->email,
        ]);

        $response = $this->post(route('site.register'), [
            'first_name' => $user->first_name,
            'last_name' => $user->last_name,
            'last_name_prefix' => $user->last_name_prefix,
            'email' => $user->email,
            'phone' => $user->telephone,
            'street' => $address->street,
            'house_number' => $address->house_number,
            'postal_code' => $address->postal_code,
            'city' => $address->city,
            'country' => $address->country_iso3,
            'password' => $password,
            'password_confirmation' => $password,
            'accept_legal' => true
        ]);

        $this->assertEquals(Response::HTTP_FOUND, $response->status());

        $this->assertDatabaseHas('site_users', [
            'email' => $user->email,
        ]);
    }
}