Files
oficial/app/tests/unit/src/Repository/DireccionTest.php
aldarien 61c813fc08 feature/cierres (#30)
Reservas agregar y aprobar

Co-authored-by: Juan Pablo Vial <jpvialb@incoviba.cl>
Reviewed-on: #30
2025-09-11 15:16:12 -03:00

65 lines
2.2 KiB
PHP

<?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));
}
}