/ tests / Feature / Models / VulnerabilityTest.php
VulnerabilityTest.php
 1  <?php
 2  
 3  namespace Tests\Feature\Models;
 4  
 5  use App\Models\TOE;
 6  use App\Models\Vulnerability;
 7  use Tests\TestCase;
 8  
 9  class VulnerabilityTest extends TestCase
10  {
11      public function test_toe_attach_vulnerability()
12      {
13          $vulnerability = Vulnerability::factory()->create();
14          $toe = TOE::factory()->create();
15  
16          $toe->vulnerabilities()->attach($vulnerability);
17  
18          $this->assertDatabaseHas('toe_vulnerability', [
19              'toe_id' => $toe->id,
20              'vulnerability_id' => $vulnerability->id,
21              'applies' => 0,
22          ]);
23          $this->assertCount(1, $toe->vulnerabilities);
24          $this->assertCount(1, $vulnerability->toes);
25          $this->assertEquals($toe->id, $vulnerability->toes->first()->id);
26          $this->assertEquals($vulnerability->id, $toe->vulnerabilities->first()->id);
27      }
28  }