Skip to content

Commit

Permalink
Test Suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Pollastri committed Nov 13, 2023
1 parent 5f24221 commit ed0c82c
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Models/Sede.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Sede extends Model
{
public string $Indirizzo;
public string $Cap;
public string $CAP;
public string $Comune;
public ?string $Provincia;
public ?string $Nazione;
Expand Down
45 changes: 45 additions & 0 deletions tests/IdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Axiostudio\FatturaElettronica\Tests;

use Axiostudio\FatturaElettronica\Models\Id;
use Axiostudio\FatturaElettronica\Settings;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Validation;

class IdTest extends TestCase
{
public function testConstructorWithIdPaese(): void
{
$idCodice = 'ABC123456789';
$idPaese = 'IT';

$id = new Id($idCodice, $idPaese);

$this->assertInstanceOf(Id::class, $id);
$this->assertEquals($idCodice, $id->IdCodice);
$this->assertEquals($idPaese, $id->IdPaese);
}

public function testConstructorWithoutIdPaese(): void
{
$idCodice = 'ABC123456789';

$id = new Id($idCodice);

$this->assertInstanceOf(Id::class, $id);
$this->assertEquals($idCodice, $id->IdCodice);
$this->assertEquals(Settings::IdPaeseDefault(), $id->IdPaese);
}

public function testValidation(): void
{
$id = new Id('ABC123456789', 'IT');

$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();

$violations = $validator->validate($id);

$this->assertCount(0, $violations);
}
}
56 changes: 56 additions & 0 deletions tests/SedeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Axiostudio\FatturaElettronica\Tests;

use Axiostudio\FatturaElettronica\Models\Sede;
use Axiostudio\FatturaElettronica\Settings;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Validation;

class SedeTest extends TestCase
{
public function testConstructorWithProvinciaAndNazione(): void
{
$indirizzo = 'Via Example, 123';
$cap = '12345';
$comune = 'Example City';
$provincia = 'EX';
$nazione = 'IT';

$sede = new Sede($indirizzo, $cap, $comune, $provincia, $nazione);

$this->assertInstanceOf(Sede::class, $sede);
$this->assertEquals($indirizzo, $sede->Indirizzo);
$this->assertEquals($cap, $sede->CAP);
$this->assertEquals($comune, $sede->Comune);
$this->assertEquals($provincia, $sede->Provincia);
$this->assertEquals($nazione, $sede->Nazione);
}

public function testConstructorWithoutProvinciaAndNazione(): void
{
$indirizzo = 'Via Example, 123';
$cap = '12345';
$comune = 'Example City';

$sede = new Sede($indirizzo, $cap, $comune);

$this->assertInstanceOf(Sede::class, $sede);
$this->assertEquals($indirizzo, $sede->Indirizzo);
$this->assertEquals($cap, $sede->CAP);
$this->assertEquals($comune, $sede->Comune);
$this->assertNull($sede->Provincia);
$this->assertEquals(Settings::IdPaeseDefault(), $sede->Nazione);
}

public function testValidation(): void
{
$sede = new Sede('Via Example, 123', '12345', 'Example City', 'EX', 'IT');

$validator = Validation::createValidatorBuilder()->enableAnnotationMapping()->getValidator();

$violations = $validator->validate($sede);

$this->assertCount(0, $violations);
}
}

0 comments on commit ed0c82c

Please sign in to comment.