Skip to content

Commit

Permalink
use document generators
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Mar 11, 2019
1 parent 924f188 commit c81bdeb
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 136 deletions.
3 changes: 1 addition & 2 deletions tests/Xml/Builder/CeBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\StoreTrait;
use Greenter\Model\Despatch\Despatch;
use Greenter\Model\DocumentInterface;
use Greenter\Model\Perception\Perception;
Expand All @@ -26,7 +25,7 @@
*/
trait CeBuilderTrait
{
use StoreTrait;
use SharedBuilderTrait;

/**
* @param string $className
Expand Down
8 changes: 4 additions & 4 deletions tests/Xml/Builder/CeDespatchBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\Generator\DespatchStore;
use Greenter\Model\Despatch\Despatch;

/**
Expand All @@ -21,18 +22,17 @@ class CeDespatchBuilderTest extends \PHPUnit_Framework_TestCase

public function testCreateXmlDespatch()
{
$despatch = $this->getDespatch();
$despatch = $this->createDocument(DespatchStore::class);

$xml = $this->build($despatch);

// file_put_contents('guia.xml', $xml);
$this->assertSchema($xml);

}

public function testDespatchFilename()
{
$despatch = $this->getDespatch();
/**@var $despatch Despatch*/
$despatch= $this->createDocument(DespatchStore::class);
$filename = $despatch->getName();

$this->assertEquals($this->getFilename($despatch), $filename);
Expand Down
17 changes: 5 additions & 12 deletions tests/Xml/Builder/CePerceptionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\Generator\PerceptionStore;
use Greenter\Model\Perception\Perception;

/**
Expand All @@ -21,35 +22,27 @@ class CePerceptionBuilderTest extends \PHPUnit_Framework_TestCase

public function testCreateXmlPerception()
{
$perception = $this->getPerception();
$perception = $this->createDocument(PerceptionStore::class);
$xml = $this->build($perception);

$this->assertNotEmpty($xml);
$this->assertSchema($xml);
//file_put_contents('percep.xml', $xml);
}

public function testCreateXmlPerceptionWithoutInformation()
{
$perception = $this->getPerception();
foreach ($perception->getDetails() as $per)
{
$per->setImpCobrar(0)
->setCobros(null)
->setImpPercibido(0);

}
$perception = $this->createDocument(PerceptionStore::class);

$xml = $this->build($perception);

$this->assertNotEmpty($xml);
$this->assertSchema($xml);
//file_put_contents('percep.xml', $xml);
}

public function testPerceptionFilename()
{
$perception = $this->getPerception();
/**@var $perception Perception*/
$perception = $this->createDocument(PerceptionStore::class);
$filename = $perception->getName();

$this->assertEquals($this->getFilename($perception), $filename);
Expand Down
36 changes: 5 additions & 31 deletions tests/Xml/Builder/CeRetentionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\Generator\RetentionStore;
use Greenter\Model\Retention\Retention;

/**
Expand All @@ -21,55 +22,28 @@ class CeRetentionBuilderTest extends \PHPUnit_Framework_TestCase

public function testCreateXmlRetention()
{
$retention = $this->getRetention();
$retention = $this->createDocument(RetentionStore::class);

foreach ($retention->getDetails() as $per)
{
$per->setImpPagar(0)
->setPagos(null)
->setImpRetenido(0);

}
$xml = $this->build($retention);

$this->assertNotEmpty($xml);
$this->assertSchema($xml);
// file_put_contents('reten.xml', $xml);
}

public function testCreateXmlRetentionWithoutInformation()
{
$retention = $this->getRetention();

foreach ($retention->getDetails() as $per)
{
$per->setImpPagar(0)
->setPagos(null)
->setImpRetenido(0);
$retention = $this->createDocument(RetentionStore::class);

}
$xml = $this->build($retention);

$this->assertNotEmpty($xml);
$this->assertSchema($xml);
// file_put_contents('reten.xml', $xml);
}

public function testCreateXmlRetentionWihtoutExchange()
{
$retention = $this->getRetention();

foreach ($retention->getDetails() as $detail) {
$detail->setTipoCambio(null);
}
$xml = $this->build($retention);

$this->assertNotEmpty($xml);
}

public function testRetentionFilename()
{
$retention = $this->getRetention();
/**@var $retention Retention*/
$retention = $this->createDocument(RetentionStore::class);
$filename = $retention->getName();

$this->assertEquals($this->getFilename($retention), $filename);
Expand Down
6 changes: 4 additions & 2 deletions tests/Xml/Builder/CeReversionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\Generator\ReversionStore;
use Greenter\Model\Voided\Reversion;

/**
Expand All @@ -21,7 +22,7 @@ class CeReversionBuilderTest extends \PHPUnit_Framework_TestCase

public function testCreateXmlReversion()
{
$reversion = $this->getReversion();
$reversion = $this->createDocument(ReversionStore::class);

$xml = $this->build($reversion);

Expand All @@ -31,7 +32,8 @@ public function testCreateXmlReversion()

public function testReversionFilename()
{
$reversion = $this->getReversion();
/**@var $reversion Reversion */
$reversion = $this->createDocument(ReversionStore::class);
$filename = $reversion->getName();

$this->assertEquals($this->getFilename($reversion), $filename);
Expand Down
43 changes: 10 additions & 33 deletions tests/Xml/Builder/FeBuilderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,28 @@
* Created by PhpStorm.
* User: Administrador
* Date: 19/07/2017
* Time: 10:40 AM
* Time: 10:40 AM.
*/

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\StoreTrait;
use Greenter\Builder\BuilderInterface;
use Greenter\Model\DocumentInterface;
use Greenter\Model\Sale\Invoice;
use Greenter\Model\Sale\Note;
use Greenter\Model\Summary\Summary;
use Greenter\Model\Voided\Voided;
use Greenter\Builder\BuilderInterface;
use Greenter\Model\Company\Address;
use Greenter\Model\Company\Company;
use Greenter\Xml\Builder\InvoiceBuilder;
use Greenter\Xml\Builder\NoteBuilder;
use Greenter\Xml\Builder\SummaryBuilder;
use Greenter\Xml\Builder\VoidedBuilder;

/**
* Trait FeBuilderTrait
* @package tests\Greenter\Xml\Builder
* Trait FeBuilderTrait.
*/
trait FeBuilderTrait
{
use StoreTrait;
use SharedBuilderTrait;

private $builders = [
Invoice::class => InvoiceBuilder::class,
Expand All @@ -40,22 +36,25 @@ trait FeBuilderTrait

/**
* @param $className
*
* @return BuilderInterface
*/
private function getGenerator($className)
{
$builder = new $this->builders[$className]([
$builderClass = $this->builders[$className];
$builder = new $builderClass([
'cache' => false,
'strict_variables' => true,
'autoescape' => false,
]);

/**@var $builder BuilderInterface */
/** @var $builder BuilderInterface */
return $builder;
}

/**
* @param DocumentInterface $document
*
* @return string
*/
private function build(DocumentInterface $document)
Expand All @@ -64,26 +63,4 @@ private function build(DocumentInterface $document)

return $generator->build($document);
}

/**
* @return Company
*/
private function getCompany()
{
$company = new Company();
$address = new Address();
$address->setUbigueo('150101')
->setDepartamento('LIMA')
->setProvincia('LIMA')
->setCodigoPais('PE')
->setDistrito('LIMA')
->setUrbanizacion('-')
->setDireccion('AV LS');
$company->setRuc('20000000001')
->setRazonSocial('EMPRESA SAC')
->setNombreComercial('EMPRESA')
->setAddress($address);

return $company;
}
}
}
43 changes: 5 additions & 38 deletions tests/Xml/Builder/FeInvoiceBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\Generator\InvoiceFullStore;
use Greenter\Data\Generator\InvoiceStore;
use Greenter\Model\Sale\Invoice;

/**
Expand All @@ -21,34 +23,18 @@ class FeInvoiceBuilderTest extends \PHPUnit_Framework_TestCase

public function testCreateXmlInvoice()
{
$invoice = $this->getFullInvoice();
$this->loadExtras($invoice);
$invoice = $this->createDocument(InvoiceFullStore::class);

$xml = $this->build($invoice);

// file_put_contents('x.xml', $xml);
$this->assertNotEmpty($xml);
$this->assertSchema($xml);
}

public function testCompanyValidate()
{
$company = $this->getCompany();
$adress = $company->getAddress();

$this->assertNotNull($company->getAddress());
$this->assertNotEmpty($company->getNombreComercial());
$this->assertNotEmpty($company->getRazonSocial());
$this->assertNotEmpty($company->getRuc());
$this->assertNotEmpty($adress->getDepartamento());
$this->assertNotEmpty($adress->getProvincia());
$this->assertNotEmpty($adress->getDistrito());
$this->assertNotEmpty($adress->getUrbanizacion());
}

public function testInvoiceFilename()
{
$invoice = $this->getInvoice();
/**@var $invoice Invoice*/
$invoice = $this->createDocument(InvoiceStore::class);
$filename = $invoice->getName();

$this->assertEquals($this->getFilename($invoice), $filename);
Expand All @@ -65,23 +51,4 @@ private function getFileName(Invoice $invoice)

return join('-', $parts);
}

private function loadExtras(Invoice $invoice)
{
$invoice->getCompany()
->setEmail('[email protected]')
->setTelephone('001-123243');

$invoice->getClient()
->setEmail('[email protected]')
->setTelephone('001-445566');

$invoice->setSeller($this->getClient()
->setTipoDoc('0')
->setNumDoc('00000000')
->setRznSocial('Super Seller')
->setEmail('[email protected]')
->setTelephone('990134255'));

}
}
11 changes: 6 additions & 5 deletions tests/Xml/Builder/FeNoteBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Tests\Greenter\Xml\Builder;

use Greenter\Data\Generator\NoteStore;
use Greenter\Model\Sale\Note;

/**
Expand All @@ -21,30 +22,30 @@ class FeNoteBuilderTest extends \PHPUnit_Framework_TestCase

public function testCreateXmlCreditNote()
{
$note = $this->getNote();
$note = $this->createDocument(NoteStore::class);

$xml = $this->build($note);

$this->assertNotEmpty($xml);
$this->assertSchema($xml);
// file_put_contents('notecr.xml', $xml);
}

public function testCreateXmlDebitNote()
{
$note = $this->getNote();
/**@var $note Note*/
$note = $this->createDocument(NoteStore::class);
$note->setTipoDoc('08');

$xml = $this->build($note);

$this->assertNotEmpty($xml);
$this->assertSchema($xml);
// file_put_contents('notedb.xml', $xml);
}

public function testNoteFilename()
{
$note = $this->getNote();
/**@var $note Note*/
$note = $this->createDocument(NoteStore::class);
$filename = $note->getName();

$this->assertEquals($this->getFilename($note), $filename);
Expand Down
Loading

0 comments on commit c81bdeb

Please sign in to comment.