2017 © Pedro Peláez
 

library laravel-relationship-test

Enhance the unit test of relationship in model to projects in laravel

image

fs-ap/laravel-relationship-test

Enhance the unit test of relationship in model to projects in laravel

  • Tuesday, April 26, 2016
  • by Edilton
  • Repository
  • 1 Watchers
  • 4 Stars
  • 58 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

# Fs-ap/Laravel-relationship-test

Enhance the unit test of relationship in model to projects in laravel, (*1)

Composer Installation

{

  "require-dev": {
    "fs-ap/laravel-relationship-test": "~1.0"
  }
}

Or, (*2)

Through terminal: composer require --dev fs-ap/laravel-relationship-test:~1.0, (*3)

Usage

<?php

use Fs\Relationship;

    class AuthorModelTest extends PHPUnit_Framework_TestCase {

        /**
         * Check if the class in first param has a method that defines relation of type Relationship::HAS_MANY
         * and the second class has a relation of type Relationship::BELONGS_TO
         */
        public function testAuthorCanHaveManyComments()
        {
            Relationship::check(Author::class, Relationship::HAS_MANY, Comment::class));
        }
    }

Explain

This feature checks bidirectional relation between models through of @return annotations on method that defines the relation, (*4)

<?php

    class Author extends Illuminate\Database\Eloquent\Model {

        /**
        * @return Illuminate\Database\Eloquent\Relations\HasMany
        */
        public function comments() { return \$this->hasMany(Comment::class); }
    }

And, (*5)

<?php

    class Comment extends Illuminate\Database\Eloquent\Model {

        /**
        * @return Illuminate\Database\Eloquent\Relations\BelongsTo
        */
        public function author() { return \$this->belongsTo(Author::class); }
    }

Map of bidirectional check

Relation Mapped to
Relationship::HAS_MANY Relationship::BELONGS_TO
Relationship::BELONGS_TO Relationship::HAS_MANY
Relationship::HAS_ONE Relationship::HAS_ONE

Disable bidirectional check

<?php

Relationship::check(Author::class, Relationship::HAS_MANY, Comment::class, true);

This checks only if the Author has many Comment independent if the relation has defined in Comment class, (*6)

The Versions

26/04 2016

dev-master

9999999-dev

Enhance the unit test of relationship in model to projects in laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

22/04 2016

1.0

1.0.0.0

Enhance the unit test of relationship in model to projects in laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

22/04 2016

1.1

1.1.0.0

Enhance the unit test of relationship in model to projects in laravel

  Sources   Download

MIT

The Requires

 

The Development Requires