thirteen/testing

Testing library for Laravel 5

This package's canonical repository appears to be gone and the package has been frozen as a result.

0.2.15 2015-09-13 03:23 UTC

README

Laravel Test Cases is a compilation of traits and test cases to make it manageable to test Models and Repositories.

Installation

Install Composer Dependency

composer require "thirteen/testing:0.2.*" --dev

Install the Service Provider in your config/app.php

Thirteen\Testing\TestingServiceProvider::class

Testing Models

To test models, you can just add the ModelAssertionsTrait in your class.

use App\User;
use Thirteen\Testing\ModelAssertionsTrait;

class UserTest extends TestCase
{
    /** @test **/
    function it_has_many_posts()
    {
        $this->assertHasMany((new User)->posts(), App\Post::class);
    }
}

Assertions

  • assertBelongsTo($relationship, $class, $foreignKey = null);
  • assertBelongsToMany($relationship, $class, $table = null, $foreignKey = null);
  • assertHasMany($relationship, $class, $foreignKey = null);
  • assertHasOne($relationship, $class, $foreignKey = null);

Testing Repositories

I don't really recommend using this since it just extends tests from the repository test case.

If you really want to test all your repository methods then by all means.

use App\User;
use Thirteen\Testing\EloquentRepositoryTestCase;

class UserRepositoryTest extends EloquentRepositoryTestCase
{
    public function repository() {
        return App\Repositories\UserRepository::class;
    }

    public function create() {
        return ['full_name' => 'Jake the Dog'];
    }

    public function update() {
        return ['name' => 'Finn the Human'];
    }
}

Issues

  • I can't seem to make the @before function trait work.