Package Data | |
---|---|
Maintainer Username: | Edilton |
Maintainer Contact: | 05.paulotarso@gmail.com (Paulo Silva) |
Package Create Date: | 2016-04-22 |
Package Last Update: | 2016-04-26 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-20 03:02:57 |
Package Statistics | |
---|---|
Total Downloads: | 174 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
==================
Enhance the unit test of relationship in model to projects in laravel
{
"require-dev": {
"fs-ap/laravel-relationship-test": "~1.0"
}
}
Or
Through terminal: composer require --dev fs-ap/laravel-relationship-test:~1.0
<?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));
}
}
This feature checks bidirectional relation between models through of @return
annotations on method that defines the relation
<?php
class Author extends Illuminate\Database\Eloquent\Model {
/**
* @return Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments() { return \$this->hasMany(Comment::class); }
}
And
<?php
class Comment extends Illuminate\Database\Eloquent\Model {
/**
* @return Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function author() { return \$this->belongsTo(Author::class); }
}
| Relation | Mapped to | | ------ | ----------- | | Relationship::HAS_MANY | Relationship::BELONGS_TO | | Relationship::BELONGS_TO | Relationship::HAS_MANY | | Relationship::HAS_ONE |Relationship::HAS_ONE |
<?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