Skip to content

Commit

Permalink
adding unit test for Record
Browse files Browse the repository at this point in the history
  • Loading branch information
terazus committed Feb 17, 2019
1 parent c3f8c4c commit c31795d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

class Record extends Model
{
protected $fillable = [
protected $fillable = [
'name', 'description', 'url'
];

public function get_attributes()
{
return $this->attributes;
}
}
22 changes: 22 additions & 0 deletions tests/Feature/UserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class UserTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function testExample()
{
$response = $this->get('/');

$response->assertStatus(200);
}
}
35 changes: 35 additions & 0 deletions tests/Unit/RecordTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Record;

class RecordTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function testRecords()
{
// Assert that there is 5 records after the seed
$this->assertEquals(5, Record::count());

// Select the first record
$record_1 = Record::find(1)->get_attributes();

//fwrite(STDERR, print_r($record_1));

// Assert is has all the proper attributes
$this->assertEquals(1, $record_1['id']);
$this->assertTrue(array_key_exists('description', $record_1));
$this->assertTrue(array_key_exists('url', $record_1));
$this->assertTrue(array_key_exists('title', $record_1));
$this->assertTrue(array_key_exists('created_at', $record_1));
$this->assertTrue(array_key_exists('updated_at', $record_1));
}
}
20 changes: 20 additions & 0 deletions tests/Unit/UserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class UserTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function testExample()
{
$this->assertTrue(true);
}
}

0 comments on commit c31795d

Please sign in to comment.