Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complementando testes ICMSSN #1050

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,17 @@
}
},
"scripts": {
"precommit": [
"@stan",
"@phpcbf",
"@phpcs",
"@test"
],
"test": "vendor/bin/phpunit -c phpunit.xml.dist",
"test-with-coverage": "vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=coverage.xml",
"phpcbf": "vendor/bin/phpcbf src/",
"phpcs": "vendor/bin/phpcs src/",
"stan": "vendor/bin/phpstan analyse src/"
"phpcbf": "vendor/bin/phpcbf src/ tests/",
"phpcs": "vendor/bin/phpcs src/ tests/",
"stan": "vendor/bin/phpstan analyse src/ tests/"
},
"extra": {
"branch-alias": {
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ parameters:
paths:
- src
- tests
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
treatPhpDocTypesAsCertain: false
1 change: 0 additions & 1 deletion tests/Common/StandardizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function testWhichIsFailNotXMLNull()
{
$this->expectException(\NFePHP\NFe\Exception\DocumentsException::class);
$st = new Standardize();
//@phpstan-ignore-next-line
$st->whichIs(null);
}

Expand Down
225 changes: 221 additions & 4 deletions tests/MakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,9 @@ private function validarCriacaoTagICMS(\stdClass $icms): void
$tag = $this->make->tagICMS($icms);
$this->assertEquals('ICMS', $tag->nodeName);
unset($attributos['item']);
foreach ($attributos as $attributo => $valor){
$this->assertEquals($icms->{$attributo}, $tag->getElementsByTagName($attributo)->item(0)->nodeValue, "Campo {$attributo} possui valor incorreto!");
foreach ($attributos as $attributo => $valor) {
$element = $tag->getElementsByTagName($attributo)->item(0);
$this->assertEquals($icms->{$attributo}, $element->nodeValue, "Campo {$attributo} possui valor incorreto!");
}
}

Expand Down Expand Up @@ -944,12 +945,228 @@ public function test_tagICMSST(): void
$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_101(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '101';
$std->pCredSN = 3;
$std->vCredICMSSN = 4;

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN101')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN101', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_102(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '102';

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN102')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN102', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_103(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '103';

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN102')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN102', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_300(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '300';

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN102')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN102', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_400(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '400';

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN102')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN102', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_201(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '201';
$std->modBCST = 4;
$std->pMVAST = 10;
$std->pRedBCST = 20;
$std->vBCST = 300;
$std->pICMSST = 1;
$std->vICMSST = 1;
$std->vBCFCPST = 1;
$std->pFCPST = 1;
$std->vFCPST = 1;
$std->pCredSN = 1;
$std->vCredICMSSN = 1;


$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN201')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN201', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_202(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '202';
$std->modBCST = 4;
$std->pMVAST = 10;
$std->pRedBCST = 20;
$std->vBCST = 300;
$std->pICMSST = 1;
$std->vICMSST = 1;
$std->vBCFCPST = 1;
$std->pFCPST = 1;
$std->vFCPST = 1;

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN202')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN202', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_203(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '203';
$std->modBCST = 4;
$std->pMVAST = 10;
$std->pRedBCST = 20;
$std->vBCST = 300;
$std->pICMSST = 1;
$std->vICMSST = 1;
$std->vBCFCPST = 1;
$std->pFCPST = 1;
$std->vFCPST = 1;

$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN202')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN202', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_500(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '500';
$std->vBCSTRet = 1;
$std->pST = 1;
$std->vICMSSubstituto = 1;
$std->vICMSSTRet = 1;
$std->vBCFCPSTRet = 1;
$std->pFCPSTRet = 1;
$std->vFCPSTRet = 1;
$std->pRedBCEfet = 1;
$std->vBCEfet = 1;
$std->pICMSEfet = 1;
$std->vICMSEfet = 1;


$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN500')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN500', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

public function test_tagICMSSN_900(): void
{
$std = new \stdClass();
$std->item = 1;
$std->orig = 0;
$std->CSOSN = '900';
$std->modBC = 3;
$std->vBC = 100;
$std->pRedBC = 1;
$std->pICMS = 1;
$std->vICMS = 1;
$std->pCredSN = 3;
$std->vCredICMSSN = 4;
$std->modBCST = 3;
$std->pMVAST = 1;
$std->pRedBCST = 1;
$std->vBCST = 1;
$std->pICMSST = 1;
$std->vICMSST = 1;
$std->vBCFCPST = 1;
$std->pFCPST = 1;
$std->vFCPST = 1;


$tag = $this->make->tagICMSSN($std);
$tag2 = $tag->getElementsByTagName('ICMSSN900')->item(0);
$this->assertEquals('ICMS', $tag->nodeName);
$this->assertEquals('ICMSSN900', $tag2->nodeName);

$this->validarExistenciaCampos($std, $tag2);
}

private function validarExistenciaCampos(\stdClass $std, \DOMElement $tag): void
{
$attributos = get_object_vars($std);
unset($attributos['item']);
foreach ($attributos as $attributo => $valor){
$this->assertEquals($std->{$attributo}, $tag->getElementsByTagName($attributo)->item(0)->nodeValue, "Campo {$attributo} possui valor incorreto!");
foreach ($attributos as $attributo => $valor) {
if ($valor === null) {
continue;
}
$elemento = $tag->getElementsByTagName($attributo)->item(0);
$this->assertInstanceOf(\DOMElement::class, $elemento, "Elemento {$attributo} não encontrado");
$this->assertEquals($std->{$attributo}, $elemento->nodeValue, "Campo {$attributo} possui valor incorreto!");
}
}

Expand Down