1. Go to this page and download the library: Download sofa/eloquent-testsuite library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sofa / eloquent-testsuite example snippets
class SomeModelTest extends \PHPUnit\Framework\TestCase
{
use EloquentSuite;
/** @test */
public function user_belongs_to_organization()
{
$user = $this->createRelationMock(User::class, 'belongsTo', Organization::class);
$this->assertRelation('belongsTo', $user->organization());
}
/** @test */
public function user_has_many_customers()
{
// $relation is a Mockery mock
[$user, $relation] = $this->createRelationChainMock(User::class, 'hasMany', Customer::class);
$relation->shouldReceive('active')->once()->andReturnSelf();
$relation->shouldReceive('latest')->once()->andReturnSelf();
$this->assertRelation('hasMany', $user->customers());
}
}
class SomeModelTest extends \PHPUnit\Framework\TestCase
{
use EloquentSuite;
public function testScopePublished()
{
$article = new Article();
$this->assertScopeFilters($article, 'published', 'status', 1);
}
public function testScopeAvailable()
{
$article = new Article();
$this->assertScopeFiltersNull($article, 'available', 'deleted_at');
}
public function testScopeDeleted()
{
$article = new Article();
$this->assertScopeFiltersNotNull($article, 'deleted', 'deleted_at');
}
}
public function scopeValidOnDate($query, $date)
{
return $query->whereRaw('? between valid_from and valid_to', [$date]);
}
public function testScopeValidOnDate()
{
$assertion = $this->stringContains('valid_from');
$params = ['2020-10-10'];
$query = $this->createQueryMock('whereRaw', $assertion, $params);
$ticket = new Ticket();
$ticket->scopeValidOnDate($query, '2020-10-10');
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.