2
Personal talk!
Following the idea of Boilerplate http://laravel-boilerplate.com I have a Repository like this:
class EmpresaRepository extends BaseRepository
{
public function __construct(Empresa $model)
{
$this->model = $model;
}
}
and Serviceprovider in this way:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Models\Empresa;
use App\Repositories\Backend\EmpresaRepository;
class RepositoryServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('App\Repositories\Contracts\EmpresaRepositoryContract', function ($app) {
return new EmpresaRepository(new Empresa());
});
}
}
I want to run the following test:
public function empresa_repository_pode_recuperar_empresas()
{
$repo = resolve('App\Repositories\Backend\EmpresaRepository');
$empresas = factory(Empresa::class, 5)->create();
$query_empresas = $repo->all();
$this->assertEquals(count($empresas), count($query_empresas));
}
The problem that occurs is: whenever I instate a Restpository, it creates a new instance of Enterprise, and Count($query_empresas) always returns one more company than those already created with Factory.
Doubts: This approach of Repository always receiving an entity is even correct?
How can I pass this test?
Young man, your Preview service has been registered in config/app.php ?
– Diego Ananias