Skip to content

Commit

Permalink
Up coverage test + Add new validations model
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Aug 13, 2017
1 parent c2f62fa commit bf208fe
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 17 deletions.
4 changes: 4 additions & 0 deletions src/Greenter/Model/Sale/BaseSale.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,21 @@ class BaseSale

/**
* @Assert\NotBlank()
* @Assert\Type("numeric")
* @var float
*/
protected $mtoOperGravadas;

/**
* @Assert\NotBlank()
* @Assert\Type("numeric")
* @var float
*/
protected $mtoOperInafectas;

/**
* @Assert\NotBlank()
* @Assert\Type("numeric")
* @var float
*/
protected $mtoOperExoneradas;
Expand All @@ -100,6 +103,7 @@ class BaseSale
* Importe total de la venta, cesión en uso o del servicio prestado.
*
* @Assert\NotBlank()
* @Assert\Type("numeric")
* @var float
*/
protected $mtoImpVenta;
Expand Down
26 changes: 20 additions & 6 deletions src/Greenter/Xml/Validator/InvoiceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ public static function loadValidatorMetadata(ClassMetadata $metadata)
new Assert\NotBlank(),
new Assert\Length(['max' => 3]),
]);
$metadata->addPropertyConstraint('mtoOperGravadas', new Assert\NotBlank());
$metadata->addPropertyConstraint('mtoOperInafectas', new Assert\NotBlank());
$metadata->addPropertyConstraint('mtoOperExoneradas', new Assert\NotBlank());
$metadata->addPropertyConstraint('mtoImpVenta', new Assert\NotBlank());
$metadata->addPropertyConstraint('client', new Assert\NotBlank());
$metadata->addPropertyConstraint('client', new Assert\Valid());
$metadata->addPropertyConstraints('mtoOperGravadas',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('mtoOperInafectas',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('mtoOperExoneradas',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('mtoImpVenta',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('client', [
new Assert\NotBlank(),
new Assert\Valid(),
]);
$metadata->addPropertyConstraint('details', new Assert\Valid());
$metadata->addPropertyConstraint('legends', new Assert\Valid());
$metadata->addPropertyConstraint('relDocs', new Assert\Valid());
Expand Down
26 changes: 20 additions & 6 deletions src/Greenter/Xml/Validator/NoteValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,26 @@ public static function loadValidatorMetadata(ClassMetadata $metadata)
new Assert\NotBlank(),
new Assert\Length(['max' => 3]),
]);
$metadata->addPropertyConstraint('mtoOperGravadas', new Assert\NotBlank());
$metadata->addPropertyConstraint('mtoOperInafectas', new Assert\NotBlank());
$metadata->addPropertyConstraint('mtoOperExoneradas', new Assert\NotBlank());
$metadata->addPropertyConstraint('mtoImpVenta', new Assert\NotBlank());
$metadata->addPropertyConstraint('client', new Assert\NotBlank());
$metadata->addPropertyConstraint('client', new Assert\Valid());
$metadata->addPropertyConstraints('mtoOperGravadas',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('mtoOperInafectas',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('mtoOperExoneradas',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('mtoImpVenta',[
new Assert\NotBlank(),
new Assert\Type(['type' => 'numeric']),
]);
$metadata->addPropertyConstraints('client', [
new Assert\NotBlank(),
new Assert\Valid(),
]);
$metadata->addPropertyConstraint('details', new Assert\Valid());
$metadata->addPropertyConstraint('legends', new Assert\Valid());
$metadata->addPropertyConstraint('relDocs', new Assert\Valid());
Expand Down
14 changes: 14 additions & 0 deletions tests/Greenter/Factory/CeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function testReversion()
$reversion = $this->getReversion();
$result = $this->factory->sendReversion($reversion);

$this->assertNotEmpty($this->factory->getLastXml());
$this->assertTrue($result->isSuccess());
$this->assertNotEmpty($result->getTicket());
$this->assertEquals(13, strlen($result->getTicket()));
Expand Down Expand Up @@ -129,8 +130,21 @@ public function testStatus($ticket)

$this->assertTrue($result->isSuccess());
$this->assertNotNull($result->getCdrResponse());
$this->assertNotNull($result->getCdrZip());
$this->assertEquals('0', $result->getCode());
$this->assertRegExp(
'/El Comprobante numero RR-\d{8}-001 ha sido aceptado$/',
$result->getCdrResponse()->getDescription());
}

public function testStatusInvalidTicket()
{
$result = $this->factory->getStatus('123456789456');

$this->assertFalse($result->isSuccess());
$this->assertNotNull($result->getError());
$this->assertEquals('0127', $result->getError()->getCode());
$this->assertEquals('El ticket no existe',
$result->getError()->getMessage());
}
}
2 changes: 2 additions & 0 deletions tests/Greenter/Factory/FeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function testResumen()
$this->assertFalse($result->isSuccess());
$this->assertNotNull($result->getError());
$this->assertEquals('2072', $result->getError()->getCode());
$this->assertEquals('CustomizationID - La versión del documento no es la correcta',
$result->getError()->getMessage());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Greenter/Resources/invoice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@
<cbc:LineExtensionAmount currencyID="PEN">100.00</cbc:LineExtensionAmount>
<cac:PricingReference>
<cac:AlternativeConditionPrice>
<cbc:PriceAmount currencyID="PEN">56.00</cbc:PriceAmount>
<cbc:PriceTypeCode>01</cbc:PriceTypeCode>
<cbc:PriceAmount currencyID="PEN">2.00</cbc:PriceAmount>
<cbc:PriceTypeCode>02</cbc:PriceTypeCode>
</cac:AlternativeConditionPrice>
</cac:PricingReference>
<cac:AllowanceCharge>
Expand Down Expand Up @@ -239,7 +239,7 @@
</cac:SellersItemIdentification>
</cac:Item>
<cac:Price>
<cbc:PriceAmount currencyID="PEN">50.00</cbc:PriceAmount>
<cbc:PriceAmount currencyID="PEN">10.00</cbc:PriceAmount>
</cac:Price>
</cac:InvoiceLine>
</Invoice>
6 changes: 4 additions & 2 deletions tests/Greenter/Xml/Builder/FeInvoiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ private function getInvoice()
->setCodUnidadMedida('NIU')
->setCtdUnidadItem(2)
->setDesItem('PROD 2')
->setMtoDsctoItem(1)
->setMtoIgvItem(18)
->setTipAfeIgv('10')
->setMtoValorVenta(100)
->setMtoValorUnitario(50)
->setMtoPrecioUnitario(56);
->setMtoValorUnitario(10)
->setMtoValorGratuito(2)
->setMtoPrecioUnitario(0);

$legend = new Legend();
$legend->setCode('1000')
Expand Down

0 comments on commit bf208fe

Please sign in to comment.