feature/cierres (#30)
Reservas agregar y aprobar Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl> Reviewed-on: #30
This commit is contained in:
64
app/tests/unit/src/Repository/DireccionTest.php
Normal file
64
app/tests/unit/src/Repository/DireccionTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace Incoviba\Test\Repository;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Faker;
|
||||
use Incoviba\Common\Define;
|
||||
use Incoviba\Model;
|
||||
use Incoviba\Repository;
|
||||
|
||||
class DireccionTest extends TestCase
|
||||
{
|
||||
protected Define\Connection $connection;
|
||||
protected Repository\Comuna $comunaRepository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->connection = $this->getMockBuilder(Define\Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->comunaRepository = $this->getMockBuilder(Repository\Comuna::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->comunaRepository->method('fetchById')->willReturnCallback(function ($id) {
|
||||
$comuna = new Model\Comuna();
|
||||
$comuna->id = $id;
|
||||
return $comuna;
|
||||
});
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
{
|
||||
$direccionRepository = new Repository\Direccion($this->connection, $this->comunaRepository);
|
||||
|
||||
$faker = Faker\Factory::create();
|
||||
$data = [
|
||||
'calle' => $faker->streetName,
|
||||
'numero' => $faker->randomNumber(),
|
||||
'extra' => $faker->streetSuffix,
|
||||
'comuna' => $faker->randomNumber(),
|
||||
];
|
||||
$direccion = $direccionRepository->create($data);
|
||||
|
||||
$this->assertTrue(!isset($direccion->id));
|
||||
$this->assertEquals($data['calle'], $direccion->calle);
|
||||
$this->assertEquals($data['numero'], $direccion->numero);
|
||||
$this->assertEquals($data['extra'], $direccion->extra);
|
||||
$this->assertEquals($data['comuna'], $direccion->comuna->id);
|
||||
}
|
||||
public function testSave(): void
|
||||
{
|
||||
$direccionRepository = new Repository\Direccion($this->connection, $this->comunaRepository);
|
||||
$faker = Faker\Factory::create();
|
||||
|
||||
$direccion = new Model\Direccion();
|
||||
$direccion->calle = $faker->streetName;
|
||||
$direccion->numero = $faker->randomNumber(3);
|
||||
$direccion->extra = $faker->streetSuffix;
|
||||
$direccion->comuna = $this->getMockBuilder(Model\Comuna::class)->getMock();
|
||||
$direccion->comuna->id = $faker->numberBetween(10000, 18000);
|
||||
$direccion = $direccionRepository->save($direccion);
|
||||
|
||||
$this->assertTrue(isset($direccion->id));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user