Your tests should be able to run under 5 seconds! SQLite would be a good solution for that ;)
phpunit really slow with mysql. Tried sqlite. Throws null errors on migration/saving
Completely new to testing.
My production db is on MariaDB and locally I'm using MySQL on Homestead.
I've written a few very basic tests following tutorials to get started, connecting to a local mysql db.
However have noticed that to run these tests it literally takes 45 seconds. I've read that sqlite is a lot faster but is 45 seconds what you would expect for the below tests with mysql?
These are my tests. Some of them are probably a bit stupid but I'm learning ;)
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class PagesTest extends TestCase
{
/** @test */
function browse_main_pages_to_artist_profile()
{
$this->visit('/')
->see('Home')
->click('Inspiration Board')
->see('Need some inspiration?')
->click('Browse Artists')
->see('Search for')
->select('berkshire', 'location')
->press('SEARCH')
->see('Artists In Berkshire')
->click('VIEW PROFILE')
->see('Contact Artist');
}
/** @test */
function footer_pages()
{
$this->visit('/')
->click('SIGN UP')
->see('Request availability')
->click('LOGIN')
->see('Login')
->click('FAQs')
->see('FAQs')
->click('JOIN US')
->see('Artist Registration')
->click('OUR MISSION')
->see('Our Mission')
->click('TERMS OF USE')
->see('Terms of Use')
->click('PRIVACY POLICY')
->see('Privacy Policy')
->click('COOKIE POLICY')
->see('Use of Cookies')
->click('CONTACT US')
->see('Contact us');
}
}
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\User;
class ProfessionalRegistrationTest extends TestCase
{
/** @test */
function a_user_fills_out_the_application_form_and_gets_a_success_message()
{
$email = str_random(10) . '@test-professional.com';
$this->visit('/professional-registration')
->type('Ralph', 'first_name')
->type('Morr', 'last_name')
->type($email, 'email')
->type($email, 'email_confirmation')
->type('Ralphs Business name', 'business_name')
->type('qqqqqqQ1', 'password')
->type('qqqqqqQ1', 'password_confirmation')
->select('1', 'insurance')
->select('1', 'services')
->type('Example postal code', 'postal_code')
->type('some town', 'town')
->type('Hampshire', 'county')
->select('1', 'locations')
->type('5', 'years_experience')
->type('www.google.com', 'website')
->type('ralphyinsta', 'instagram_username')
->check('accept_terms')
->press('Sign Up')
->see('Email confirmation sent!');
}
/** @test */
function a_professional_confirms_their_email_address()
{
$user = User::orderBy('created_at', 'desc')->first();
$this->visit(route('professional.registration.confirm', $user->confirmation_code))
->see('Thanks for confirming!');
}
}
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\User;
class BrideSignUpTest extends TestCase
{
/** @test */
function a_bride_fills_out_the_enquiry_form_on_the_home_page()
{
$email = str_random(10) . '@test-bride.com';
$input = [
'first_name' => 'Lucy',
'last_name' => 'Bradd',
'email' => $email,
'email_confirmation' => $email,
'client[job][wedding_date]' => '25-12-2020',
'client[job][location_id]' => '3',
'client[job][bride_makeup]' => 1,
'client[job][bride_hair]' => 1,
'client[job][bridesmaids_makeup]' => 1,
'client[job][bridesmaids_hair]' => 1,
'client[job][mothers_of_hair]' => 0,
'client[job][mothers_of_makeup]' => 0,
'client[job][flower_girls_makeup]' => 0,
'client[job][flower_girls_hair]' => 0
];
$this->visit('/')
->submitForm('Send now!', $input)
->see('Set your password!');
}
/** @test */
function a_bride_then_confirms_their_email_address()
{
$user = User::orderBy('created_at', 'desc')->first();
$this->visit(route('client-dashboard.confirm', $user->confirmation_code))
->see('Your enquiry has been sent!');
}
}
One thing I've also noticed is that emails are getting sent out when I run the test even though I don't have my queue worker running locally when running the tests which is kinda cool! But probably slowing down things?
Lastly, I tried using sqlite for test but got loads of errors with the migrations to do with making all fields nullable when adding to an existing table. I added nullable to get around this but then got syntax errors on the below method even this works fine with mysql. Just wondering if maintaining two database types is going to be more of a pain than it's worth?
public function makeUniqueSlug($slug)
{
$slug = str_slug($slug, '-');
$count = Professional::whereRaw("slug RLIKE '^{$slug}(-[0-9]+)?$'")->count();
return $count ? "{$slug}-{$count}" : $slug;
}
Appreciate any advice!
Please or to participate in this conversation.