Last active
June 30, 2022 22:09
-
-
Save vicentimartins/4d7c79c31adc056a2af846b30d6077a4 to your computer and use it in GitHub Desktop.
Teste de repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $query é um Eloquent\Builder | |
$query = parent::newQuery(); | |
$query->with('relation') // with() é um método de Eloquent\Builder | |
->join( // join() é método de Query\Builder | |
'table2', | |
'table1.user_id', | |
'table2.another_user_id' | |
) | |
->where('table2.another_user_id', $parametro); // where() está em ambos, Query\Builder e Eloquent\Builder | |
return $query->get(); //get() é método de Query\Builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$repository = new Repository(); | |
$filter = ['another_user_id' => 100]; | |
$data = Collection::make([]); // Representa meus dados esperados de retorno | |
$queryBuilderMock = Mockery::mock(QueryBuilder::class, function (MockInterface $qb) use ($filter, $data) { | |
$qb->shouldReceive('join') | |
->atLeast(1) | |
->with(Mockery::type('string'), Mockery::type('string'), Mockery::type('string')) | |
->andReturnSelf(); | |
$qb->shouldReceive('where') | |
->atLeast(1) | |
->with(Mockery::type('string'), $filter['tax_assistant_id']) | |
->andReturnSelf(); | |
}); | |
$builderMock = Mockery::mock(EloquentBuilder::class, function (MockInterface $eb) { | |
$eb->shouldReceive('with') | |
->atLeast(1) | |
->with('Conversations') | |
->andReturnSelf(); | |
}); | |
$baseRepositoryMock = Mockery::mock(BaseRepository::class) | |
->shouldAllowMockingProtectedMethods(); | |
$baseRepositoryMock->shouldReceive('newQuery') | |
->atLeast(1) | |
->andReturn($builderMock); | |
$this->assertEquals(1, $repository->listAll($filter)->count()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment