55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Entry;
|
|
use App\Models\School;
|
|
use App\Models\Student;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function () {
|
|
$this->school = School::factory()->create();
|
|
$this->student = Student::factory()->create([
|
|
'school_id' => $this->school->id,
|
|
'first_name' => 'Chris',
|
|
'last_name' => 'Tomlin',
|
|
]);
|
|
});
|
|
|
|
it('has a school', function () {
|
|
expect($this->student->school->is($this->school))->toBeTrue()
|
|
->and($this->student->school)->toBeInstanceOf(School::class);
|
|
});
|
|
|
|
it('has users also called directors', function () {
|
|
// Arrange
|
|
$users = User::factory()->count(2)->create([
|
|
'school_id' => $this->school->id,
|
|
]);
|
|
// Act & Assert
|
|
expect($this->student->users->count())->toBe(2)
|
|
->and($this->student->users->first()->is($users->first()))->toBeTrue()
|
|
->and($this->student->directors->count())->toBe(2)
|
|
->and($this->student->directors->first()->is($users->first()))->toBeTrue();
|
|
});
|
|
|
|
it('has entries', function () {
|
|
// Arrange
|
|
$entry = Entry::factory()->create([
|
|
'student_id' => $this->student->id,
|
|
]);
|
|
Entry::factory()->count(4)->create([
|
|
'student_id' => $this->student->id,
|
|
]);
|
|
// Act & Assert
|
|
expect($this->student->entries->count())->toBe(5)
|
|
->and($this->student->entries->first()->is($entry))->toBeTrue()
|
|
->and($this->student->entries->first())->toBeInstanceOf(Entry::class);
|
|
});
|
|
|
|
it('formats a full name and can do it last name first if needed', function () {
|
|
expect($this->student->full_name())->toBe('Chris Tomlin')
|
|
->and($this->student->full_name(true))->toBe('Tomlin, Chris');
|
|
});
|