-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnitsRepositoryTest.php
70 lines (62 loc) · 1.93 KB
/
UnitsRepositoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
use App\Models\Units;
use App\Repositories\UnitsRepository;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class UnitsRepositoryTest extends TestCase
{
use MakeUnitsTrait, ApiTestTrait, DatabaseTransactions;
/**
* @var UnitsRepository
*/
protected $unitsRepo;
public function setUp()
{
parent::setUp();
$this->unitsRepo = App::make(UnitsRepository::class);
}
/**
* @test create
*/
public function testCreateUnits()
{
$units = $this->fakeUnitsData();
$createdUnits = $this->unitsRepo->create($units);
$createdUnits = $createdUnits->toArray();
$this->assertArrayHasKey('id', $createdUnits);
$this->assertNotNull($createdUnits['id'], 'Created Units must have id specified');
$this->assertNotNull(Units::find($createdUnits['id']), 'Units with given id must be in DB');
$this->assertModelData($units, $createdUnits);
}
/**
* @test read
*/
public function testReadUnits()
{
$units = $this->makeUnits();
$dbUnits = $this->unitsRepo->find($units->id);
$dbUnits = $dbUnits->toArray();
$this->assertModelData($units->toArray(), $dbUnits);
}
/**
* @test update
*/
public function testUpdateUnits()
{
$units = $this->makeUnits();
$fakeUnits = $this->fakeUnitsData();
$updatedUnits = $this->unitsRepo->update($fakeUnits, $units->id);
$this->assertModelData($fakeUnits, $updatedUnits->toArray());
$dbUnits = $this->unitsRepo->find($units->id);
$this->assertModelData($fakeUnits, $dbUnits->toArray());
}
/**
* @test delete
*/
public function testDeleteUnits()
{
$units = $this->makeUnits();
$resp = $this->unitsRepo->delete($units->id);
$this->assertTrue($resp);
$this->assertNull(Units::find($units->id), 'Units should not exist in DB');
}
}