diff --git a/tests/Xml/Builder/CeBuilderTrait.php b/tests/Xml/Builder/CeBuilderTrait.php index a9c300b..36499a5 100644 --- a/tests/Xml/Builder/CeBuilderTrait.php +++ b/tests/Xml/Builder/CeBuilderTrait.php @@ -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; @@ -26,7 +25,7 @@ */ trait CeBuilderTrait { - use StoreTrait; + use SharedBuilderTrait; /** * @param string $className diff --git a/tests/Xml/Builder/CeDespatchBuilderTest.php b/tests/Xml/Builder/CeDespatchBuilderTest.php index cb8e120..0c9b2d6 100644 --- a/tests/Xml/Builder/CeDespatchBuilderTest.php +++ b/tests/Xml/Builder/CeDespatchBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\DespatchStore; use Greenter\Model\Despatch\Despatch; /** @@ -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); diff --git a/tests/Xml/Builder/CePerceptionBuilderTest.php b/tests/Xml/Builder/CePerceptionBuilderTest.php index c3715aa..1ba9423 100644 --- a/tests/Xml/Builder/CePerceptionBuilderTest.php +++ b/tests/Xml/Builder/CePerceptionBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\PerceptionStore; use Greenter\Model\Perception\Perception; /** @@ -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); diff --git a/tests/Xml/Builder/CeRetentionBuilderTest.php b/tests/Xml/Builder/CeRetentionBuilderTest.php index 0d98088..2b39060 100644 --- a/tests/Xml/Builder/CeRetentionBuilderTest.php +++ b/tests/Xml/Builder/CeRetentionBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\RetentionStore; use Greenter\Model\Retention\Retention; /** @@ -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); diff --git a/tests/Xml/Builder/CeReversionBuilderTest.php b/tests/Xml/Builder/CeReversionBuilderTest.php index c2a5bbf..1da8036 100644 --- a/tests/Xml/Builder/CeReversionBuilderTest.php +++ b/tests/Xml/Builder/CeReversionBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\ReversionStore; use Greenter\Model\Voided\Reversion; /** @@ -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); @@ -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); diff --git a/tests/Xml/Builder/FeBuilderTrait.php b/tests/Xml/Builder/FeBuilderTrait.php index 15394f2..1c9b094 100644 --- a/tests/Xml/Builder/FeBuilderTrait.php +++ b/tests/Xml/Builder/FeBuilderTrait.php @@ -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, @@ -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) @@ -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; - } -} \ No newline at end of file +} diff --git a/tests/Xml/Builder/FeInvoiceBuilderTest.php b/tests/Xml/Builder/FeInvoiceBuilderTest.php index 575f1fa..a9488d9 100644 --- a/tests/Xml/Builder/FeInvoiceBuilderTest.php +++ b/tests/Xml/Builder/FeInvoiceBuilderTest.php @@ -8,6 +8,8 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\InvoiceFullStore; +use Greenter\Data\Generator\InvoiceStore; use Greenter\Model\Sale\Invoice; /** @@ -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); @@ -65,23 +51,4 @@ private function getFileName(Invoice $invoice) return join('-', $parts); } - - private function loadExtras(Invoice $invoice) - { - $invoice->getCompany() - ->setEmail('admin@corp.com') - ->setTelephone('001-123243'); - - $invoice->getClient() - ->setEmail('client@corp.com') - ->setTelephone('001-445566'); - - $invoice->setSeller($this->getClient() - ->setTipoDoc('0') - ->setNumDoc('00000000') - ->setRznSocial('Super Seller') - ->setEmail('seller@corp.com') - ->setTelephone('990134255')); - - } } \ No newline at end of file diff --git a/tests/Xml/Builder/FeNoteBuilderTest.php b/tests/Xml/Builder/FeNoteBuilderTest.php index ba6e494..327fb21 100644 --- a/tests/Xml/Builder/FeNoteBuilderTest.php +++ b/tests/Xml/Builder/FeNoteBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\NoteStore; use Greenter\Model\Sale\Note; /** @@ -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); diff --git a/tests/Xml/Builder/FeSummaryBuilderTest.php b/tests/Xml/Builder/FeSummaryBuilderTest.php index c272928..947a938 100644 --- a/tests/Xml/Builder/FeSummaryBuilderTest.php +++ b/tests/Xml/Builder/FeSummaryBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\SummaryStore; use Greenter\Model\Summary\Summary; /** @@ -21,8 +22,7 @@ class FeSummaryBuilderTest extends \PHPUnit_Framework_TestCase public function testCreateXmlSummary() { - $summary = $this->getSummary(); - $summary->getDetails()[0]->setMtoOperExportacion(10); + $summary = $this->createDocument(SummaryStore::class); $xml = $this->build($summary); @@ -32,7 +32,8 @@ public function testCreateXmlSummary() public function testCreateXmlSummaryOtherMoney() { - $summary = $this->getSummary(); + /**@var $summary Summary*/ + $summary = $this->createDocument(SummaryStore::class); $summary->setMoneda('USD'); $xml = $this->build($summary); @@ -44,7 +45,8 @@ public function testCreateXmlSummaryOtherMoney() public function testSummaryFilename() { - $summary = $this->getSummary(); + /**@var $summary Summary*/ + $summary = $this->createDocument(SummaryStore::class); $filename = $summary->getName(); $this->assertEquals($this->getFilename($summary), $filename); diff --git a/tests/Xml/Builder/FeVoidedBuilderTest.php b/tests/Xml/Builder/FeVoidedBuilderTest.php index 90e4229..fbec762 100644 --- a/tests/Xml/Builder/FeVoidedBuilderTest.php +++ b/tests/Xml/Builder/FeVoidedBuilderTest.php @@ -8,6 +8,7 @@ namespace Tests\Greenter\Xml\Builder; +use Greenter\Data\Generator\VoidedStore; use Greenter\Model\Voided\Voided; /** @@ -21,7 +22,7 @@ class FeVoidedBuilderTest extends \PHPUnit_Framework_TestCase public function testCreateXmlVoided() { - $voided = $this->getVoided(); + $voided = $this->createDocument(VoidedStore::class); $xml = $this->build($voided); @@ -31,7 +32,8 @@ public function testCreateXmlVoided() public function testVoidedFilename() { - $voided = $this->getVoided(); + /**@var $voided Voided */ + $voided = $this->createDocument(VoidedStore::class); $filename = $voided->getName(); $this->assertEquals($this->getFilename($voided), $filename); diff --git a/tests/Xml/Builder/v21/FeInvoiceBuilderTest.php b/tests/Xml/Builder/v21/FeInvoiceBuilderTest.php index fcfd2a9..d782bec 100644 --- a/tests/Xml/Builder/v21/FeInvoiceBuilderTest.php +++ b/tests/Xml/Builder/v21/FeInvoiceBuilderTest.php @@ -8,6 +8,9 @@ namespace Tests\Greenter\Xml\Builder\v21; +use Greenter\Data\Generator\InvoiceDiscountStore; +use Greenter\Data\Generator\InvoiceFullStore; +use Greenter\Model\Sale\Invoice; use Tests\Greenter\Xml\Builder\FeBuilderTrait; use Tests\Greenter\Xml\Builder\XsdValidatorTrait; @@ -18,7 +21,8 @@ class FeInvoiceBuilderTest extends \PHPUnit_Framework_TestCase public function testGenerate() { - $invoice = $this->getFullInvoice(); + /**@var $invoice Invoice*/ + $invoice = $this->createDocument(InvoiceFullStore::class); $invoice->setUblVersion('2.1'); $xml = $this->build($invoice); @@ -27,4 +31,14 @@ public function testGenerate() $this->assertNotEmpty($xml); $this->assertSchema($xml); } + + public function testInvoiceWithDiscount() + { + $invoice = $this->createDocument(InvoiceDiscountStore::class); + + $xml = $this->build($invoice); + // file_put_contents('x.xml', $xml); + $this->assertNotEmpty($xml); + $this->assertSchema($xml); + } } \ No newline at end of file diff --git a/tests/Xml/Builder/v21/FeNoteBuilderTest.php b/tests/Xml/Builder/v21/FeNoteBuilderTest.php index 7b4d524..adf812d 100644 --- a/tests/Xml/Builder/v21/FeNoteBuilderTest.php +++ b/tests/Xml/Builder/v21/FeNoteBuilderTest.php @@ -8,6 +8,8 @@ namespace Tests\Greenter\Xml\Builder\v21; +use Greenter\Data\Generator\NoteStore; +use Greenter\Model\Sale\Note; use Tests\Greenter\Xml\Builder\FeBuilderTrait; use Tests\Greenter\Xml\Builder\XsdValidatorTrait; @@ -22,7 +24,8 @@ class FeNoteBuilderTest extends \PHPUnit_Framework_TestCase public function testCreateXmlCreditNote() { - $note = $this->getNote(); + /**@var $note Note*/ + $note = $this->createDocument(NoteStore::class); $note->setUblVersion('2.1'); $xml = $this->build($note); @@ -34,7 +37,8 @@ public function testCreateXmlCreditNote() public function testCreateXmlDebitNote() { - $note = $this->getNote(); + /**@var $note Note*/ + $note = $this->createDocument(NoteStore::class); $note->setTipoDoc('08'); $note->setUblVersion('2.1');