GrypeSpdxTest.php
1 <?php 2 3 namespace Tests\Unit\Jobs; 4 5 use App\Jobs\GrypeSpdx; 6 use App\Models\TOE; 7 use App\Models\User; 8 use App\Models\Vulnerability; 9 use Tests\TestCase; 10 11 class GrypeSpdxTest extends TestCase 12 { 13 public string $path = 'test_files/toe.spdx'; 14 public TOE $toe; 15 public User $cto; 16 17 public function setUp(): void 18 { 19 parent::setUp(); 20 $this->toe = TOE::factory()->create(['spdx_path' => $this->path]); 21 $this->cto = User::factory([ 22 'username' => 'CTO01', 23 'email' => 'cto@csgoc.eu', 24 ])->create(); 25 $this->cto->assignRole('technical_manager'); 26 $this->cto->notifications()->delete(); 27 } 28 29 public function test_creates_vulnerabilities() 30 { 31 $grype = new GrypeSpdx(collect([$this->toe])); 32 $grype->handle(); 33 34 $this->assertTrue(Vulnerability::count() > 0); 35 $this->assertDatabaseHas('toe_vulnerability', [ 36 'toe_id' => $this->toe->id, 37 'vulnerability_id' => Vulnerability::first()->id, 38 'applies' => 0, 39 ]); 40 $this->assertCount(1, $this->cto->notifications); 41 } 42 }