repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Common/SelloDigitalCertificadoWithRegularCertificadoTrait.php | tests/CfdiUtilsTests/Validate/Common/SelloDigitalCertificadoWithRegularCertificadoTrait.php | <?php
namespace CfdiUtilsTests\Validate\Common;
use CfdiUtils\Utils\Format;
use CfdiUtils\Validate\Common\SelloDigitalCertificadoValidatorTrait;
use CfdiUtils\Validate\Contracts\DiscoverableCreateInterface;
use CfdiUtils\Validate\Contracts\RequireXmlResolverInterface;
use CfdiUtils\Validate\Contracts\RequireXmlStringInterface;
use CfdiUtils\Validate\Status;
trait SelloDigitalCertificadoWithRegularCertificadoTrait
{
public function testObjectSpecification(): void
{
$this->assertInstanceOf(DiscoverableCreateInterface::class, $this->validator);
$this->assertInstanceOf(RequireXmlStringInterface::class, $this->validator);
$this->assertInstanceOf(RequireXmlResolverInterface::class, $this->validator);
}
public function testValidateWithoutCertificado(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO01');
$this->assertCount(8, $this->asserts);
foreach (range(2, 8) as $i) {
$this->assertStatusEqualsCode(Status::none(), 'SELLO0' . $i);
}
}
public function testValidateBadCertificadoNumber(): void
{
$this->setUpCertificado([
'NoCertificado' => 'X',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO02');
}
public function testValidateBadRfcAndNameNumber(): void
{
$this->setUpCertificado([], [
'Rfc' => null,
'Nombre' => 'Foo Bar',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO03');
$this->assertStatusEqualsCode(Status::error(), 'SELLO04');
}
public function testValidateOkLowerFecha(): void
{
// Fecha inicial de vigencia del certificado
$validLowerDate = strtotime('2023-05-18T11:43:51+00:00');
$this->setUpCertificado(['Fecha' => Format::datetime($validLowerDate)]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'SELLO05');
$this->assertStatusEqualsCode(Status::ok(), 'SELLO06');
}
public function testValidateBadLowerFecha(): void
{
// Fecha inicial de vigencia del certificado - 1
$validLowerDate = strtotime('2023-05-18T11:43:50+00:00');
$this->setUpCertificado(['Fecha' => Format::datetime($validLowerDate - 1)]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO05');
$this->assertStatusEqualsCode(Status::ok(), 'SELLO06');
}
public function testValidateOkHigherFecha(): void
{
// Fecha final de vigencia del certificado
$validHigherDate = strtotime('2023-06-17T19:44:13+00:00');
$this->setUpCertificado(['Fecha' => Format::datetime($validHigherDate)]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'SELLO05');
$this->assertStatusEqualsCode(Status::ok(), 'SELLO06');
}
public function testValidateBadHigherFecha(): void
{
// Fecha final de vigencia del certificado + 1
$validHigherDate = strtotime('2027-05-18T11:43:52+00:00');
$this->setUpCertificado(['Fecha' => Format::datetime($validHigherDate + 1)]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'SELLO05');
$this->assertStatusEqualsCode(Status::error(), 'SELLO06');
}
public function testValidateBadSelloBase64(): void
{
$this->setUpCertificado(['Sello' => 'ñ']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO07');
}
/**
* This test does not care about locales
*
* @testWith [true, "ABC", "ABC"]
* [true, "Empresa \"Equis\"", "Empresa Equis"]
* [false, "Empresa Equis Sa de Cv", "Empresa Equis SA CV"]
*/
public function testCompareNamesBasicChars(bool $expected, string $first, string $second): void
{
$validator = new class () {
use SelloDigitalCertificadoValidatorTrait;
protected function validateNombre(string $emisorNombre, string $rfc): void
{
}
public function testCompareNames(string $first, string $second): bool
{
return $this->compareNames($first, $second);
}
};
$this->assertSame($expected, $validator->testCompareNames($first, $second));
}
/**
* This test will perform comparison only when locales are set up or can be set,
* otherwise the test will be skipped.
*
* @testWith ["Cesar Gomez Aguero", "César Gómez Agüero"]
* ["Cesar Gomez Aguero", "CÉSAR GÓMEZ AGÜERO"]
* ["CAÑA SA", "Cana SA"]
*/
public function testCompareNamesExtendedChars(string $first, string $second): void
{
$validator = new class () {
use SelloDigitalCertificadoValidatorTrait;
protected function validateNombre(string $emisorNombre, string $rfc): void
{
}
public function testCompareNames(string $first, string $second): bool
{
return $this->compareNames($first, $second);
}
public function testCastNombre(string $name): string
{
return $this->castNombre($name);
}
};
$currentLocale = setlocale(LC_CTYPE, '0') ?: 'C';
if (
('C' === $currentLocale || 'POSIX' === $currentLocale)
&& false === setlocale(LC_CTYPE, 'es_MX.utf8', 'en_US.utf8', 'es_MX', 'en_US', 'spanish', 'english')
) {
$this->markTestSkipped('Cannot compare names without LC_CTYPE configured');
}
try {
$this->assertTrue($validator->testCompareNames($first, $second), sprintf(
'Unable to assert name equals (%s, %s) [%s like %s] with locale %s',
$first,
$second,
$validator->testCastNombre($first),
$validator->testCastNombre($second),
setlocale(LC_CTYPE, '0') ?: 'C'
));
} finally {
setlocale(LC_CTYPE, $currentLocale);
}
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Common/TimbreFiscalDigital11SelloTestTrait.php | tests/CfdiUtilsTests/Validate/Common/TimbreFiscalDigital11SelloTestTrait.php | <?php
namespace CfdiUtilsTests\Validate\Common;
use CfdiUtils\Elements\Tfd11\TimbreFiscalDigital;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Nodes\NodeInterface;
use CfdiUtils\Validate\Status;
trait TimbreFiscalDigital11SelloTestTrait
{
public function testValidCase(): void
{
$selloCfdi = $this->validSelloCfdi();
$selloSat = $this->validSelloSat();
$this->comprobante['Sello'] = $selloCfdi;
$tfd = $this->newTimbreFiscalDigital([
'NoCertificadoSAT' => $this->validCertificadoSAT(),
'SelloSAT' => $selloSat,
// these are required to create the source string
'SelloCFD' => $selloCfdi,
'FechaTimbrado' => '2018-01-12T08:17:54',
'RfcProvCertif' => 'DCD090706E42',
'UUID' => 'CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC',
]);
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TFDSELLO01');
}
public function testValidatorDontHaveXmlResolver(): void
{
$this->validator->setXmlResolver(null);
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'TFDSELLO01');
$this->assertStringContainsString(
'No se puede hacer la validación',
$this->asserts->get('TFDSELLO01')->getExplanation()
);
}
public function testValidatorDontHaveTimbreFiscalDigital(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'TFDSELLO01');
$this->assertStringContainsString('no contiene un Timbre', $this->asserts->get('TFDSELLO01')->getExplanation());
}
public function testValidatorTimbreFiscalDigitalVersionIsNotPresent(): void
{
$tfd = $this->newTimbreFiscalDigital();
unset($tfd['Version']);
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'TFDSELLO01');
$this->assertStringContainsString('La versión del timbre', $this->asserts->get('TFDSELLO01')->getExplanation());
}
public function testValidatorTimbreFiscalDigitalVersionIsNotValid(): void
{
$tfd = $this->newTimbreFiscalDigital();
$tfd['Version'] = '1.0';
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'TFDSELLO01');
$this->assertStringContainsString('La versión del timbre', $this->asserts->get('TFDSELLO01')->getExplanation());
}
public function testValidatorTimbreFiscalDigitalSelloSatDoesNotMatchWithComprobante(): void
{
$tfd = $this->newTimbreFiscalDigital();
$tfd['SelloCFD'] = 'foo';
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TFDSELLO01');
$this->assertStringContainsString('no coincide', $this->asserts->get('TFDSELLO01')->getExplanation());
}
public function testValidatorNoCertificadoSatEmpty(): void
{
$tfd = $this->newTimbreFiscalDigital();
$tfd['SelloCFD'] = 'foo';
$this->comprobante['Sello'] = $tfd['SelloCFD'];
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TFDSELLO01');
$this->assertStringContainsString('NoCertificadoSAT', $this->asserts->get('TFDSELLO01')->getExplanation());
}
public function testValidatorNoCertificadoSatInvalid(): void
{
$tfd = $this->newTimbreFiscalDigital();
$tfd['SelloCFD'] = 'foo';
$tfd['NoCertificadoSAT'] = '9876543210987654321A';
$this->comprobante['Sello'] = $tfd['SelloCFD'];
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TFDSELLO01');
$this->assertStringContainsString('NoCertificadoSAT', $this->asserts->get('TFDSELLO01')->getExplanation());
}
public function testValidatorNoCertificadoSatNonExistent(): void
{
$tfd = $this->newTimbreFiscalDigital();
$tfd['SelloCFD'] = 'foo';
$tfd['NoCertificadoSAT'] = '98765432109876543210';
$this->comprobante['Sello'] = $tfd['SelloCFD'];
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TFDSELLO01');
$this->assertStringContainsString(
'obtener el certificado',
$this->asserts->get('TFDSELLO01')->getExplanation()
);
}
public function testValidatorSelloSatInvalid(): void
{
// to make it fail we change the FechaTimbrado
$selloCfdi = $this->validSelloCfdi();
$selloSat = $this->validSelloSat();
$this->comprobante['Sello'] = $selloCfdi;
$tfd = $this->newTimbreFiscalDigital([
'NoCertificadoSAT' => $this->validCertificadoSAT(),
'SelloSAT' => $selloSat,
// these are required to create the source string
'SelloCFD' => $selloCfdi,
'FechaTimbrado' => '2018-01-12T08:17:53', // this was 54 seconds
'RfcProvCertif' => 'DCD090706E42',
'UUID' => 'CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC',
]);
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TFDSELLO01');
$this->assertStringContainsString(
'La verificación del timbrado fue negativa',
$this->asserts->get('TFDSELLO01')->getExplanation()
);
}
private function newTimbreFiscalDigital(array $attributes = []): NodeInterface
{
return new TimbreFiscalDigital($attributes);
}
private function validCertificadoSAT(): string
{
return '00001000000406258094';
}
private function validSelloCfdi(): string
{
return 'Xt7tK83WumikNMyx4Y/Z3R7D0rOjqTrrLu8wBlCnvXrpMFgWtyrcFUttGnevvUqCnQjuVUSpFcXqbzIQEUYNKFjxmtjwGHN+b'
. '15xUvcnfqpJRBoJe2IKd5YMZqYp9NhTJIMBYsE7+fhP1+mHcKdKn9WwXrar8uXzISqPgZ97AORBsMWmXxbVWYRtqT4MX/Xq4yhbT4jao'
. 'aut5AwhVzE1TUyZ10/C2gGySQeFVyEp9aqNScIxPotVDb7fMIWxsV26XODf6GK14B0TJNmRlCIfmfb2rQeskiYeiF5AQPb6Z2gmGLHcN'
. 'ks7qC+eO3EsGVr1/ntmGcwTurbGXmE4/OAgdg==';
}
private function validSelloSat(): string
{
return 'IRy7wQnKnlIsN/pSZSR7qEm/SOJuLIbNjj/S3EAd278T2uo0t73KXfXzUbbfWOwpdZEAZeosq/yEiStTaf44ZonqRS1fq6oYk1'
. '2udMmT4NFrEYbPEEKLn4lqdhuW4v8ZK2Vos/pjCtYtpT+/oVIXiWg9KrGVGuMvygRPWSmd+YJq3Jm7qTz0ON0vzBOvXralSZ4Q14xUvt'
. '6ZDM9gYqIzTtCjIWaNrAdEYyqfZjvfy0uCyThh6HvCbMsX9gq4RsQj3SIoA56g+1SJevoZ6Jr722mDCLcPox3KCN75Bk8ALJI6G0weP7'
. 'rQO5jEtulTRNWN3w+tlryZWElkD79MDZA6Zg==';
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Common/TimbreFiscalDigital11VersionTestTrait.php | tests/CfdiUtilsTests/Validate/Common/TimbreFiscalDigital11VersionTestTrait.php | <?php
namespace CfdiUtilsTests\Validate\Common;
use CfdiUtils\Elements\Tfd11\TimbreFiscalDigital;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Status;
trait TimbreFiscalDigital11VersionTestTrait
{
public function testValidCase(): void
{
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [
new TimbreFiscalDigital(),
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TFDVERSION01');
}
public function providerInvalidVersion(): array
{
return[
['1.0'],
['1.2'],
['0.1'],
['1.10'],
['ASD'],
[''],
['0'],
[null],
];
}
/**
* @dataProvider providerInvalidVersion
*/
public function testInvalidCase(?string $version): void
{
$tfd = new TimbreFiscalDigital();
$tfd->addAttributes(['Version' => $version]); // override version
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [$tfd]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TFDVERSION01');
}
public function testNoneCase(): void
{
$this->comprobante->addChild(new Node('cfdi:Complemento', [], []));
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'TFDVERSION01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationRequireXmlResolverInterface.php | tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationRequireXmlResolverInterface.php | <?php
namespace CfdiUtilsTests\Validate\FakeObjects;
use CfdiUtils\Validate\Contracts\RequireXmlResolverInterface;
use CfdiUtils\XmlResolver\XmlResolverPropertyTrait;
final class ImplementationRequireXmlResolverInterface extends ImplementationValidatorInterface implements
RequireXmlResolverInterface
{
use XmlResolverPropertyTrait;
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationDiscoverableCreateInterface.php | tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationDiscoverableCreateInterface.php | <?php
namespace CfdiUtilsTests\Validate\FakeObjects;
use CfdiUtils\Validate\Contracts\DiscoverableCreateInterface;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
final class ImplementationDiscoverableCreateInterface implements DiscoverableCreateInterface
{
public static function createDiscovered(): ValidatorInterface
{
return new ImplementationValidatorInterface();
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationRequireXmlStringInterface.php | tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationRequireXmlStringInterface.php | <?php
namespace CfdiUtilsTests\Validate\FakeObjects;
use CfdiUtils\Validate\Contracts\RequireXmlStringInterface;
use CfdiUtils\Validate\Traits\XmlStringPropertyTrait;
final class ImplementationRequireXmlStringInterface extends ImplementationValidatorInterface implements
RequireXmlStringInterface
{
use XmlStringPropertyTrait;
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationValidatorInterface.php | tests/CfdiUtilsTests/Validate/FakeObjects/ImplementationValidatorInterface.php | <?php
namespace CfdiUtilsTests\Validate\FakeObjects;
use CfdiUtils\Nodes\NodeInterface;
use CfdiUtils\Validate\Asserts;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
class ImplementationValidatorInterface implements ValidatorInterface
{
public string $version = '3.3';
public bool $onValidateSetMustStop = false;
public bool $enterValidateMethod = false;
public ?Asserts $assertsToImport = null;
public function validate(NodeInterface $comprobante, Asserts $asserts): void
{
if ($this->assertsToImport instanceof Asserts) {
$asserts->import($this->assertsToImport);
}
$this->enterValidateMethod = true;
$asserts->mustStop($this->onValidateSetMustStop);
}
public function canValidateCfdiVersion(string $version): bool
{
return $version === $this->version;
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi40/Xml/XmlDefinitionTest.php | tests/CfdiUtilsTests/Validate/Cfdi40/Xml/XmlDefinitionTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi40\Xml;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi40\Xml\XmlDefinition;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate40TestCase;
final class XmlDefinitionTest extends Validate40TestCase
{
/** @var XmlDefinition */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new XmlDefinition();
}
public function testCorrectDefinition(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'XML01');
$this->assertStatusEqualsCode(Status::ok(), 'XML02');
$this->assertStatusEqualsCode(Status::ok(), 'XML03');
}
public function testInCorrectDefinitionNamespacePrefix(): void
{
$this->comprobante->addAttributes([
'xmlns:cfdi' => null,
'xmlns:cfdi4' => 'http://www.sat.gob.mx/cfd/4',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'XML01');
}
public function testInCorrectDefinitionNamespaceValue(): void
{
$this->comprobante->addAttributes([
'xmlns:cfdi' => 'http://www.sat.gob.mx/cfd/40',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'XML01');
}
public function testInCorrectDefinitionRootPrefix(): void
{
$this->comprobante = new Node('cfdi4:Comprobante');
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'XML02');
}
public function testInCorrectDefinitionRootName(): void
{
$this->comprobante = new Node('cfdi:Cfdi');
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'XML02');
}
public function testInCorrectDefinitionVersionName(): void
{
$this->comprobante->addAttributes([
'Version' => null,
'version' => '4.0',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'XML03');
}
public function testInCorrectDefinitionVersionValue(): void
{
$this->comprobante->addAttributes([
'Version' => '4.1',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'XML03');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi40/Standard/SelloDigitalCertificadoTest.php | tests/CfdiUtilsTests/Validate/Cfdi40/Standard/SelloDigitalCertificadoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi40\Standard;
use CfdiUtils\Validate\Cfdi40\Standard\SelloDigitalCertificado;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Common\SelloDigitalCertificadoWithRegularCertificadoTrait;
use CfdiUtilsTests\Validate\Validate40TestCase;
final class SelloDigitalCertificadoTest extends Validate40TestCase
{
use SelloDigitalCertificadoWithRegularCertificadoTrait;
/** @var SelloDigitalCertificado */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new SelloDigitalCertificado();
$this->hydrater->hydrate($this->validator);
}
public function testObjectVersion(): void
{
$this->assertTrue($this->validator->canValidateCfdiVersion('4.0'));
}
public function testValidateBadSello(): void
{
$this->setupCfdiFile('cfdi40-valid.xml');
$this->comprobante['Sello'] = $this->comprobante['Certificado'];
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO08');
}
public function testValidateOk(): void
{
$this->setupCfdiFile('cfdi40-valid.xml');
$this->runValidate();
$expected = [
'SELLO01' => Status::ok(),
'SELLO02' => Status::ok(),
'SELLO03' => Status::ok(),
'SELLO04' => Status::ok(),
'SELLO05' => Status::ok(),
'SELLO06' => Status::ok(),
'SELLO07' => Status::ok(),
'SELLO08' => Status::ok(),
];
foreach ($expected as $code => $status) {
$this->assertStatusEqualsCode($status, $code);
}
$this->assertCount(8, $this->asserts, 'All 8 were are tested');
}
public function testValidateNameEmpty(): void
{
$this->setUpCertificado([], [
'Nombre' => '',
]);
$this->runValidate();
$status = $this->getAssertByCodeOrFail('SELLO04');
$this->assertTrue($status->getStatus()->isError());
$this->assertSame('Nombre del emisor vacío', $status->getExplanation());
}
public function testValidateNameMoralPerson(): void
{
$this->setUpCertificado([], [
'Nombre' => 'ESCUELA KEMPER URGATE',
]);
$this->runValidate();
$status = $this->getAssertByCodeOrFail('SELLO04');
$this->assertTrue($status->getStatus()->isOk());
$this->assertSame(
'Nombre certificado: ESCUELA KEMPER URGATE SA DE CV, Nombre comprobante: ESCUELA KEMPER URGATE.',
$status->getExplanation()
);
}
public function testValidateWithIdenticalNameRegularPerson(): void
{
$this->setUpCertificado([], [
'Rfc' => 'COSC8001137NA', // set as persona física to force name comparison and not remove suffix
'Nombre' => 'ESCUELA KEMPER URGATE SA DE CV',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'SELLO04');
}
public function testValidateWithoutIdenticalNameRegularPerson(): void
{
$this->setUpCertificado([], [
'Rfc' => 'COSC8001137NA', // set as persona física to force name comparison
'Nombre' => 'ESCUELA KEMPER URGATE SA DE CV ',
]);
$this->runValidate();
$status = $this->getAssertByCodeOrFail('SELLO04');
$this->assertTrue($status->getStatus()->isError());
$this->assertSame(
'Nombre certificado: ESCUELA KEMPER URGATE SA DE CV, Nombre comprobante: ESCUELA KEMPER URGATE SA DE CV .',
$status->getExplanation()
);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi40/Standard/TimbreFiscalDigitalVersionTest.php | tests/CfdiUtilsTests/Validate/Cfdi40/Standard/TimbreFiscalDigitalVersionTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi40\Standard;
use CfdiUtils\Validate\Cfdi40\Standard\TimbreFiscalDigitalVersion;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtilsTests\Validate\Common\TimbreFiscalDigital11VersionTestTrait;
use CfdiUtilsTests\Validate\Validate40TestCase;
final class TimbreFiscalDigitalVersionTest extends Validate40TestCase
{
use TimbreFiscalDigital11VersionTestTrait;
/** @var TimbreFiscalDigitalVersion */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new TimbreFiscalDigitalVersion();
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi40/Standard/TimbreFiscalDigitalSelloTest.php | tests/CfdiUtilsTests/Validate/Cfdi40/Standard/TimbreFiscalDigitalSelloTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi40\Standard;
use CfdiUtils\Validate\Cfdi40\Standard\TimbreFiscalDigitalSello;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtilsTests\Validate\Common\TimbreFiscalDigital11SelloTestTrait;
use CfdiUtilsTests\Validate\Validate40TestCase;
final class TimbreFiscalDigitalSelloTest extends Validate40TestCase
{
use TimbreFiscalDigital11SelloTestTrait;
/** @var TimbreFiscalDigitalSello */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new TimbreFiscalDigitalSello();
$this->hydrater->hydrate($this->validator);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi40/Standard/SelloDigitalCertificadoWithCfdiRegistroFiscalTest.php | tests/CfdiUtilsTests/Validate/Cfdi40/Standard/SelloDigitalCertificadoWithCfdiRegistroFiscalTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi40\Standard;
use CfdiUtils\Validate\Cfdi40\Standard\SelloDigitalCertificado;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtilsTests\Validate\Common\SelloDigitalCertificadoWithCfdiRegistroFiscalTrait;
use CfdiUtilsTests\Validate\Validate40TestCase;
final class SelloDigitalCertificadoWithCfdiRegistroFiscalTest extends Validate40TestCase
{
use SelloDigitalCertificadoWithCfdiRegistroFiscalTrait;
/** @var SelloDigitalCertificado */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new SelloDigitalCertificado();
$this->hydrater->hydrate($this->validator);
$cerfile = $this->utilAsset('certs/00001000000403258748.cer');
$this->setUpCertificado([], [
'Nombre' => 'CARLOS CORTES SOTO',
'Rfc' => 'COSC8001137NA',
], $cerfile);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteDescuentoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteDescuentoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteDescuento;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteDescuentoTest extends Validate33TestCase
{
/** @var ComprobanteDescuento */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteDescuento();
}
public function providerValidCases(): array
{
return[
['0', '1'],
['1', '1'],
['0.000000', '0.000001'],
['0', '0'],
['1.00', '1.01'],
];
}
/**
* @dataProvider providerValidCases
*/
public function testValidCases(string $descuento, string $subtotal): void
{
$this->comprobante->addAttributes([
'Descuento' => $descuento,
'SubTotal' => $subtotal,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'DESCUENTO01');
}
public function providerInvalidCases(): array
{
return[
['', '0'],
['1', '0'],
['5', null],
['0.000001', '0.000000'],
['-1', '5'],
['-5', '5'],
];
}
/**
* @dataProvider providerInvalidCases
*/
public function testInvalidCases(string $descuento, ?string $subtotal): void
{
$this->comprobante->addAttributes([
'Descuento' => $descuento,
'SubTotal' => $subtotal,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'DESCUENTO01');
}
public function testNoneCase(): void
{
$this->comprobante->addAttributes([
'Descuento' => null,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'DESCUENTO01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteTotalTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteTotalTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteTotal;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteTotalTest extends Validate33TestCase
{
/** @var ComprobanteTotal */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteTotal();
}
public function providerTotalWithInvalidValue(): array
{
return [
'empty' => [''],
'missing' => [null],
'not a number' => ['foo'],
'1.2e3' => ['1.2e3'],
['0.'],
['.0'],
['0..0'],
['0.0.0'],
['-0.0001'],
];
}
/**
* @dataProvider providerTotalWithInvalidValue
*/
public function testTotalWithInvalidValue(?string $value): void
{
$this->comprobante->addAttributes([
'Total' => $value,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TOTAL01');
}
public function providerTotalWithValidValues(): array
{
return [
'0' => ['0'],
'0.0' => ['0.0'],
'123.45' => ['123.45'],
];
}
/**
* @dataProvider providerTotalWithValidValues
*/
public function testTotalWithCorrectValues(string $value): void
{
$this->comprobante->addAttributes([
'Total' => $value,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TOTAL01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/FechaComprobanteTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/FechaComprobanteTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Utils\Format;
use CfdiUtils\Validate\Cfdi33\Standard\FechaComprobante;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class FechaComprobanteTest extends Validate33TestCase
{
/** @var FechaComprobante */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new FechaComprobante();
}
public function testConstructWithoutArguments(): void
{
$expectedTolerance = 300;
$expectedMaxTime = time() + $expectedTolerance;
$validator = new FechaComprobante();
$this->assertTrue($validator->canValidateCfdiVersion('3.3'));
$this->assertEquals($expectedMaxTime, $validator->getMaximumDate());
$this->assertEquals($expectedTolerance, $validator->getTolerance());
}
public function testSetMaximumDate(): void
{
$validator = new FechaComprobante();
$validator->setMaximumDate(0);
$this->assertEquals(0, $validator->getMaximumDate());
}
public function testSetTolerance(): void
{
$validator = new FechaComprobante();
$validator->setTolerance(1000);
$this->assertEquals(1000, $validator->getTolerance());
}
public function testValidateOkCurrentDate(): void
{
$timestamp = time();
$this->comprobante->addAttributes([
'Fecha' => Format::datetime($timestamp),
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'FECHA01');
$this->assertStatusEqualsCode(Status::ok(), 'FECHA02');
$this->assertFalse($this->asserts->hasErrors());
}
public function testValidateOkMinimumDate(): void
{
$timestamp = $this->validator->getMinimumDate();
$this->comprobante->addAttributes([
'Fecha' => Format::datetime($timestamp),
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'FECHA01');
$this->assertStatusEqualsCode(Status::ok(), 'FECHA02');
$this->assertFalse($this->asserts->hasErrors());
}
public function testValidateOkMaximumDate(): void
{
$timestamp = $this->validator->getMaximumDate();
$this->comprobante->addAttributes([
'Fecha' => Format::datetime($timestamp),
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'FECHA01');
$this->assertStatusEqualsCode(Status::ok(), 'FECHA02');
$this->assertFalse($this->asserts->hasErrors());
}
public function testValidateWithoutFecha(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'FECHA01');
$this->assertStatusEqualsCode(Status::none(), 'FECHA02');
}
public function testValidateEmptyFecha(): void
{
$this->comprobante->addAttributes([
'Fecha' => '',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'FECHA01');
$this->assertStatusEqualsCode(Status::none(), 'FECHA02');
}
public function testValidateMalformedFecha(): void
{
$this->comprobante->addAttributes([
'Fecha' => 'YYYY-MM-DD hh:mm:ss',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'FECHA01');
$this->assertStatusEqualsCode(Status::none(), 'FECHA02');
}
public function testValidateOlderFecha(): void
{
$this->comprobante->addAttributes([
'Fecha' => '2017-06-30T23:59:59',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'FECHA01');
$this->assertStatusEqualsCode(Status::error(), 'FECHA02');
}
public function testValidateFutureFecha(): void
{
$this->comprobante->addAttributes([
'Fecha' => Format::datetime($this->validator->getMaximumDate() + 1),
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'FECHA01');
$this->assertStatusEqualsCode(Status::error(), 'FECHA02');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ReceptorResidenciaFiscalTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ReceptorResidenciaFiscalTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\ReceptorResidenciaFiscal;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ReceptorResidenciaFiscalTest extends Validate33TestCase
{
/** @var ReceptorResidenciaFiscal */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ReceptorResidenciaFiscal();
}
public function providerValidCases(): array
{
return [
// RESFISC01: Si el RFC no es XEXX010101000 entonces la residencia fiscal no debe existir
[null, null, null, false, 'RESFISC01'],
['', null, null, false, 'RESFISC01'],
['XXXXXXXXXXXX', null, null, false, 'RESFISC01'],
// RESFISC02: Si el RFC sí es XEXX010101000 y existe el complemento de comercio exterior
// entonces la residencia fiscal debe establecerse y no puede ser "MEX"
['XEXX010101000', 'XXX', null, true, 'RESFISC02'],
// RESFISC03: Si el RFC sí es XEXX010101000 y se registró el número de registro de identificación fiscal
// entonces la residencia fiscal debe establecerse y no puede ser "MEX"
['XEXX010101000', 'XXX', '1234', false, 'RESFISC03'],
];
}
/**
* @dataProvider providerValidCases
*/
public function testValidCase(
?string $receptorRfc,
?string $residenciaFiscal,
?string $numRegIdTrib,
bool $putComercioExterior,
string $ok,
): void {
$this->comprobante->addChild(new Node('cfdi:Receptor', [
'Rfc' => $receptorRfc,
'ResidenciaFiscal' => $residenciaFiscal,
'NumRegIdTrib' => $numRegIdTrib,
]));
if ($putComercioExterior) {
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [
new Node('cce11:ComercioExterior'),
]));
}
$this->runValidate();
$this->assertFalse($this->asserts->hasErrors());
$this->assertStatusEqualsCode(Status::ok(), $ok);
}
public function providerInvalidCases(): array
{
return [
// RESFISC01: Si el RFC no es XEXX010101000 entonces la residencia fiscal no debe existir
[null, '', null, false, 'RESFISC01'],
['', '', null, false, 'RESFISC01'],
['XXXXXXXXXXXX', '', null, false, 'RESFISC01'],
[null, 'GER', null, false, 'RESFISC01'],
['', 'GER', null, false, 'RESFISC01'],
['XXXXXXXXXXXX', 'GER', null, false, 'RESFISC01'],
// RESFISC02: Si el RFC sí es XEXX010101000 y existe el complemento de comercio exterior
// entonces la residencia fiscal debe establecerse y no puede ser "MEX"
['XEXX010101000', null, null, true, 'RESFISC02'],
['XEXX010101000', '', null, true, 'RESFISC02'],
['XEXX010101000', 'MEX', null, true, 'RESFISC02'],
// RESFISC03: Si el RFC sí es XEXX010101000 y se registró el número de registro de identificación fiscal
// entonces la residencia fiscal debe establecerse y no puede ser "MEX"
['XEXX010101000', null, '1234', false, 'RESFISC03'],
['XEXX010101000', '', '1234', false, 'RESFISC03'],
['XEXX010101000', 'MEX', '1234', false, 'RESFISC03'],
];
}
/**
* @dataProvider providerInvalidCases
*/
public function testInvalidCase(
?string $receptorRfc,
?string $residenciaFiscal,
?string $numRegIdTrib,
bool $putComercioExterior,
string $error,
): void {
$this->comprobante->addChild(new Node('cfdi:Receptor', [
'Rfc' => $receptorRfc,
'ResidenciaFiscal' => $residenciaFiscal,
'NumRegIdTrib' => $numRegIdTrib,
]));
if ($putComercioExterior) {
$this->comprobante->addChild(new Node('cfdi:Complemento', [], [
new Node('cce11:ComercioExterior'),
]));
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), $error);
}
public function testValidCaseWithoutReceptorNode(): void
{
$this->runValidate();
$this->assertFalse($this->asserts->hasErrors());
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteImpuestosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteImpuestosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteImpuestos;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteImpuestosTest extends Validate33TestCase
{
/** @var ComprobanteImpuestos */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteImpuestos();
}
/**
* @testWith [true, false]
* [false, true]
* [true, true]
*/
public function testValidImpuestos(bool $putTraslados, bool $putRetenciones): void
{
$nodeImpuestos = new Node('cfdi:Impuestos');
if ($putTraslados) {
$nodeImpuestos['TotalImpuestosTrasladados'] = '';
$nodeImpuestos->addChild(new Node('cfdi:Traslados', [], [new Node('cfdi:Traslado')]));
}
if ($putRetenciones) {
$nodeImpuestos['TotalImpuestosRetenidos'] = '';
$nodeImpuestos->addChild(new Node('cfdi:Retenciones', [], [new Node('cfdi:Retencion')]));
}
$this->comprobante->addChild($nodeImpuestos);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPIMPUESTOSC01');
$this->assertStatusEqualsCode(Status::ok(), 'COMPIMPUESTOSC02');
$this->assertStatusEqualsCode(Status::ok(), 'COMPIMPUESTOSC03');
}
public function testInvalidWithEmptyImpuestos(): void
{
$this->comprobante->addChild(new Node('cfdi:Impuestos'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'COMPIMPUESTOSC01');
}
public function testInvalidTrasladosNodesWithoutTotalTraslados(): void
{
$this->comprobante->addChild(new Node(
'cfdi:Impuestos',
[],
[new Node('cfdi:Traslados', [], [new Node('cfdi:Traslado')])]
));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'COMPIMPUESTOSC02');
}
public function testValidTotalTrasladosWithoutTrasladosNodes(): void
{
$this->comprobante->addChild(new Node(
'cfdi:Impuestos',
['TotalImpuestosTrasladados' => '']
));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPIMPUESTOSC02');
}
public function testInvalidRetencionesNodesWithoutTotalRetenciones(): void
{
$this->comprobante->addChild(new Node(
'cfdi:Impuestos',
[],
[new Node('cfdi:Retenciones', [], [new Node('cfdi:Retencion')])]
));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'COMPIMPUESTOSC03');
}
public function testValidTotalRetencionesWithoutRetencionesNodes(): void
{
$this->comprobante->addChild(new Node(
'cfdi:Impuestos',
['TotalImpuestosRetenidos' => '']
));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPIMPUESTOSC03');
}
public function testWithoutNodeImpuestos(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'COMPIMPUESTOSC01');
$this->assertStatusEqualsCode(Status::none(), 'COMPIMPUESTOSC02');
$this->assertStatusEqualsCode(Status::none(), 'COMPIMPUESTOSC03');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/SumasConceptosComprobanteImpuestosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/SumasConceptosComprobanteImpuestosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\SumasConceptosComprobanteImpuestos;
use CfdiUtils\Validate\Contracts\DiscoverableCreateInterface;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class SumasConceptosComprobanteImpuestosTest extends Validate33TestCase
{
/** @var SumasConceptosComprobanteImpuestos */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new SumasConceptosComprobanteImpuestos();
}
public function testObjectSpecification(): void
{
$this->assertInstanceOf(DiscoverableCreateInterface::class, $this->validator);
$this->assertTrue($this->validator->canValidateCfdiVersion('3.3'));
}
public function testValidateOk(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$this->runValidate();
// all asserts
foreach ($this->asserts as $assert) {
$this->assertStatusEqualsAssert(Status::ok(), $assert);
}
// total expected count: 12 regular + 2 extras
$this->assertCount(14, $this->asserts, 'All 14 expected asserts were are tested');
}
public function testValidateBadSubtotal(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$this->comprobante['SubTotal'] = '123.45';
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS01');
}
public function testValidateUnsetSubtotal(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
unset($this->comprobante['SubTotal']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS01');
}
public function testValidateBadDescuentos(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$this->comprobante['Descuento'] = '123.45';
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS02');
}
public function testValidateBadTotal(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$this->comprobante['Total'] = '123.45';
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS03');
}
public function testValidateUnsetTotal(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
unset($this->comprobante['Total']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS03');
}
public function testValidateUnsetImpuestos(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$impuestos = $this->comprobante->searchNode('cfdi:Impuestos');
if (null !== $impuestos) {
$this->comprobante->children()->remove($impuestos);
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS04');
$this->assertStatusEqualsCode(Status::error(), 'SUMAS05');
$this->assertStatusEqualsCode(Status::error(), 'SUMAS06');
$this->assertStatusEqualsCode(Status::error(), 'SUMAS08');
$this->assertStatusEqualsCode(Status::error(), 'SUMAS09');
$this->assertStatusEqualsCode(Status::error(), 'SUMAS10');
}
public function testValidateUnsetTotalImpuestosTrasladados(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
if (null !== $impuestos = $this->comprobante->searchNode('cfdi:Impuestos')) {
$impuestos['TotalImpuestosTrasladados'] = '123456.78';
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS04');
}
public function testValidateUnsetOneImpuestosTrasladados(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$traslados = $this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Traslados');
if (null !== $traslados) {
$traslado = $traslados->searchNode('cfdi:Traslado');
if (null !== $traslado) {
$traslados->children()->remove($traslado);
}
}
$this->assertNull($this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Traslados', 'cfdi:Traslado'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS05');
}
public function testValidateBadOneImpuestosTrasladados(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$traslados = $this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Traslados');
if (null !== $traslados) {
$traslado = $traslados->searchNode('cfdi:Traslado');
if (null !== $traslado) {
$traslado['Importe'] = '123456.78';
}
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS06');
}
public function testValidateMoreImpuestosTrasladados(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$traslados = $this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Traslados');
if (null !== $traslados) {
$traslados->addChild(new Node('cfdi:Traslado', [
'Base' => '1000.00',
'Impuesto' => 'XXX',
'TipoFactor' => '0.050000',
'TasaOCuota' => 'tasa',
'Importe' => '50.00',
]));
}
$this->runValidate();
$assert = $this->getAssertByCodeOrFail('SUMAS07');
$this->assertTrue($assert->getStatus()->isError());
$this->assertEquals(
'No encontrados: 1 impuestos. Impuesto: XXX, TipoFactor: 0.050000, TasaOCuota: tasa, Importe: 50.00.',
$assert->getExplanation()
);
}
public function testValidateUnsetTotalImpuestosRetenidos(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$impuestos = $impuestos = $this->comprobante->searchNode('cfdi:Impuestos');
if (null !== $impuestos) {
$impuestos['TotalImpuestosRetenidos'] = '123456.78';
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS08');
}
public function testValidateUnsetOneImpuestosRetenidos(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$retenciones = $this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Retenciones');
if (null !== $retenciones) {
$retencion = $retenciones->searchNode('cfdi:Retencion');
if (null !== $retencion) {
$retenciones->children()->remove($retencion);
}
}
$this->assertNull($this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Retenciones', 'cfdi:Retencion'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS09');
}
public function testValidateBadOneImpuestosRetenidos(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$retenciones = $this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Retenciones');
if (null !== $retenciones) {
$retencion = $retenciones->searchNode('cfdi:Retencion');
if (null !== $retencion) {
$retencion['Importe'] = '123456.78';
}
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS10');
}
public function testValidateMoreImpuestosRetenciones(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$retenciones = $this->comprobante->searchNode('cfdi:Impuestos', 'cfdi:Retenciones');
if (null !== $retenciones) {
$retenciones->addChild(new Node('cfdi:Retencion', [
'Base' => '1000.00',
'Impuesto' => 'XXX',
'TipoFactor' => '0.050000',
'TasaOCuota' => 'tasa',
'Importe' => '50.00',
]));
}
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SUMAS11');
}
public function providerValidateDescuentoLessOrEqualThanSubTotal(): array
{
return [
'greater' => ['12345.679', '12345.678', Status::error()],
'equal' => ['12345.678', '12345.678', Status::ok()],
'less' => ['12345.677', '12345.678', Status::ok()],
'empty' => ['', '12345.678', Status::ok()],
'zeros' => ['0.00', '0.00', Status::ok()],
];
}
/**
* @dataProvider providerValidateDescuentoLessOrEqualThanSubTotal
*/
public function testValidateDescuentoLessOrEqualThanSubTotal(
string $descuento,
string $subtotal,
Status $expected,
): void {
$this->comprobante->addAttributes([
'SubTotal' => $subtotal,
'Descuento' => $descuento,
]);
$this->runValidate();
$this->assertStatusEqualsCode($expected, 'SUMAS12');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/EmisorRegimenFiscalTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/EmisorRegimenFiscalTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\EmisorRegimenFiscal;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class EmisorRegimenFiscalTest extends Validate33TestCase
{
/** @var EmisorRegimenFiscal */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new EmisorRegimenFiscal();
}
public function providerValidCases(): array
{
return[
// personas morales
['AAA010101AAA', '601'],
['AAA010101AAA', '603'],
['AAA010101AAA', '609'],
['AAA010101AAA', '610'],
['AAA010101AAA', '620'],
['AAA010101AAA', '622'],
['AAA010101AAA', '623'],
['AAA010101AAA', '624'],
['AAAA010101AA', '626'],
['AAA010101AAA', '628'],
['ÑAA010101AAA', '601'], // with Ñ
// personas físicas
['AAAA010101AAA', '605'],
['AAAA010101AAA', '606'],
['AAAA010101AAA', '607'],
['AAAA010101AAA', '608'],
['AAAA010101AAA', '610'],
['AAAA010101AAA', '611'],
['AAAA010101AAA', '612'],
['AAAA010101AAA', '614'],
['AAAA010101AAA', '615'],
['AAAA010101AAA', '616'],
['AAAA010101AAA', '621'],
['AAAA010101AAA', '625'],
['AAAA010101AAA', '629'],
['AAAA010101AAA', '630'],
['AAAA010101AAA', '626'], // regimen RESICO
['AAAA010101AAA', '615'],
['ÑAAA010101AAA', '605'], // with Ñ
['AAA010000AAA', '601'], // RFC inválido, regimen válido persona moral
['AAAA010000AAA', '605'], // RFC inválido, regimen válido persona física
];
}
/**
* @dataProvider providerValidCases
*/
public function testValidCases(string $emisorRfc, string $regimenFiscal): void
{
$this->comprobante->addChild(new Node('cfdi:Emisor', [
'RegimenFiscal' => $regimenFiscal,
'Rfc' => $emisorRfc,
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'REGFIS01');
}
public function providerInvalidCases(): array
{
return [
['AAA010101AAA', '605'], // persona moral con regimen incorrecto
['AAAA010101AAA', '601'], // persona física con regimen incorrecto
['', '615'], // RFC vacío, con regimen
['', ''], // RFC vacío, regimen vacío
[null, ''], // sin RFC, regimen vacío
[null, '630'], // sin RFC, con regimen
[null, null], // sin RFC, sin regimen
];
}
/**
* @dataProvider providerInvalidCases
*/
public function testInvalidCases(?string $emisorRfc, ?string $regimenFiscal): void
{
$this->comprobante->addChild(new Node('cfdi:Emisor', [
'RegimenFiscal' => $regimenFiscal,
'Rfc' => $emisorRfc,
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'REGFIS01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/EmisorRfcTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/EmisorRfcTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Utils\Rfc;
use CfdiUtils\Validate\Cfdi33\Standard\EmisorRfc;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class EmisorRfcTest extends Validate33TestCase
{
/** @var EmisorRfc */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new EmisorRfc();
}
public function providerValidCases(): array
{
return [
'person' => ['COSC8001137NA'],
'moral' => ['DIM8701081LA'],
];
}
/**
* @dataProvider providerValidCases
*/
public function testValidCases(string $rfc): void
{
$this->comprobante->addChild(new Node('cfdi:Emisor', [
'Rfc' => $rfc,
]));
$this->runValidate();
$this->assertFalse($this->asserts->hasErrors());
$this->assertStatusEqualsCode(Status::ok(), 'EMISORRFC01');
}
public function providerInvalidCases(): array
{
return [
'none' => [null],
'empty' => [''],
'wrong' => ['COSC8099137NA'],
'generic' => [Rfc::RFC_GENERIC],
'foreign' => [Rfc::RFC_FOREIGN],
];
}
/**
* @dataProvider providerInvalidCases
*/
public function testInvalidCases(?string $rfc): void
{
$this->comprobante->addChild(new Node('cfdi:Emisor', [
'Rfc' => $rfc,
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'EMISORRFC01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/SelloDigitalCertificadoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/SelloDigitalCertificadoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\SelloDigitalCertificado;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Common\SelloDigitalCertificadoWithRegularCertificadoTrait;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class SelloDigitalCertificadoTest extends Validate33TestCase
{
use SelloDigitalCertificadoWithRegularCertificadoTrait;
/** @var SelloDigitalCertificado */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new SelloDigitalCertificado();
$this->hydrater->hydrate($this->validator);
}
public function testObjectVersion(): void
{
$this->assertTrue($this->validator->canValidateCfdiVersion('3.3'));
}
public function testValidateBadSello(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$this->comprobante['Sello'] = $this->comprobante['Certificado'];
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'SELLO08');
}
public function testValidateOk(): void
{
$this->setupCfdiFile('cfdi33-valid.xml');
$this->runValidate();
foreach (range(1, 8) as $i) {
$this->assertStatusEqualsCode(Status::ok(), 'SELLO0' . $i);
}
$this->assertCount(8, $this->asserts, 'All 8 were are tested');
}
public function testValidateWithEqualButNotIdenticalName(): void
{
// change case, and punctuation to original name
// ESCUELA KEMPER URGATE SA DE CV
$this->setUpCertificado([], [
'Nombre' => 'ESCUELA "Kemper Urgate", S.A. DE C.V.',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'SELLO04');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteDecimalesMonedaTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteDecimalesMonedaTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteDecimalesMoneda;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteDecimalesMonedaTest extends Validate33TestCase
{
/** @var ComprobanteDecimalesMoneda */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteDecimalesMoneda();
}
public function testUnknownCurrency(): void
{
$this->comprobante['Moneda'] = 'LYD'; // Dinar libio
$this->runValidate();
foreach ($this->asserts as $assert) {
$this->assertStatusEqualsStatus(Status::none(), $assert->getStatus());
}
}
public function testAllAssertsAreOk(): void
{
$this->comprobante->addAttributes([
'Moneda' => 'MXN',
'SubTotal' => '123',
'Descuento' => '1.2',
'Total' => '999.99',
]);
$this->comprobante->addChild(new Node('cfdi:Impuestos', [
'TotalImpuestosTrasladados' => '1.23',
'TotalImpuestosRetenidos' => '1.23',
], [
new Node('cfdi:Traslados', [], [
new Node('cfdi:Traslado', ['Importe' => '123.45']),
]),
new Node('cfdi:Retenciones', [], [
new Node('cfdi:Retencion', ['Importe' => '123.45']),
]),
]));
$this->runValidate();
foreach ($this->asserts as $assert) {
$this->assertStatusEqualsAssert(Status::ok(), $assert);
}
}
public function testAllAssertsMissingAttributes(): void
{
$this->comprobante->addAttributes([
'Moneda' => 'MXN',
]);
$this->comprobante->addChild(new Node('cfdi:Impuestos', [
], [
new Node('cfdi:Traslados', [], [
new Node('cfdi:Traslado'),
]),
new Node('cfdi:Retenciones', [], [
new Node('cfdi:Retencion'),
]),
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'MONDEC01');
$this->assertStatusEqualsCode(Status::ok(), 'MONDEC02');
$this->assertStatusEqualsCode(Status::error(), 'MONDEC03');
$this->assertStatusEqualsCode(Status::ok(), 'MONDEC04');
$this->assertStatusEqualsCode(Status::ok(), 'MONDEC05');
}
public function testAllAssertAreError(): void
{
$this->comprobante->addAttributes([
'Moneda' => 'MXN',
'SubTotal' => '123.000',
'Descuento' => '123.000',
'Total' => '123.000',
]);
$this->comprobante->addChild(new Node('cfdi:Impuestos', [
'TotalImpuestosTrasladados' => '123.000',
'TotalImpuestosRetenidos' => '123.000',
], [
new Node('cfdi:Traslados', [], [
new Node('cfdi:Traslado', ['Importe' => '123.00']),
new Node('cfdi:Traslado', ['Importe' => '123.000']),
]),
new Node('cfdi:Retenciones', [], [
new Node('cfdi:Retencion', ['Importe' => '123.00']),
new Node('cfdi:Retencion', ['Importe' => '123.000']),
]),
]));
$this->runValidate();
foreach ($this->asserts as $assert) {
$this->assertStatusEqualsAssert(Status::error(), $assert);
}
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteTipoCambioTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteTipoCambioTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteTipoCambio;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteTipoCambioTest extends Validate33TestCase
{
/** @var ComprobanteTipoCambio */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteTipoCambio();
}
public function providerMonedaWithValidValues(): array
{
return [
['MXN', '1', 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['MXN', '1.000000', 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['MXN', null, 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['XXX', null, 'TIPOCAMBIO03', ['TIPOCAMBIO02', 'TIPOCAMBIO04']],
['USD', '10.0', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '20', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '0005.10000', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '123456789012345678.0', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '0.123456', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
];
}
/**
* @param string[] $nones
* @dataProvider providerMonedaWithValidValues
*/
public function testMonedaWithValidValues(string $moneda, ?string $tipoCambio, string $ok, array $nones): void
{
$this->comprobante->addAttributes([
'Moneda' => $moneda,
'TipoCambio' => $tipoCambio,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCAMBIO01');
$this->assertStatusEqualsCode(Status::ok(), $ok);
foreach ($nones as $none) {
$this->assertStatusEqualsCode(Status::none(), $none);
}
}
public function providerNoMonedaOrEmpty(): array
{
return [
[null, null],
[null, ''],
[null, '18.9000'],
['', null],
['', ''],
['', '18.9000'],
];
}
/**
* @dataProvider providerNoMonedaOrEmpty
*/
public function testNoMonedaOrEmpty(?string $moneda, ?string $tipoCambio): void
{
$this->comprobante->addAttributes([
'Moneda' => $moneda,
'TipoCambio' => $tipoCambio,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCAMBIO01');
$this->assertStatusEqualsCode(Status::none(), 'TIPOCAMBIO02');
$this->assertStatusEqualsCode(Status::none(), 'TIPOCAMBIO03');
$this->assertStatusEqualsCode(Status::none(), 'TIPOCAMBIO04');
}
public function providerMonedaWithInvalidValues(): array
{
return [
['MXN', '', 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['MXN', '1.000001', 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['MXN', '0.999999', 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['MXN', '10.0', 'TIPOCAMBIO02', ['TIPOCAMBIO03', 'TIPOCAMBIO04']],
['XXX', '', 'TIPOCAMBIO03', ['TIPOCAMBIO02', 'TIPOCAMBIO04']],
['XXX', '10.0', 'TIPOCAMBIO03', ['TIPOCAMBIO02', 'TIPOCAMBIO04']],
['USD', null, 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', 'abc', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '1234567890123456789.0', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '0.1234567', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '0.', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '.0', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '0..0', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
['USD', '0.0.0', 'TIPOCAMBIO04', ['TIPOCAMBIO02', 'TIPOCAMBIO03']],
];
}
/**
* @param string[] $nones
* @dataProvider providerMonedaWithInvalidValues
*/
public function testMonedaWithInvalidValues(string $moneda, ?string $tipoCambio, string $error, array $nones): void
{
$this->comprobante->addAttributes([
'Moneda' => $moneda,
'TipoCambio' => $tipoCambio,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCAMBIO01');
$this->assertStatusEqualsCode(Status::error(), $error);
foreach ($nones as $none) {
$this->assertStatusEqualsCode(Status::none(), $none);
}
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ConceptoDescuentoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ConceptoDescuentoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\ConceptoDescuento;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ConceptoDescuentoTest extends Validate33TestCase
{
/** @var ConceptoDescuento */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ConceptoDescuento();
}
public function providerValidCases(): array
{
return[
['', '0'],
['0', '1'],
['1', '1'],
['0.000000', '0.000001'],
['0', '0'],
['1.00', '1.01'],
];
}
/**
* @dataProvider providerValidCases
*/
public function testValidCases(string $descuento, string $importe): void
{
$this->getComprobante()->addConcepto([
'Descuento' => $descuento,
'Importe' => $importe,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'CONCEPDESC01');
}
public function providerInvalidCases(): array
{
return[
['1', '0'],
['5', null],
['0.000001', '0.000000'],
['-1', '5'],
['-5', '5'],
];
}
/**
* @dataProvider providerInvalidCases
*/
public function testInvalidCases(string $descuento, ?string $importe): void
{
$this->getComprobante()->addConcepto(['Descuento' => '1', 'Importe' => '2']);
$concepto = $this->getComprobante()->addConcepto([
'Descuento' => $descuento,
'Importe' => $importe,
]);
$this->assertTrue($this->validator->conceptoHasInvalidDiscount($concepto));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPDESC01');
}
public function testNoneCase(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'CONCEPDESC01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ReceptorRfcTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ReceptorRfcTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Utils\Rfc;
use CfdiUtils\Validate\Cfdi33\Standard\ReceptorRfc;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ReceptorRfcTest extends Validate33TestCase
{
/** @var ReceptorRfc */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ReceptorRfc();
}
public function providerValidCases(): array
{
return [
'generic' => [Rfc::RFC_GENERIC],
'foreign' => [Rfc::RFC_FOREIGN],
'person' => ['COSC8001137NA'],
'moral' => ['DIM8701081LA'],
];
}
/**
* @dataProvider providerValidCases
*/
public function testValidCases(string $rfc): void
{
$this->comprobante->addChild(new Node('cfdi:Receptor', [
'Rfc' => $rfc,
]));
$this->runValidate();
$this->assertFalse($this->asserts->hasErrors());
$this->assertStatusEqualsCode(Status::ok(), 'RECRFC01');
}
public function providerInvalidCases(): array
{
return [
'none' => [null],
'empty' => [''],
'wrong' => ['COSC8099137NA'],
];
}
/**
* @dataProvider providerInvalidCases
*/
public function testInvalidCases(?string $rfc): void
{
$this->comprobante->addChild(new Node('cfdi:Receptor', [
'Rfc' => $rfc,
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'RECRFC01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ConceptoImpuestosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ConceptoImpuestosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Elements\Cfdi33\Comprobante;
use CfdiUtils\Validate\Cfdi33\Standard\ConceptoImpuestos;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ConceptoImpuestosTest extends Validate33TestCase
{
/** @var ConceptoImpuestos */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ConceptoImpuestos();
}
public function testInvalidCaseNoRetencionOrTraslado(): void
{
$comprobante = $this->validComprobante();
$comprobante->addConcepto()->getImpuestos();
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPIMPC01');
}
public function providerInvalidBaseTraslado(): array
{
return [
['0'],
['0.0000001'],
['-1'],
['foo'],
['0.0.0.0'],
];
}
/**
* @dataProvider providerInvalidBaseTraslado
*/
public function testTrasladoHasBaseGreaterThanZeroInvalidCase(string $base): void
{
$comprobante = $this->validComprobante();
$comprobante->addConcepto()->addTraslado(['Base' => $base]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPIMPC02');
}
public function providerTrasladoTipoFactorExento(): array
{
return[
['1', '1'],
[null, '1'],
['1', null],
];
}
/**
* @dataProvider providerTrasladoTipoFactorExento
*/
public function testTrasladoTipoFactorExentoInvalidCase(?string $tasaOCuota, ?string $importe): void
{
$comprobante = $this->validComprobante();
$comprobante->addConcepto()->addTraslado([
'TipoFactor' => 'Exento',
'TasaOCuota' => $tasaOCuota,
'Importe' => $importe,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPIMPC03');
}
public function providerTrasladosTipoFactorTasaOCuotaInvalidCase(): array
{
return $this->providerFullJoin(
[['Tasa'], ['Cuota']], // tipoFactor
[['1'], [''], [null]], // tasaOCuota
[[''], [null]] // importe
);
}
/**
* @dataProvider providerTrasladosTipoFactorTasaOCuotaInvalidCase
*/
public function testTrasladosTipoFactorTasaOCuotaInvalidCase(
string $tipoFactor,
?string $tasaOCuota,
?string $importe,
): void {
$comprobante = $this->validComprobante();
$comprobante->addConcepto()->addTraslado([
'TipoFactor' => $tipoFactor,
'TasaOCuota' => $tasaOCuota,
'Importe' => $importe,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPIMPC04');
}
public function providerInvalidBaseRetencion(): array
{
return[
['0'],
['0.0000001'],
['-1'],
['foo'],
['0.0.0.0'],
];
}
/**
* @dataProvider providerInvalidBaseTraslado
*/
public function testRetencionesHasBaseGreaterThanZeroInvalidCase(string $base): void
{
$comprobante = $this->validComprobante();
$comprobante->addConcepto()->addRetencion(['Base' => $base]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPIMPC05');
}
public function testInvalidCaseRetencionTipoFactorExento(): void
{
$comprobante = $this->validComprobante();
$comprobante->addConcepto()->addRetencion(['TipoFactor' => 'Exento']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'CONCEPIMPC06');
}
public function testValidComprobante(): void
{
$this->validComprobante();
$this->runValidate();
$this->assertFalse($this->asserts->hasErrors());
}
private function validComprobante(): Comprobante
{
/** @var Comprobante $comprobante */
$comprobante = $this->comprobante;
$comprobante->addConcepto();
$comprobante->addConcepto()->multiTraslado([
'TipoFactor' => 'Exento',
'Base' => '123.45',
], [
'Base' => '123.45',
'TipoFactor' => 'Tasa',
'TasaOCuota' => '0.160000',
'Importe' => '19.75',
])->multiRetencion([
'Base' => '0.000001',
'TipoFactor' => 'Tasa',
'TasaOCuota' => '0.02',
'Importe' => '1.23',
], [
'Base' => '123.45',
'TipoFactor' => 'Cuota',
]);
return $comprobante;
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/TimbreFiscalDigitalVersionTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/TimbreFiscalDigitalVersionTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\TimbreFiscalDigitalVersion;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtilsTests\Validate\Common\TimbreFiscalDigital11VersionTestTrait;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class TimbreFiscalDigitalVersionTest extends Validate33TestCase
{
use TimbreFiscalDigital11VersionTestTrait;
/** @var TimbreFiscalDigitalVersion */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new TimbreFiscalDigitalVersion();
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteTipoDeComprobanteTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteTipoDeComprobanteTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteTipoDeComprobante;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteTipoDeComprobanteTest extends Validate33TestCase
{
/** @var ComprobanteTipoDeComprobante */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteTipoDeComprobante();
}
public function providerTPN(): array
{
return [['T'], ['P'], ['N']];
}
/**
* @dataProvider providerTPN
*/
public function testValidTPN(string $tipoDeComprobante): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP01');
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP02');
}
/**
* @dataProvider providerTPN
*/
public function testInvalidTPN(string $tipoDeComprobante): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
'CondicionesDePago' => '',
'FormaPago' => '',
'MetodoPago' => '',
]);
$this->comprobante->addChild(new Node('cfdi:Impuestos'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP01');
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP02');
}
public function providerTP(): array
{
return [['T'], ['P']];
}
/**
* @dataProvider providerTP
*/
public function testValidTP(string $tipoDeComprobante): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
'FormaPago' => null, // set to null to make clear that it must not exists
'MetodoPago' => null, // set to null to make clear that it must not exists
'SubTotal' => '0',
'Total' => '0.00',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP03');
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP04');
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP05');
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP06');
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP07');
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP08');
}
/**
* @dataProvider providerTP
*/
public function testInvalidTP(string $tipoDeComprobante): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
'FormaPago' => '',
'MetodoPago' => '',
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP03');
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP04');
}
/**
* @dataProvider providerTP
*/
public function testInvalidTPDescuentos(string $tipoDeComprobante): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
'Descuento' => '',
]);
$this->comprobante->addChild(new Node('cfdi:Conceptos', [], [
new Node('cfdi:Concepto'),
new Node('cfdi:Concepto', ['Descuento' => '']),
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP05');
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP06');
}
public function providerTPNonZero(): array
{
$types = [
['T'],
['P'],
];
$values = [
[null],
[''],
['0.000001'],
['123.45'],
['foo'],
];
return $this->providerFullJoin($types, $values);
}
/**
* @dataProvider providerTPNonZero
*/
public function testInvalidSubTotal(string $tipoDeComprobante, ?string $subtotal): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
'SubTotal' => $subtotal,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP07');
}
/**
* @dataProvider providerTPNonZero
*/
public function testInvalidTotal(string $tipoDeComprobante, ?string $total): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
'Total' => $total,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP08');
}
public function providerIEN(): array
{
return [['I'], ['E'], ['N']];
}
/**
* @dataProvider providerIEN
*/
public function testValidIENValorUnitarioGreaterThanZero(string $tipoDeComprobante): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
]);
$this->comprobante->addChild(new Node('cfdi:Conceptos', [], [
new Node('cfdi:Concepto', ['ValorUnitario' => '123.45']),
new Node('cfdi:Concepto', ['ValorUnitario' => '0.000001']),
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'TIPOCOMP09');
}
public function providerIENWrongValue(): array
{
return $this->providerFullJoin(
$this->providerIEN(),
[[null], [''], ['0'], ['0.00'], ['0.0000001']]
);
}
/**
* @dataProvider providerIENWrongValue
*/
public function testInvalidIENValorUnitarioGreaterThanZero(string $tipoDeComprobante, ?string $wrongUnitValue): void
{
$this->comprobante->addAttributes([
'TipoDeComprobante' => $tipoDeComprobante,
]);
$this->comprobante->addChild(new Node('cfdi:Conceptos', [], [
new Node('cfdi:Concepto', ['ValorUnitario' => '123.45']),
new Node('cfdi:Concepto', [
'ValorUnitario' => $wrongUnitValue,
]),
]));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'TIPOCOMP09');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteFormaPagoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/ComprobanteFormaPagoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\Standard\ComprobanteFormaPago;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComprobanteFormaPagoTest extends Validate33TestCase
{
/** @var ComprobanteFormaPago */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobanteFormaPago();
}
public function testValidateNothingWhenNotFormaPagoAndNotComplementoPago(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'FORMAPAGO01');
}
public function testValidateNothingWhenFormaPagoAndNotComplementoPago(): void
{
$this->comprobante['FormaPago'] = '01'; // efectivo
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'FORMAPAGO01');
}
public function testValidateOkWhenNotFormaPagoAndComplementoPago(): void
{
$this->comprobante
->addChild(new Node('cfdi:Complemento'))
->addChild(new Node('pago10:Pagos'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'FORMAPAGO01');
}
public function testValidateErrorWhenFormaPagoAndComplementoPago(): void
{
$this->comprobante['FormaPago'] = '01'; // efectivo
$this->comprobante
->addChild(new Node('cfdi:Complemento'))
->addChild(new Node('pago10:Pagos'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'FORMAPAGO01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/TimbreFiscalDigitalSelloTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/TimbreFiscalDigitalSelloTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\TimbreFiscalDigitalSello;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtilsTests\Validate\Common\TimbreFiscalDigital11SelloTestTrait;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class TimbreFiscalDigitalSelloTest extends Validate33TestCase
{
use TimbreFiscalDigital11SelloTestTrait;
/** @var TimbreFiscalDigitalSello */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new TimbreFiscalDigitalSello();
$this->hydrater->hydrate($this->validator);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/Standard/SelloDigitalCertificadoWithCfdiRegistroFiscalTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/Standard/SelloDigitalCertificadoWithCfdiRegistroFiscalTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\Standard;
use CfdiUtils\Validate\Cfdi33\Standard\SelloDigitalCertificado;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtilsTests\Validate\Common\SelloDigitalCertificadoWithCfdiRegistroFiscalTrait;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class SelloDigitalCertificadoWithCfdiRegistroFiscalTest extends Validate33TestCase
{
use SelloDigitalCertificadoWithCfdiRegistroFiscalTrait;
/** @var SelloDigitalCertificado */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new SelloDigitalCertificado();
$this->hydrater->hydrate($this->validator);
$cerfile = $this->utilAsset('certs/00001000000403258748.cer');
$this->setUpCertificado([], [
'Nombre' => 'CARLOS CORTES SOTO',
'Rfc' => 'COSC8001137NA',
], $cerfile);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ConceptosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ConceptosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Elements\Cfdi33\Concepto;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Conceptos;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
final class ConceptosTest extends ValidateComplementoPagosTestCase
{
/** @var Conceptos */
protected ValidatorInterface $validator;
protected Concepto $concepto;
protected function setUp(): void
{
parent::setUp();
$this->validator = new Conceptos();
// setup a valid case and in the test change to make it fail
$comprobante = $this->getComprobante();
$this->concepto = $comprobante->addConcepto([
'ClaveProdServ' => Conceptos::REQUIRED_CLAVEPRODSERV,
'ClaveUnidad' => Conceptos::REQUIRED_CLAVEUNIDAD,
'Descripcion' => Conceptos::REQUIRED_DESCRIPCION,
'Cantidad' => Conceptos::REQUIRED_CANTIDAD,
'ValorUnitario' => Conceptos::REQUIRED_VALORUNITARIO,
'Importe' => Conceptos::REQUIRED_IMPORTE,
]);
}
public function testValidCase(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'PAGCON01');
}
public function testConceptosNotExists(): void
{
$comprobante = $this->getComprobante();
$comprobante->children()->remove($comprobante->getConceptos());
$this->runValidate();
$assert = $this->getAssertByCodeOrFail('PAGCON01');
$this->assertStatusEqualsAssert(Status::error(), $assert);
$this->assertStringContainsString('No se encontró el nodo Conceptos', $assert->getExplanation());
}
public function testConceptosZeroChildren(): void
{
$comprobante = $this->getComprobante();
$comprobante->getConceptos()->children()->removeAll();
$this->runValidate();
$assert = $this->getAssertByCodeOrFail('PAGCON01');
$this->assertStatusEqualsAssert(Status::error(), $assert);
$this->assertStringContainsString('Se esperaba encontrar un solo hijo de conceptos', $assert->getExplanation());
}
public function testConceptosChildrenMoreThanOne(): void
{
$comprobante = $this->getComprobante();
$comprobante->addConcepto();
$this->runValidate();
$assert = $this->getAssertByCodeOrFail('PAGCON01');
$this->assertStatusEqualsAssert(Status::error(), $assert);
$this->assertStringContainsString('Se esperaba encontrar un solo hijo de conceptos', $assert->getExplanation());
}
public function testConceptosChildIsNotConcepto(): void
{
$comprobante = $this->getComprobante();
$conceptos = $comprobante->getConceptos();
$conceptos->children()->removeAll();
$conceptos->addChild(new Node('cfdi:foo'));
$this->runValidate();
$assert = $this->getAssertByCodeOrFail('PAGCON01');
$this->assertStatusEqualsAssert(Status::error(), $assert);
$this->assertStringContainsString('No se encontró el nodo Concepto', $assert->getExplanation());
}
public function testConceptoWithChildren(): void
{
$this->concepto->addChild(new Node('cfdi:foo'));
$this->runValidate();
$assert = $this->getAssertByCodeOrFail('PAGCON01');
$this->assertStatusEqualsAssert(Status::error(), $assert);
$this->assertStringContainsString('Se esperaba encontrar ningún hijo de concepto', $assert->getExplanation());
}
public function providerConceptoInvalidData(): array
{
$second = [
[null],
[''],
['_'],
];
return static::providerFullJoin([
['ClaveProdServ'],
['Cantidad'],
['ClaveUnidad'],
['Descripcion'],
['ValorUnitario'],
['Importe'],
], $second);
}
/**
* @dataProvider providerConceptoInvalidData
*/
public function testConceptoInvalidData(string $attribute, ?string $value): void
{
$this->concepto[$attribute] = $value;
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCON01');
}
public function providerConceptoInvalidDataMustNotExists(): array
{
return [
['NoIdentificacion'],
['Unidad'],
['Descuento'],
];
}
/**
* @dataProvider providerConceptoInvalidDataMustNotExists
*/
public function testConceptoInvalidDataMustNotExists(string $attribute): void
{
$this->concepto[$attribute] = '';
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCON01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ComplementoPagosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ComplementoPagosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Elements\Pagos10\Pagos as PagosElement;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\ComplementoPagos;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class ComplementoPagosTest extends Validate33TestCase
{
/** @var ComplementoPagos */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComplementoPagos();
}
private function setUpComplemento(): PagosElement
{
$comprobante = $this->getComprobante();
$comprobante['TipoDeComprobante'] = 'P';
$pagos = new PagosElement();
$comprobante->addComplemento($pagos);
return $pagos;
}
public function testValidCaseWithComplemento(): void
{
$this->setUpComplemento();
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG01');
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG02');
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG03');
}
public function testValidCaseWithoutComplemento(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG01');
$this->assertStatusEqualsCode(Status::none(), 'COMPPAG02');
$this->assertStatusEqualsCode(Status::none(), 'COMPPAG03');
}
public function testWithoutComplemento(): void
{
$comprobante = $this->getComprobante();
$comprobante['TipoDeComprobante'] = 'P';
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'COMPPAG01');
$this->assertStatusEqualsCode(Status::none(), 'COMPPAG02');
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG03');
}
public function testWithoutTipoDeComprobante(): void
{
$comprobante = $this->getComprobante();
$comprobante->addComplemento(new PagosElement());
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'COMPPAG01');
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG02');
$this->assertStatusEqualsCode(Status::none(), 'COMPPAG03');
}
public function testWithInvalidComprobanteVersion(): void
{
$this->setUpComplemento();
$this->comprobante['Version'] = '3.2';
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG01');
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG02');
$this->assertStatusEqualsCode(Status::error(), 'COMPPAG03');
}
public function testWithInvalidComplementoVersion(): void
{
$complemento = $this->setUpComplemento();
$complemento['Version'] = '0.9';
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG01');
$this->assertStatusEqualsCode(Status::error(), 'COMPPAG02');
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG03');
}
public function testImpuestosMustNotExists(): void
{
$this->setUpComplemento();
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'COMPPAG04');
}
public function testImpuestosMustNotExistsButExists(): void
{
$pagos = $this->setUpComplemento();
$pagos->addChild(new Node('pago10:Impuestos'));
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'COMPPAG04');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/PagoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/PagoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pago;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
final class PagoTest extends ValidateComplementoPagosTestCase
{
/** @var Pago */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new Pago();
}
public function testValidatorsCodes(): void
{
$expectedValidators = [];
foreach (range(2, 22) as $i) {
$expectedValidators[] = sprintf('PAGO%02d', $i);
}
$expectedValidators[] = 'PAGO30';
$validators = $this->validator->getValidators();
$validatorsCodes = [];
foreach ($validators as $validator) {
if ('' !== $validator->getCode()) {
$validatorsCodes[] = $validator->getCode();
}
}
$this->assertEquals($expectedValidators, $validatorsCodes);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/UsoCfdiTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/UsoCfdiTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\UsoCfdi;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
final class UsoCfdiTest extends ValidateComplementoPagosTestCase
{
/** @var UsoCfdi */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new UsoCfdi();
}
public function testValidCase(): void
{
$comprobante = $this->getComprobante();
$comprobante->addReceptor(['UsoCFDI' => 'P01']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'PAGUSO01');
}
public function testInvalidUsoCfdi(): void
{
$comprobante = $this->getComprobante();
$comprobante->addReceptor(['UsoCFDI' => 'P02']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGUSO01');
}
public function testInvalidNoReceptor(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGUSO01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/SamplesTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/SamplesTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\CfdiValidator33;
use CfdiUtils\Validate\Status;
use CfdiUtilsTests\TestCase;
final class SamplesTest extends TestCase
{
/**
* @testWith ["sample-factura123.xml"]
* ["sample-facturador01.xml"]
* ["sample-facturador02.xml"]
* ["sample-validacfd01.xml"]
* ["sample-validacfd02.xml"]
* ["sample-validacfd03.xml"]
* ["sample-validacfd04.xml"]
* ["sample-validacfd05.xml"]
*/
public function testSamplesFiles(string $sampleName): void
{
$sampleFile = $this->utilAsset('pagos10/' . $sampleName);
$this->assertFileExists($sampleFile);
$validator = new CfdiValidator33();
$asserts = $validator->validateXml(strval(file_get_contents($sampleFile)));
// Remove these assertions because we are using manipulated cfdi
$asserts->removeByCode('SELLO08');
$errors = $asserts->errors();
if ([] !== $errors) { // display errors!
echo PHP_EOL, 'source: ', $sampleName;
foreach ($asserts->errors() as $error) {
echo PHP_EOL, ' *** ', strval($error), ' => ', $error->getExplanation();
}
}
$this->assertFalse($asserts->hasErrors());
}
public function testSamplesWithErrors(): void
{
$sampleFile = $this->utilAsset('pagos10/sample-errors.xml');
$this->assertFileExists($sampleFile);
$validator = new CfdiValidator33();
$asserts = $validator->validateXml(strval(file_get_contents($sampleFile)));
// Remove this tests! we are using manipulated cfdi
$asserts->removeByCode('SELLO08');
$asserts->removeByCode('EMISORRFC01');
// Check that this codes are in error state
$expectedErrorCodes = [
'PAGO09', // MontoBetweenIntervalSumOfDocuments
'PAGO09-00',
'PAGO17', // CuentaBeneficiariaProhibida
'PAGO17-00',
'PAGO18', // CuentaBeneficiariaPatron
'PAGO18-00',
'PAGO28', // ImporteSaldoInsolutoValor
'PAGO28-00',
'PAGO28-00-00',
];
foreach ($expectedErrorCodes as $expectedErrorCode) {
$this->assertEquals(Status::error(), $asserts->get($expectedErrorCode)->getStatus());
$asserts->removeByCode($expectedErrorCode);
}
$this->assertFalse($asserts->hasErrors(), 'Asserts has more errors than expected');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/PagosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/PagosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
final class PagosTest extends ValidateComplementoPagosTestCase
{
/** @var Pagos */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new Pagos();
}
public function testValidCase(): void
{
$this->complemento->addPago();
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'PAGOS01');
}
public function testWithoutNodes(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGOS01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ValidateComplementoPagosTestCase.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ValidateComplementoPagosTestCase.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Elements\Pagos10\Pagos as Pagos10;
use CfdiUtilsTests\Validate\Validate33TestCase;
abstract class ValidateComplementoPagosTestCase extends Validate33TestCase
{
protected Pagos10 $complemento;
protected function setUp(): void
{
parent::setUp();
$comprobante = $this->getComprobante();
$comprobante['TipoDeComprobante'] = 'P';
$this->complemento = new Pagos10();
$comprobante->addComplemento($this->complemento);
}
public function testWithoutComplementoDidNotCreateAnyAssertion(): void
{
$this->getComprobante()->children()->removeAll();
$this->runValidate();
$this->assertCount(0, $this->asserts, sprintf(
'The validator %s should not create any assert',
$this->validator::class
));
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/CfdiRelacionadosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/CfdiRelacionadosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\CfdiRelacionados;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
final class CfdiRelacionadosTest extends ValidateComplementoPagosTestCase
{
/** @var CfdiRelacionados */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new CfdiRelacionados();
}
public function testValidTipoRelacion(): void
{
$comprobante = $this->getComprobante();
$comprobante->addCfdiRelacionados(['TipoRelacion' => '04']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::ok(), 'PAGREL01');
}
public function testInvalidTipoRelacion(): void
{
$comprobante = $this->getComprobante();
$comprobante->addCfdiRelacionados(['TipoRelacion' => 'XX']);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGREL01');
}
public function testWithoutCfdiRelacionados(): void
{
$this->runValidate();
$this->assertStatusEqualsCode(Status::none(), 'PAGREL01');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ComprobantePagosTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/ComprobantePagosTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos;
use CfdiUtils\Elements\Pagos10\Pagos;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\ComprobantePagos;
use CfdiUtils\Validate\Contracts\ValidatorInterface;
use CfdiUtils\Validate\Status;
final class ComprobantePagosTest extends ValidateComplementoPagosTestCase
{
/** @var ComprobantePagos */
protected ValidatorInterface $validator;
protected function setUp(): void
{
parent::setUp();
$this->validator = new ComprobantePagos();
// setup a valid case and in the test change to make it fail
$comprobante = $this->getComprobante();
$comprobante->addAttributes([
'Moneda' => 'XXX',
'SubTotal' => '0',
'Total' => '0',
]);
}
public function testValidCase(): void
{
$this->runValidate();
foreach (range(1, 10) as $i) {
$this->assertStatusEqualsCode(Status::ok(), sprintf('PAGCOMP%02d', $i));
}
}
public function testErrorWithMoreThanOneComplementoPagos(): void
{
$this->getComprobante()->getComplemento()->add(new Pagos());
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP01');
}
public function testErrorWithFormaPago(): void
{
$this->getComprobante()->addAttributes([
'FormaPago' => '', // exists, even empty
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP02');
}
public function testErrorWithCondicionesDePago(): void
{
$this->getComprobante()->addAttributes([
'CondicionesDePago' => '', // exists, even empty
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP03');
}
public function testErrorWithMetodoPago(): void
{
$this->getComprobante()->addAttributes([
'MetodoPago' => '', // exists, even empty
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP04');
}
/**
* @testWith [""]
* [null]
* ["MXN"]
*/
public function testErrorWithMonedaNotXxx(?string $input): void
{
$this->getComprobante()->addAttributes([
'Moneda' => $input,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP05');
}
public function testErrorWithTipoCambio(): void
{
$this->getComprobante()->addAttributes([
'TipoCambio' => '', // exists, even empty
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP06');
}
public function testErrorWithDescuento(): void
{
$this->getComprobante()->addAttributes([
'Descuento' => '', // exists, even empty
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP07');
}
/**
* @testWith [""]
* [null]
* ["0.0"]
*/
public function testErrorWithSubTotalNotZero(?string $input): void
{
$this->getComprobante()->addAttributes([
'SubTotal' => $input,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP08');
}
/**
* @testWith [""]
* [null]
* ["0.0"]
*/
public function testErrorWithTotalNotZero(?string $input): void
{
$this->getComprobante()->addAttributes([
'Total' => $input,
]);
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP09');
}
public function testErrorWithImpuestos(): void
{
$this->getComprobante()->getImpuestos();
$this->runValidate();
$this->assertStatusEqualsCode(Status::error(), 'PAGCOMP10');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/CalculateDocumentAmountTraitTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/CalculateDocumentAmountTraitTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Helpers;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use PHPUnit\Framework\TestCase;
final class CalculateDocumentAmountTraitTest extends TestCase
{
public function testCalculateDocumentAmountWhenIsSet(): void
{
$validator = new CalculateDocumentAmountUse();
$amount = $validator->calculateDocumentAmount(new DoctoRelacionado([
'ImpPagado' => '123.45',
]), new Pago());
$this->assertEqualsWithDelta(123.45, $amount, 0.001);
}
public function testCalculateDocumentAmountWhenIsUndefined(): void
{
$pago = new Pago(['Monto' => '123.45']);
$docto = $pago->addDoctoRelacionado();
$validator = new CalculateDocumentAmountUse();
$amount = $validator->calculateDocumentAmount($docto, $pago);
$this->assertEqualsWithDelta(123.45, $amount, 0.001);
}
public function testCalculateDocumentAmountWhenIsUndefinedWithExchangeRate(): void
{
$pago = new Pago(['Monto' => '123.45']);
$docto = $pago->addDoctoRelacionado(['TipoCambioDR' => 'EUR']);
$validator = new CalculateDocumentAmountUse();
$amount = $validator->calculateDocumentAmount($docto, $pago);
$this->assertEqualsWithDelta(0, $amount, 0.001);
}
public function testCalculateDocumentAmountWhenIsUndefinedWithMoreDocuments(): void
{
$pago = new Pago(['Monto' => '123.45']);
$pago->addDoctoRelacionado(); // first
$docto = $pago->addDoctoRelacionado(); // second
$validator = new CalculateDocumentAmountUse();
$amount = $validator->calculateDocumentAmount($docto, $pago);
$this->assertEqualsWithDelta(0, $amount, 0.001);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/FormaPagoCatalogTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/FormaPagoCatalogTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Helpers;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Helpers\FormaPagoCatalog;
use PHPUnit\Framework\TestCase;
final class FormaPagoCatalogTest extends TestCase
{
public function providerObtain(): array
{
return [
'Efectivo' => ['01'],
'Cheque nominativo' => ['02'],
'Transferencia electrónica de fondos' => ['03'],
'Tarjeta de crédito' => ['04'],
'Monedero electrónico' => ['05'],
'Dinero electrónico' => ['06'],
'Vales de despensa' => ['08'],
'Dación en pago' => ['12'],
'Pago por subrogación' => ['13'],
'Pago por consignación' => ['14'],
'Condonación' => ['15'],
'Compensación' => ['17'],
'Novación' => ['23'],
'Confusión' => ['24'],
'Remisión de deuda' => ['25'],
'Prescripción o caducidad' => ['26'],
'A satisfacción del acreedor' => ['27'],
'Tarjeta de débito' => ['28'],
'Tarjeta de servicios' => ['29'],
'Por definir' => ['99'],
];
}
/**
* @dataProvider providerObtain
*/
public function testObtain(string $key): void
{
$paymentType = (new FormaPagoCatalog())->obtain($key);
$this->assertSame($key, $paymentType->key());
}
public function testObtainWithNonExistentKey(): void
{
$this->expectException(\OutOfBoundsException::class);
$this->expectExceptionMessage('FOO');
(new FormaPagoCatalog())->obtain('FOO');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/CalculateDocumentAmountUse.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/CalculateDocumentAmountUse.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Helpers;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Helpers\CalculateDocumentAmountTrait;
final class CalculateDocumentAmountUse
{
use CalculateDocumentAmountTrait;
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/FormaPagoEntryTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Helpers/FormaPagoEntryTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Helpers;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Helpers\FormaPagoEntry;
use PHPUnit\Framework\TestCase;
final class FormaPagoEntryTest extends TestCase
{
/**
* @testWith ["foo", "bar", false, false, "", false, false, "", false]
* ["foo", "bar", true, false, "", false, false, "", false]
* ["foo", "bar", false, true, "", false, false, "", false]
* ["foo", "bar", false, true, "/[0-9]+/", false, false, "", false]
* ["foo", "bar", false, false, "/[0-9]+/", false, false, "", false]
* ["foo", "bar", false, false, "", true, false, "", false]
* ["foo", "bar", false, false, "", false, true, "", false]
* ["foo", "bar", false, false, "", false, true, "/[0-9]+/", false]
* ["foo", "bar", false, false, "", false, false, "/[0-9]+/", false]
* ["foo", "bar", false, false, "", false, false, "", true]
*/
public function testConstructValidObject(
string $key,
string $description,
bool $allowSenderRfc,
bool $allowSenderAccount,
string $senderAccountPattern,
bool $allowReceiverRfc,
bool $allowReceiverAccount,
string $receiverAccountPattern,
bool $allowPaymentSignature,
): void {
$paymentType = new FormaPagoEntry(
$key,
$description,
$allowSenderRfc,
$allowSenderAccount,
$senderAccountPattern,
$allowReceiverRfc,
$allowReceiverAccount,
$receiverAccountPattern,
$allowPaymentSignature
);
$expectedSenderAccountPattern = '/^$/';
if ($allowSenderAccount && '' !== $senderAccountPattern) {
$expectedSenderAccountPattern = $senderAccountPattern;
}
$expectedReceiverAccountPattern = '/^$/';
if ($allowReceiverAccount && '' !== $receiverAccountPattern) {
$expectedReceiverAccountPattern = $receiverAccountPattern;
}
$this->assertSame($key, $paymentType->key());
$this->assertSame($description, $paymentType->description());
$this->assertSame($allowSenderRfc, $paymentType->allowSenderRfc());
$this->assertSame($allowSenderAccount, $paymentType->allowSenderAccount());
$this->assertSame($expectedSenderAccountPattern, $paymentType->senderAccountPattern());
$this->assertSame($allowReceiverRfc, $paymentType->allowReceiverRfc());
$this->assertSame($allowReceiverAccount, $paymentType->allowReceiverAccount());
$this->assertSame($expectedReceiverAccountPattern, $paymentType->receiverAccountPattern());
$this->assertSame($allowPaymentSignature, $paymentType->allowPaymentSignature());
}
public function testConstructWithoutKey(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage(' key ');
new FormaPagoEntry('', 'bar', false, false, '', false, false, '', false);
}
public function testConstructWithoutDescription(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage(' description ');
new FormaPagoEntry('foo', '', false, false, '', false, false, '', false);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoOrdenanteRfcCorrectoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoOrdenanteRfcCorrectoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\BancoOrdenanteRfcCorrecto;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class BancoOrdenanteRfcCorrectoTest extends TestCase
{
/**
* @testWith ["COSC8001137NA"]
* ["XEXX010101000"]
* [null]
*/
public function testValid(?string $rfc): void
{
$pago = new Pago([
'RfcEmisorCtaOrd' => $rfc,
]);
$validator = new BancoOrdenanteRfcCorrecto();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["COSC8099137N1"]
* ["XAXX010101000"]
* [""]
*/
public function testInvalid(string $rfc): void
{
$pago = new Pago([
'RfcEmisorCtaOrd' => $rfc,
]);
$validator = new BancoOrdenanteRfcCorrecto();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaBeneficiariaProhibidaTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaBeneficiariaProhibidaTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\CuentaBeneficiariaProhibida;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class CuentaBeneficiariaProhibidaTest extends TestCase
{
/**
* @testWith ["02", "x"]
* ["02", ""]
* ["02", null]
* ["01", null]
*/
public function testValid(string $paymentType, ?string $account): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'CtaBeneficiario' => $account,
]);
$validator = new CuentaBeneficiariaProhibida();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["01", "x"]
* ["01", ""]
*/
public function testInvalid(string $paymentType, string $account): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'CtaBeneficiario' => $account,
]);
$validator = new CuentaBeneficiariaProhibida();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MonedaPagoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MonedaPagoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\MonedaPago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class MonedaPagoTest extends TestCase
{
public function testValid(): void
{
$pago = new Pago([
'MonedaP' => '999',
]);
$validator = new MonedaPago();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith [null]
* [""]
* ["XXX"]
*/
public function testInvalid(?string $currency): void
{
$pago = new Pago([
'MonedaP' => $currency,
]);
$validator = new MonedaPago();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaBeneficiariaPatronTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaBeneficiariaPatronTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\CuentaBeneficiariaPatron;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class CuentaBeneficiariaPatronTest extends TestCase
{
/**
* @testWith ["1234567890123456"]
* [null]
*/
public function testValid(?string $input): void
{
$pago = new Pago([
'FormaDePagoP' => '04', // require a pattern of 16 digits
'CtaBeneficiario' => $input,
]);
$validator = new CuentaBeneficiariaPatron();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["1"]
* [""]
*/
public function testInvalid(string $input): void
{
$pago = new Pago([
'FormaDePagoP' => '04', // require a pattern of 16 digits
'CtaBeneficiario' => $input,
]);
$validator = new CuentaBeneficiariaPatron();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionadoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionadoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use PHPUnit\Framework\TestCase;
final class DoctoRelacionadoTest extends TestCase
{
public function testValidatorsCodes(): void
{
$expectedValidators = [];
foreach (range(23, 33) as $i) {
$expectedValidators[] = sprintf('PAGO%02d', $i);
}
$validator = new DoctoRelacionado();
$validators = $validator->createValidators();
$codes = [];
foreach ($validators as $validator) {
$codes[] = $validator->getCode();
}
$this->assertEquals($expectedValidators, $codes);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoCadenaTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoCadenaTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\TipoCadenaPagoCadena;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class TipoCadenaPagoCadenaTest extends TestCase
{
/**
* @testWith [null, null]
* ["1", "1"]
*/
public function testValid(?string $tipoCadPago, ?string $input): void
{
$pago = new Pago([
'TipoCadPago' => $tipoCadPago,
'CadPago' => $input,
]);
$validator = new TipoCadenaPagoCadena();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith [null, "1"]
* ["", "1"]
* ["1", null]
* ["1", ""]
* [null, ""]
* ["", null]
*/
public function testInvalid(?string $tipoCadPago, ?string $input): void
{
$pago = new Pago([
'TipoCadPago' => $tipoCadPago,
'CadPago' => $input,
]);
$validator = new TipoCadenaPagoCadena();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/FechaTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/FechaTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Utils\Format;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\Fecha;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use CfdiUtilsTests\Validate\Validate33TestCase;
final class FechaTest extends Validate33TestCase
{
public function testValid(): void
{
$pagoNode = new Pago([
'FechaPago' => Format::datetime(time()),
]);
$validator = new Fecha();
$this->assertTrue($validator->validatePago($pagoNode));
}
/**
* @testWith [null]
* [""]
* ["not a date"]
* ["2018-01-01"]
*/
public function testInvalid(?string $fechaPago): void
{
$pagoNode = new Pago([
'FechaPago' => $fechaPago,
]);
$validator = new Fecha();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pagoNode);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoOrdenanteRfcProhibidoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoOrdenanteRfcProhibidoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\BancoOrdenanteRfcProhibido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class BancoOrdenanteRfcProhibidoTest extends TestCase
{
/**
* @testWith ["02", "COSC8001137NA"]
* ["02", ""]
* ["02", null]
* ["01", null]
*/
public function testValid(string $paymentType, ?string $rfc): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'RfcEmisorCtaOrd' => $rfc,
]);
$validator = new BancoOrdenanteRfcProhibido();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["01", "COSC8001137NA"]
* ["01", ""]
* [null, "COSC8001137NA"]
*/
public function testInvalid(?string $paymentType, string $rfc): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'RfcEmisorCtaOrd' => $rfc,
]);
$validator = new BancoOrdenanteRfcProhibido();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoBeneficiarioRfcProhibidoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoBeneficiarioRfcProhibidoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\BancoBeneficiarioRfcProhibido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class BancoBeneficiarioRfcProhibidoTest extends TestCase
{
/**
* @testWith ["02", "COSC8001137NA"]
* ["02", ""]
* ["02", null]
* ["01", null]
*/
public function testValid(string $paymentType, ?string $rfc): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'RfcEmisorCtaBen' => $rfc,
]);
$validator = new BancoBeneficiarioRfcProhibido();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["01", "COSC8001137NA"]
* ["01", ""]
*/
public function testInvalid(string $paymentType, string $rfc): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'RfcEmisorCtaBen' => $rfc,
]);
$validator = new BancoBeneficiarioRfcProhibido();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoProhibidoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoProhibidoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\TipoCadenaPagoProhibido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class TipoCadenaPagoProhibidoTest extends TestCase
{
/**
* @testWith ["01", null]
* ["03", null]
* ["03", "SPEI"]
*/
public function testValid(string $paymentForm, ?string $input): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentForm,
'TipoCadPago' => $input,
]);
$validator = new TipoCadenaPagoProhibido();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["01", "SPEI"]
* ["01", ""]
*/
public function testInvalid(string $paymentForm, ?string $input): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentForm,
'TipoCadPago' => $input,
]);
$validator = new TipoCadenaPagoProhibido();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCambioExistsTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCambioExistsTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\TipoCambioExists;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class TipoCambioExistsTest extends TestCase
{
/**
* @testWith ["MXN", null]
* ["USD", "18.5678"]
*/
public function testValidInput(string $currency, ?string $exchangerate): void
{
$pago = new Pago([
'MonedaP' => $currency,
'TipoCambioP' => $exchangerate,
]);
$validator = new TipoCambioExists();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["MXN", "1"]
* ["MXN", "1.23"]
* ["USD", null]
* ["USD", ""]
*/
public function testInvalidInput(string $currency, ?string $exchangerate): void
{
$pago = new Pago([
'MonedaP' => $currency,
'TipoCambioP' => $exchangerate,
]);
$validator = new TipoCambioExists();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaOrdenantePatronTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaOrdenantePatronTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\CuentaOrdenantePatron;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class CuentaOrdenantePatronTest extends TestCase
{
/**
* @testWith ["1234567890123456"]
* [null]
*/
public function testValid(?string $input): void
{
$pago = new Pago([
'FormaDePagoP' => '04', // require a pattern of 16 digits
'CtaOrdenante' => $input,
]);
$validator = new CuentaOrdenantePatron();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["1"]
* [""]
*/
public function testInvalid(string $input): void
{
$pago = new Pago([
'FormaDePagoP' => '04', // require a pattern of 16 digits
'CtaOrdenante' => $input,
]);
$validator = new CuentaOrdenantePatron();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoGreaterOrEqualThanSumOfDocumentsTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoGreaterOrEqualThanSumOfDocumentsTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\MontoGreaterOrEqualThanSumOfDocuments;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class MontoGreaterOrEqualThanSumOfDocumentsTest extends TestCase
{
public function testValid(): void
{
$pago = new Pago([
'MonedaP' => 'USD',
'Monto' => '123.45',
]);
$pago->multiDoctoRelacionado(...[
['ImpPagado' => '50.00'], // 50.00
['MonedaDR' => 'EUR', 'TipoCambioDR' => '0.5', 'ImpPagado' => '25.00'], // 25.00 / 0.5 => 50
['MonedaDR' => 'MXN', 'TipoCambioDR' => '18.7894', 'ImpPagado' => '440.61'], // 440.61 / 18.7894 => 23.45
]);
$validator = new MontoGreaterOrEqualThanSumOfDocuments();
$this->assertTrue($validator->validatePago($pago));
}
public function testInvalid(): void
{
$pago = new Pago([
'MonedaP' => 'MXN',
'Monto' => '123.45',
]);
$pago->multiDoctoRelacionado(...[
['ImpPagado' => '50.00'], // 50.00
['MonedaDR' => 'EUR', 'TipoCambioDR' => '0.5', 'ImpPagado' => '25.01'], // 25.01 / 0.5 => 50.02
['MonedaDR' => 'MXN', 'TipoCambioDR' => '18.7894', 'ImpPagado' => '440.61'], // 440.61 / 18.7894 => 23.45
]);
$validator = new MontoGreaterOrEqualThanSumOfDocuments();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
public function testCalculateDocumentAmountWhenIsSet(): void
{
$validator = new MontoGreaterOrEqualThanSumOfDocuments();
$amount = $validator->calculateDocumentAmount(new DoctoRelacionado([
'ImpPagado' => '123.45',
]), new Pago());
$this->assertEqualsWithDelta(123.45, $amount, 0.001);
}
public function testCalculateDocumentAmountWhenIsUndefined(): void
{
$pago = new Pago(['Monto' => '123.45']);
$docto = $pago->addDoctoRelacionado();
$validator = new MontoGreaterOrEqualThanSumOfDocuments();
$amount = $validator->calculateDocumentAmount($docto, $pago);
$this->assertEqualsWithDelta(123.45, $amount, 0.001);
}
public function testCalculateDocumentAmountWhenIsUndefinedWithExchangeRate(): void
{
$pago = new Pago(['Monto' => '123.45']);
$docto = $pago->addDoctoRelacionado(['TipoCambioDR' => 'EUR']);
$validator = new MontoGreaterOrEqualThanSumOfDocuments();
$amount = $validator->calculateDocumentAmount($docto, $pago);
$this->assertEqualsWithDelta(0, $amount, 0.001);
}
public function testCalculateDocumentAmountWhenIsUndefinedWithMoreDocuments(): void
{
$pago = new Pago(['Monto' => '123.45']);
$pago->addDoctoRelacionado(); // first
$docto = $pago->addDoctoRelacionado(); // second
$validator = new MontoGreaterOrEqualThanSumOfDocuments();
$amount = $validator->calculateDocumentAmount($docto, $pago);
$this->assertEqualsWithDelta(0, $amount, 0.001);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/FormaDePagoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/FormaDePagoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\FormaDePago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class FormaDePagoTest extends TestCase
{
public function testValid(): void
{
$pago = new Pago([
'FormaDePagoP' => '23',
]);
$validator = new FormaDePago();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith [null]
* [""]
* ["99"]
*/
public function testInvalid(?string $formaPago): void
{
$pago = new Pago([
'FormaDePagoP' => $formaPago,
]);
$this->expectException(ValidatePagoException::class);
$validator = new FormaDePago();
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoSelloTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoSelloTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\TipoCadenaPagoSello;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class TipoCadenaPagoSelloTest extends TestCase
{
/**
* @testWith [null, null]
* ["1", "1"]
*/
public function testValid(?string $tipoCadPago, ?string $input): void
{
$pago = new Pago([
'TipoCadPago' => $tipoCadPago,
'SelloPago' => $input,
]);
$validator = new TipoCadenaPagoSello();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith [null, "1"]
* ["", "1"]
* ["1", null]
* ["1", ""]
* [null, ""]
* ["", null]
*/
public function testInvalid(?string $tipoCadPago, ?string $input): void
{
$pago = new Pago([
'TipoCadPago' => $tipoCadPago,
'SelloPago' => $input,
]);
$validator = new TipoCadenaPagoSello();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCambioValueTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCambioValueTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\TipoCambioValue;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class TipoCambioValueTest extends TestCase
{
/**
* @testWith ["0.000002"]
* ["18.5623"]
* [null]
*/
public function testValid(?string $exchangerate): void
{
$pago = new Pago([
'TipoCambioP' => $exchangerate,
]);
$validator = new TipoCambioValue();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["0.000001"]
* ["1.0000001"]
* ["-1"]
* ["not numeric"]
* [""]
*/
public function testInvalid(string $exchangerate): void
{
$pago = new Pago([
'TipoCambioP' => $exchangerate,
]);
$validator = new TipoCambioValue();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoGreaterThanZeroTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoGreaterThanZeroTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\MontoGreaterThanZero;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class MontoGreaterThanZeroTest extends TestCase
{
/**
* @testWith ["0.000001"]
* ["1"]
*/
public function testValid(string $amount): void
{
$pago = new Pago([
'Monto' => $amount,
]);
$validator = new MontoGreaterThanZero();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["0.0000001"]
* ["0"]
* ["-1"]
* [null]
* [""]
* ["not numeric"]
*/
public function testPagoMontoGreaterThanZeroInvalid(?string $amount): void
{
$pago = new Pago([
'Monto' => $amount,
]);
$validator = new MontoGreaterThanZero();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoBeneficiarioRfcCorrectoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoBeneficiarioRfcCorrectoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\BancoBeneficiarioRfcCorrecto;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class BancoBeneficiarioRfcCorrectoTest extends TestCase
{
/**
* @testWith ["COSC8001137NA"]
* ["XEXX010101000"]
* [null]
*/
public function testValid(?string $rfc): void
{
$pago = new Pago([
'RfcEmisorCtaBen' => $rfc,
]);
$validator = new BancoBeneficiarioRfcCorrecto();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["COSC8099137N1"]
* ["XAXX010101000"]
* [""]
*/
public function testInvalid(?string $rfc): void
{
$pago = new Pago([
'RfcEmisorCtaBen' => $rfc,
]);
$validator = new BancoBeneficiarioRfcCorrecto();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoBetweenIntervalSumOfDocumentsTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\MontoBetweenIntervalSumOfDocuments;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class MontoBetweenIntervalSumOfDocumentsTest extends TestCase
{
public function testValid(): void
{
$pago = new Pago([
'MonedaP' => 'USD',
'Monto' => '123.45',
]);
$pago->multiDoctoRelacionado(...[
['ImpPagado' => '50.00'], // 50.00
['MonedaDR' => 'EUR', 'TipoCambioDR' => '0.50', 'ImpPagado' => '25.00'], // 25.00 / 0.50 => 50
['MonedaDR' => 'MXN', 'TipoCambioDR' => '18.7894', 'ImpPagado' => '440.61'], // 440.61 / 18.7894 => 23.45
]);
$validator = new MontoBetweenIntervalSumOfDocuments();
$this->assertTrue($validator->validatePago($pago));
}
/**
* This is testing lower bound (122.94) and upper bound (123.97)
* @testWith ["122.93"]
* ["123.98"]
*/
public function testInvalids(string $monto): void
{
$pago = new Pago([
'MonedaP' => 'USD',
'Monto' => $monto,
]);
$pago->multiDoctoRelacionado(...[
['ImpPagado' => '20.00'], // 20.00
['MonedaDR' => 'USD', 'ImpPagado' => '30.00'], // 30.00
['MonedaDR' => 'EUR', 'TipoCambioDR' => '0.50', 'ImpPagado' => '25.00'], // 25.00 / 0.50 => 50
['MonedaDR' => 'MXN', 'TipoCambioDR' => '18.7894', 'ImpPagado' => '440.61'], // 440.61 / 18.7894 => 23.45
]);
$validator = new MontoBetweenIntervalSumOfDocuments();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
public function testValidWithSeveralDecimals(): void
{
// payment was made of 5,137.42 USD (ER: 18.7694) => 96,426.29 MXN
// to pay a document on USD
$pago = new Pago([
'MonedaP' => 'MXN',
'Monto' => '96426.29',
]);
$pago->addDoctoRelacionado([
'MonedaDR' => 'USD',
'TipoCambioDR' => number_format(1 / 18.7694, 4),
'ImpPagado' => '5137.42',
]);
$validator = new MontoBetweenIntervalSumOfDocuments();
$this->assertTrue($validator->validatePago($pago));
}
public function testValidWithMultiDocuments(): void
{
$pago = new Pago([
'MonedaP' => 'MXN',
'Monto' => '21588.07',
]);
$pago->multiDoctoRelacionado(...[
['MonedaDR' => 'MXN', 'ImpPagado' => '6826.60'],
['MonedaDR' => 'MXN', 'ImpPagado' => '2114.52'],
['MonedaDR' => 'MXN', 'ImpPagado' => '11245.04'],
['MonedaDR' => 'MXN', 'ImpPagado' => '1401.91'],
]);
$validator = new MontoBetweenIntervalSumOfDocuments();
$this->assertTrue($validator->validatePago($pago));
}
public function providerValidWithRandomAmounts(): array
{
$randomValues = [];
for ($i = 0; $i < 20; $i++) {
$randomValues[] = [random_int(1, 99999999) / 100];
}
return $randomValues;
}
/**
* @dataProvider providerValidWithRandomAmounts
*/
public function testValidWithRandomAmounts(float $amount): void
{
$pago = new Pago([
'MonedaP' => 'MXN',
'Monto' => number_format($amount, 2, '.', ''),
]);
$pago->multiDoctoRelacionado(...[
['MonedaDR' => 'MXN', 'ImpPagado' => number_format($amount / 3, 2, '.', '')],
['MonedaDR' => 'MXN', 'ImpPagado' => number_format(2 * $amount / 3, 2, '.', '')],
]);
$validator = new MontoBetweenIntervalSumOfDocuments();
$this->assertTrue($validator->validatePago($pago));
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoOrdenanteNombreRequeridoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/BancoOrdenanteNombreRequeridoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\BancoOrdenanteNombreRequerido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class BancoOrdenanteNombreRequeridoTest extends TestCase
{
/**
* @testWith ["XEXX010101000", "Foreign bank"]
* ["COSC8001137NA", "Banco X"]
* ["COSC8001137NA", null]
* [null, "Foreign bank"]
* [null, null]
*/
public function testValid(?string $rfc, ?string $name): void
{
$pago = new Pago([
'RfcEmisorCtaOrd' => $rfc,
'NomBancoOrdExt' => $name,
]);
$validator = new BancoOrdenanteNombreRequerido();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["XEXX010101000", ""]
* ["XEXX010101000", null]
*/
public function testInvalid(string $rfc, ?string $name): void
{
$pago = new Pago([
'RfcEmisorCtaOrd' => $rfc,
'NomBancoOrdExt' => $name,
]);
$validator = new BancoOrdenanteNombreRequerido();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaOrdenanteProhibidaTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/CuentaOrdenanteProhibidaTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\CuentaOrdenanteProhibida;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class CuentaOrdenanteProhibidaTest extends TestCase
{
/**
* @testWith ["02", "x"]
* ["02", ""]
* ["02", null]
* ["01", null]
*/
public function testValid(string $paymentType, ?string $account): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'CtaOrdenante' => $account,
]);
$validator = new CuentaOrdenanteProhibida();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["01", "x"]
* ["01", ""]
*/
public function testInvalid(string $paymentType, string $account): void
{
$pago = new Pago([
'FormaDePagoP' => $paymentType,
'CtaOrdenante' => $account,
]);
$validator = new CuentaOrdenanteProhibida();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoDecimalsTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/MontoDecimalsTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\MontoDecimals;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class MontoDecimalsTest extends TestCase
{
public function testValid(): void
{
$pago = new Pago([
'MonedaP' => 'USD', // 2 decimals
'Monto' => '1.00',
]);
$validator = new MontoDecimals();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith ["0.001"]
* ["0.000"]
* ["0.123"]
*/
public function testInvalid(string $amount): void
{
$pago = new Pago([
'MonedaP' => 'USD', // 2 decimals
'Monto' => $amount,
]);
$validator = new MontoDecimals();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoCertificadoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/TipoCadenaPagoCertificadoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\TipoCadenaPagoCertificado;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\ValidatePagoException;
use PHPUnit\Framework\TestCase;
final class TipoCadenaPagoCertificadoTest extends TestCase
{
/**
* @testWith [null, null]
* ["1", "1"]
*/
public function testValid(?string $tipoCadPago, ?string $input): void
{
$pago = new Pago([
'TipoCadPago' => $tipoCadPago,
'CertPago' => $input,
]);
$validator = new TipoCadenaPagoCertificado();
$this->assertTrue($validator->validatePago($pago));
}
/**
* @testWith [null, "1"]
* ["", "1"]
* ["1", null]
* ["1", ""]
* [null, ""]
* ["", null]
*/
public function testInvalid(?string $tipoCadPago, ?string $input): void
{
$pago = new Pago([
'TipoCadPago' => $tipoCadPago,
'CertPago' => $input,
]);
$validator = new TipoCadenaPagoCertificado();
$this->expectException(ValidatePagoException::class);
$validator->validatePago($pago);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/TipoCambioValorTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/TipoCambioValorTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\TipoCambioValor;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class TipoCambioValorTest extends TestCase
{
/**
* @testWith ["USD", "MXN", "1"]
*/
public function testValid(string $currencyPayment, string $currencyDocument, string $exchangeRate): void
{
$pago = new Pago([
'MonedaP' => $currencyPayment,
]);
$docto = $pago->addDoctoRelacionado([
'MonedaDR' => $currencyDocument,
'TipoCambioDR' => $exchangeRate,
]);
$validator = new TipoCambioValor();
$validator->setPago($pago);
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["USD", "MXN", "1.0"]
* ["USD", "MXN", ""]
* ["USD", "MXN", null]
*/
public function testInvalid(string $currencyPayment, string $currencyDocument, ?string $exchangeRate): void
{
$pago = new Pago([
'MonedaP' => $currencyPayment,
]);
$docto = $pago->addDoctoRelacionado([
'MonedaDR' => $currencyDocument,
'TipoCambioDR' => $exchangeRate,
]);
$validator = new TipoCambioValor();
$validator->setPago($pago);
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoAnteriorRequeridoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoAnteriorRequeridoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImporteSaldoAnteriorRequerido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImporteSaldoAnteriorRequeridoTest extends TestCase
{
public function testValid(): void
{
$docto = new DoctoRelacionado([
'MetodoDePagoDR' => 'PPD',
'ImpSaldoAnt' => '1',
]);
$validator = new ImporteSaldoAnteriorRequerido();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
public function testInvalid(): void
{
$docto = new DoctoRelacionado([
'MetodoDePagoDR' => 'PPD',
'ImpSaldoAnt' => null,
]);
$validator = new ImporteSaldoAnteriorRequerido();
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoAnteriorValorTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoAnteriorValorTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImporteSaldoAnteriorValor;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImporteSaldoAnteriorValorTest extends TestCase
{
/**
* @testWith ["0.01"]
* ["123456.78"]
*/
public function testValid(string $input): void
{
$docto = new DoctoRelacionado([
'ImpSaldoAnt' => $input,
]);
$validator = new ImporteSaldoAnteriorValor();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["0"]
* ["-123.45"]
* [""]
* [null]
*/
public function testInvalid(?string $input): void
{
$docto = new DoctoRelacionado([
'ImpSaldoAnt' => $input,
]);
$validator = new ImporteSaldoAnteriorValor();
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/MonedaTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/MonedaTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\Moneda;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class MonedaTest extends TestCase
{
/**
* @testWith ["MXN"]
* ["USD"]
* [""]
* [null]
*/
public function testValid(?string $input): void
{
$docto = new DoctoRelacionado([
'MonedaDR' => $input,
]);
$validator = new Moneda();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["XXX"]
*/
public function testInvalid(string $input): void
{
$docto = new DoctoRelacionado([
'MonedaDR' => $input,
]);
$validator = new Moneda();
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImportesDecimalesTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImportesDecimalesTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImportesDecimales;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImportesDecimalesTest extends TestCase
{
/**
* @testWith ["MXN", "100.00", "100.00", "0.00"]
* ["MXN", "100.0", "100.0", "0.0"]
* ["MXN", "100", "100", "0"]
*/
public function testValid(string $currency, string $previous, string $payment, string $left): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado([
'MonedaDR' => $currency,
'ImpSaldoAnt' => $previous,
'ImpPagado' => $payment,
'ImpSaldoInsoluto' => $left,
]);
$validator = new ImportesDecimales();
$validator->setIndex(0);
$validator->setPago($pago);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["MXN", "100.000", "100.00", "0.00"]
* ["MXN", "100.00", "100.000", "0.00"]
* ["MXN", "100.00", "100.00", "0.000"]
*/
public function testInvalid(string $currency, string $previous, string $payment, string $left): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado([
'MonedaDR' => $currency,
'ImpSaldoAnt' => $previous,
'ImpPagado' => $payment,
'ImpSaldoInsoluto' => $left,
]);
$validator = new ImportesDecimales();
$validator->setIndex(0);
$validator->setPago($pago);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/NumeroParcialidadRequeridoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/NumeroParcialidadRequeridoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\NumeroParcialidadRequerido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class NumeroParcialidadRequeridoTest extends TestCase
{
public function testValid(): void
{
$docto = new DoctoRelacionado([
'MetodoDePagoDR' => 'PPD',
'NumParcialidad' => '1',
]);
$validator = new NumeroParcialidadRequerido();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
public function testInvalid(): void
{
$docto = new DoctoRelacionado([
'MetodoDePagoDR' => 'PPD',
'NumParcialidad' => null,
]);
$validator = new NumeroParcialidadRequerido();
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoInsolutoRequeridoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoInsolutoRequeridoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImporteSaldoInsolutoRequerido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImporteSaldoInsolutoRequeridoTest extends TestCase
{
public function testValid(): void
{
$docto = new DoctoRelacionado([
'MetodoDePagoDR' => 'PPD',
'ImpSaldoInsoluto' => '1',
]);
$validator = new ImporteSaldoInsolutoRequerido();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
public function testInvalid(): void
{
$docto = new DoctoRelacionado([
'MetodoDePagoDR' => 'PPD',
'ImpSaldoInsoluto' => null,
]);
$validator = new ImporteSaldoInsolutoRequerido();
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoInsolutoValorTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImporteSaldoInsolutoValorTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImporteSaldoInsolutoValor;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImporteSaldoInsolutoValorTest extends TestCase
{
/**
* @testWith ["100.00", "100.00", "0.0"]
*/
public function testValid(string $previous, string $payment, string $left): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado([
'ImpSaldoAnt' => $previous,
'ImpPagado' => $payment,
'ImpSaldoInsoluto' => $left,
]);
$validator = new ImporteSaldoInsolutoValor();
$validator->setIndex(0);
$validator->setPago($pago);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["150.00", "100.00", "50.0"]
*/
public function testWithCalculate(string $previous, string $payment, string $left): void
{
$pago = new Pago(['Monto' => $payment]);
$docto = $pago->addDoctoRelacionado([
'ImpSaldoAnt' => $previous,
'ImpSaldoInsoluto' => $left,
]);
$validator = new ImporteSaldoInsolutoValor();
$validator->setIndex(0);
$validator->setPago($pago);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["100.00", "100.00", "0.01"]
* ["100.00", "100.00", "-0.01"]
* ["100.01", "100.00", "0.00"]
* ["100.00", "100.01", "0.00"]
*/
public function testInvalid(string $previous, string $payment, string $left): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado([
'ImpSaldoAnt' => $previous,
'ImpPagado' => $payment,
'ImpSaldoInsoluto' => $left,
]);
$validator = new ImporteSaldoInsolutoValor();
$validator->setIndex(0);
$validator->setPago($pago);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImportePagadoRequeridoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImportePagadoRequeridoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImportePagadoRequerido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImportePagadoRequeridoTest extends TestCase
{
public function testValid(): void
{
$docto = new DoctoRelacionado([
'ImpPagado' => '1',
]);
$validator = new ImportePagadoRequerido();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["19.8765"]
* [""]
*/
public function testInvalidExchangeRate(string $exchangeRate): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado([
'TipoCambioDR' => $exchangeRate, // exists!
]);
$validator = new ImportePagadoRequerido();
$validator->setIndex(0);
$validator->setPago($pago);
$this->expectException(ValidateDoctoException::class);
$this->expectExceptionMessage('existe el tipo de cambio');
$validator->validateDoctoRelacionado($docto);
}
public function testInvalidMoreThanOneDocument(): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado();
$pago->addDoctoRelacionado(); // second document
$validator = new ImportePagadoRequerido();
$validator->setIndex(0);
$validator->setPago($pago);
$this->expectException(ValidateDoctoException::class);
$this->expectExceptionMessage('hay más de 1 documento en el pago');
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImportePagadoValorTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/ImportePagadoValorTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ImportePagadoValor;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class ImportePagadoValorTest extends TestCase
{
/**
* @testWith ["0.01"]
* ["123456.78"]
*/
public function testValid(string $input): void
{
$docto = new DoctoRelacionado([
'ImpPagado' => $input,
]);
$validator = new ImportePagadoValor();
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
public function testWithCalculate(): void
{
$pago = new Pago(['Monto' => 123]);
$docto = $pago->addDoctoRelacionado();
$validator = new ImportePagadoValor();
$validator->setIndex(0);
$validator->setPago($pago);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["0"]
* ["-123.45"]
* [""]
* [null]
*/
public function testInvalid(?string $input): void
{
$pago = new Pago();
$docto = $pago->addDoctoRelacionado([
'ImpPagado' => $input,
]);
$validator = new ImportePagadoValor();
$validator->setIndex(0);
$validator->setPago($pago);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/TipoCambioRequeridoTest.php | tests/CfdiUtilsTests/Validate/Cfdi33/RecepcionPagos/Pagos/DoctoRelacionado/TipoCambioRequeridoTest.php | <?php
namespace CfdiUtilsTests\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado;
use CfdiUtils\Elements\Pagos10\Pago;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\TipoCambioRequerido;
use CfdiUtils\Validate\Cfdi33\RecepcionPagos\Pagos\DoctoRelacionado\ValidateDoctoException;
use PHPUnit\Framework\TestCase;
final class TipoCambioRequeridoTest extends TestCase
{
/**
* @testWith ["USD", "USD", null]
* ["MXN", "USD", "19.9876"]
*/
public function testValid(string $currencyPayment, string $currencyDocument, ?string $exchangeRate): void
{
$pago = new Pago([
'MonedaP' => $currencyPayment,
]);
$docto = $pago->addDoctoRelacionado([
'MonedaDR' => $currencyDocument,
'TipoCambioDR' => $exchangeRate,
]);
$validator = new TipoCambioRequerido();
$validator->setPago($pago);
$validator->setIndex(0);
$this->assertTrue($validator->validateDoctoRelacionado($docto));
}
/**
* @testWith ["USD", "USD", "19.9876"]
* ["MXN", "USD", null]
*/
public function testInvalid(string $currencyPayment, string $currencyDocument, ?string $exchangeRate): void
{
$pago = new Pago([
'MonedaP' => $currencyPayment,
]);
$docto = $pago->addDoctoRelacionado([
'MonedaDR' => $currencyDocument,
'TipoCambioDR' => $exchangeRate,
]);
$validator = new TipoCambioRequerido();
$validator->setPago($pago);
$validator->setIndex(0);
$this->expectException(ValidateDoctoException::class);
$validator->validateDoctoRelacionado($docto);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/QuickReader/QuickReaderTest.php | tests/CfdiUtilsTests/QuickReader/QuickReaderTest.php | <?php
namespace CfdiUtilsTests\QuickReader;
use CfdiUtils\QuickReader\QuickReader;
use PHPUnit\Framework\TestCase;
final class QuickReaderTest extends TestCase
{
public function testMinimalInstance(): void
{
$tree = new QuickReader('foo');
$this->assertSame('foo', (string) $tree);
$this->assertCount(0, $tree());
$this->assertSame([], $tree->getAttributes());
}
public function testConstructorWithAttributes(): void
{
$attributes = [
'one' => '1',
'two' => '2',
];
$foo = new QuickReader('foo', $attributes, []);
$this->assertSame('1', $foo['one']);
$this->assertSame('2', $foo['two']);
$this->assertSame($attributes, $foo->getAttributes());
}
public function testConstructorWithChildren(): void
{
$children = [
$bar = new QuickReader('bar'),
$baz = new QuickReader('baz'),
];
$tree = new QuickReader('foo', [], $children);
$this->assertSame($children, $tree());
$this->assertSame($children, $tree->getChildren());
$this->assertSame($bar, $tree->bar);
$this->assertSame($baz, $tree->baz);
$this->assertSame([$bar], $tree->getChildren('bar'));
$this->assertSame([$baz], $tree->getChildren('baz'));
}
public function testGetNotExistentAttribute(): void
{
$foo = new QuickReader('foo');
$this->assertFalse(isset($foo['bar']));
$this->assertSame('', $foo['bar']);
$this->assertFalse(isset($foo['bar'])); /** @phpstan-ignore-line */
}
public function testAccessNonExistentPropertyReturnsANewChildWithPropertyName(): void
{
$foo = new QuickReader('foo');
$this->assertFalse(isset($foo->bar));
$this->assertInstanceOf(QuickReader::class, $foo->bar);
$this->assertFalse(isset($foo->bar));
$this->assertCount(0, $foo(), 'Calling a non existent property DOES NOT append a new child');
}
public function testAccessInvokeReturnsAnArray(): void
{
$foo = new QuickReader('foo');
$this->assertTrue(is_array($foo())); /** @phpstan-ignore-line */
$this->assertTrue(is_array($foo->getChildren())); /** @phpstan-ignore-line */
$xee = $foo->bar->xee;
$this->assertTrue(is_array($xee('zee')));
$this->assertTrue(is_array($xee->__invoke('zee')));
$this->assertTrue(is_array(($foo->bar->xee)('zee')));
}
public function testAccessInvokeReturnsAnArrayOfChildrenWithTheArgumentName(): void
{
$manyBaz = [
$firstBaz = new QuickReader('baz'),
new QuickReader('baz'),
new QuickReader('baz'),
];
$manyChildren = array_merge($manyBaz, [
new QuickReader('xee'),
]);
$foo = new QuickReader('foo', [], $manyChildren);
$this->assertCount(4, $foo(), 'Assert that contains 4 children');
$this->assertCount(4, $foo->getChildren(), 'Assert that contains 4 children using getChildren()');
$this->assertSame($firstBaz, $foo->baz, 'Assert that the first child is the same as the property access');
$obtainedBaz = $foo('baz');
$this->assertSame($manyBaz, $obtainedBaz, 'Assert that all elements where retrieved');
$this->assertCount(3, $obtainedBaz, 'Assert that contains only 3 baz children');
$obtainedBaz = $foo->getChildren('baz');
$this->assertSame($manyBaz, $obtainedBaz, 'Assert that all elements where retrieved using getChildren()');
$this->assertCount(3, $obtainedBaz, 'Assert that contains only 3 baz children using getChildren()');
}
public function testPropertyGetWithDifferentCaseStillWorks(): void
{
$bar = new QuickReader('bar');
$foo = new QuickReader('foo', [], [$bar]);
$this->assertSame($bar, $foo->bar);
$this->assertTrue(isset($foo->bar));
$this->assertSame($bar, $foo->Bar);
$this->assertTrue(isset($foo->Bar));
$this->assertSame($bar, $foo->BAR);
$this->assertTrue(isset($foo->BAR));
$this->assertSame($bar, $foo->bAR);
$this->assertTrue(isset($foo->bAR));
}
public function testAttributeGetWithDifferentCaseStillWorks(): void
{
$foo = new QuickReader('foo', ['bar' => 'México']);
$this->assertSame('México', $foo['bar']);
$this->assertTrue(isset($foo['bar'])); /** @phpstan-ignore-line */
$this->assertSame('México', $foo['Bar']);
$this->assertTrue(isset($foo['Bar'])); /** @phpstan-ignore-line */
$this->assertSame('México', $foo['BAR']);
$this->assertTrue(isset($foo['BAR'])); /** @phpstan-ignore-line */
}
public function testInvokeWithDifferentChildNamesCase(): void
{
$fooA = new QuickReader('foo');
$fooB = new QuickReader('Foo');
$fooC = new QuickReader('FOO');
$root = new QuickReader('root', [], [$fooA, $fooB, $fooC]);
$this->assertCount(3, $root('fOO'));
}
public function testConstructThrowExceptionOnEmptyName(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Property name cannot be empty');
new QuickReader('');
}
public function testConstructThrowExceptionOnInvalidAttributeName(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('There is an attibute with empty or non string name');
new QuickReader('foo', ['x' => 'y', '' => 'bar']);
}
public function testConstructThrowExceptionOnInvalidAttributeValue(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("The attribute 'bar' has a non string value");
$fakeString = new \stdClass();
new QuickReader('foo', ['x' => 'y', 'bar' => $fakeString]); /** @phpstan-ignore-line */
}
public function testConstructThrowExceptionOnInvalidChildren(): void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('The child 1 is not an instance');
/** @var QuickReader $fakeQuickReader */
$fakeQuickReader = new \stdClass();
new QuickReader('foo', [], [new QuickReader('1'), $fakeQuickReader]);
}
public function testCannotSetNewProperties(): void
{
$quickReader = new QuickReader('foo');
$this->expectException(\LogicException::class);
$quickReader->foo = new QuickReader('xee');
}
public function testReadFalsyAttributes(): void
{
$quickReader = new QuickReader('foo', [
'zero' => '0',
'empty' => '',
'space' => ' ',
'control' => 'x',
]);
$this->assertTrue(isset($quickReader['control']));
$this->assertSame('x', $quickReader['control']);
$this->assertTrue(isset($quickReader['zero']));
$this->assertSame('0', $quickReader['zero']);
$this->assertTrue(isset($quickReader['empty']));
$this->assertSame('', $quickReader['empty']);
$this->assertTrue(isset($quickReader['space']));
$this->assertSame(' ', $quickReader['space']);
$this->assertFalse(isset($quickReader['non-existent']));
$this->assertSame('', $quickReader['non-existent']);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/QuickReader/QuickReaderImporterTest.php | tests/CfdiUtilsTests/QuickReader/QuickReaderImporterTest.php | <?php
namespace CfdiUtilsTests\QuickReader;
use CfdiUtils\QuickReader\QuickReader;
use CfdiUtils\QuickReader\QuickReaderImporter;
use DOMDocument;
use PHPUnit\Framework\TestCase;
final class QuickReaderImporterTest extends TestCase
{
public function testImporterImportEmptyNode(): void
{
$document = new DOMDocument();
$document->loadXML('<root/>');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertInstanceOf(QuickReader::class, $root);
$this->assertCount(0, $root());
}
public function testImporterImportEmptyNodeWithNamespaces(): void
{
$document = new DOMDocument();
$document->loadXML('<my:root xmlns:my="http://my.net/my" />');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertInstanceOf(QuickReader::class, $root);
$this->assertCount(0, $root());
}
public function testImporterImportWithAttributes(): void
{
$document = new DOMDocument();
$document->loadXML('<root id="123" score="MEX 1 - 0 GER"/>');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertInstanceOf(QuickReader::class, $root);
$this->assertCount(0, $root());
$this->assertSame('123', $root['id']);
$this->assertSame('MEX 1 - 0 GER', $root['score']);
}
public function testImporterImportWithChildren(): void
{
$document = new DOMDocument();
$document->loadXML('<root><foo /><bar /></root>');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertInstanceOf(QuickReader::class, $root);
$this->assertCount(2, $root());
$this->assertSame('foo', (string) $root->foo);
$this->assertSame('bar', (string) $root->bar);
$this->assertCount(2, $root());
}
public function testImporterImportWithGrandChildren(): void
{
$document = new DOMDocument();
$document->loadXML('<root><foo><l1><l2 id="xee"></l2></l1></foo><bar /></root>');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertInstanceOf(QuickReader::class, $root);
$this->assertSame('xee', $root->foo->l1->l2['id']);
}
public function testImportXmlWithDifferentNodes(): void
{
$document = new DOMDocument();
$document->loadXML('
<root>
<!-- comment -->
<foo />
</root>
');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertTrue(isset($root->foo));
$this->assertCount(1, $root());
$this->assertCount(0, ($root->foo)());
}
public function testImportChildrenWithSameName(): void
{
$document = new DOMDocument();
$document->loadXML('
<root>
<foo id="1"/>
<Foo id="2"/>
<FOO id="3"/>
<bar />
<bar />
<baz />
</root>
');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertCount(6, $root());
$this->assertCount(3, $root('foo'));
$this->assertCount(2, $root('bar'));
$this->assertCount(1, $root('baz'));
$this->assertCount(0, $root('xee'));
}
public function testImportWithNamespacesAreExcluded(): void
{
$document = new DOMDocument();
$document->loadXML('
<my:root xmlns:my="http://example.com/my" xmlns:other="http://example.com/other">
<my:foo id="1"/>
<my:Foo id="2"/>
<my:FOO id="3"/>
<other:bar />
<other:bar />
<other:baz />
</my:root>
');
$importer = new QuickReaderImporter();
$root = $importer->importDocument($document);
$this->assertCount(6, $root());
$this->assertCount(3, $root('foo'));
$this->assertCount(2, $root('bar'));
$this->assertCount(1, $root('baz'));
$this->assertCount(0, $root('xee'));
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/UseCases/ReadCfdiWithTimbreOnSecondComplementoTest.php | tests/CfdiUtilsTests/UseCases/ReadCfdiWithTimbreOnSecondComplementoTest.php | <?php
namespace CfdiUtilsTests\UseCases;
use CfdiUtils\CadenaOrigen\CfdiDefaultLocations;
use CfdiUtils\CadenaOrigen\DOMBuilder;
use CfdiUtils\Certificado\Certificado;
use CfdiUtils\Cfdi;
use CfdiUtils\CfdiCreator33;
use CfdiUtils\Cleaner\Cleaner;
use CfdiUtils\ConsultaCfdiSat\RequestParameters;
use CfdiUtils\Elements\Tfd11\TimbreFiscalDigital;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Utils\Format;
use CfdiUtilsTests\TestCase;
final class ReadCfdiWithTimbreOnSecondComplementoTest extends TestCase
{
public function testRetrieveTimbre(): void
{
$uuid = '11111111-2222-3333-4444-555555555555';
$dirtyXml = $this->createCfdiForTesting($uuid);
$dirtySourceString = $this->obtainSourceString($dirtyXml);
$dirtyCfdi = Cfdi::newFromString($dirtyXml);
$this->assertCount(2, $dirtyCfdi->getNode()->searchNodes('cfdi:Complemento')); // expected 2 complemento
// none of this methods retrieve the correct UUID (verification that the problem exists)
$this->assertEmpty(
$dirtyCfdi->getQuickReader()->complemento->timbreFiscalDigital['UUID'],
'Expected empty UUID from dirty CFDI using QuickReader'
);
$this->assertEmpty(
$dirtyCfdi->getNode()->searchAttribute('cfdi:Complemento', 'tfd:TimbreFiscalDigital', 'UUID'),
'Expected empty UUID from dirty CFDI using NodeInterface::searchAttribute'
);
$this->assertEmpty(
RequestParameters::createFromCfdi($dirtyCfdi)->getUuid(),
'Expected empty UUID from dirty CFDI using RequestParameters'
);
// perform cleaning
$cleaner = new Cleaner($dirtyXml);
$cleaner->collapseComprobanteComplemento();
$cleanXml = $cleaner->retrieveXml();
$cleanSourceString = $this->obtainSourceString($dirtyXml);
$cleanCfdi = Cfdi::newFromString($cleanXml);
$this->assertCount(1, $cleanCfdi->getNode()->searchNodes('cfdi:Complemento')); // expected 1 complemento
$this->assertSame($dirtySourceString, $cleanSourceString, 'Source string after cleaning must be the same');
// assert that the TimbreFiscalDigital can be read using QuickReader
$this->assertSame(
$uuid,
$cleanCfdi->getQuickReader()->complemento->timbreFiscalDigital['UUID'],
'Cannot get UUID using QuickReader'
);
// assert that the TimbreFiscalDigital can be read using Node
$this->assertSame(
$uuid,
$cleanCfdi->getNode()->searchAttribute('cfdi:Complemento', 'tfd:TimbreFiscalDigital', 'UUID'),
'Cannot get UUID using NodeInterface::searchAttribute'
);
// assert that the TimbreFiscalDigital can be read using RequestParameters
$this->assertSame(
$uuid,
RequestParameters::createFromCfdi($cleanCfdi)->getUuid(),
'Cannot get UUID using RequestParameters'
);
}
protected function createCfdiForTesting(string $uuid): string
{
$cerfile = $this->utilAsset('certs/EKU9003173C9.cer');
$keyfile = $this->utilAsset('certs/EKU9003173C9.key.pem');
$certificado = new Certificado($cerfile);
$fecha = strtotime('now - 10 minutes');
$creator = new CfdiCreator33();
$creator->putCertificado($certificado);
$creator->setXmlResolver($this->newResolver());
$comprobante = $creator->comprobante();
$comprobante->addAttributes([
'Serie' => 'XXX',
'Folio' => '0000123456',
'Fecha' => Format::datetime($fecha),
'FormaPago' => '01', // efectivo
'Moneda' => 'USD',
'TipoCambio' => Format::number(18.9008, 4),
'TipoDeComprobante' => 'I', // ingreso
'LugarExpedicion' => '52000',
]);
$comprobante['MetodoPago'] = 'PUE'; // Pago en una sola exhibición
$comprobante->addEmisor([
'RegimenFiscal' => '601', // General de Ley Personas Morales
]);
$comprobante->addReceptor([
'Rfc' => 'COSC8001137NA',
'Nombre' => 'Carlos Cortés Soto', // note is an "e" with accent
'UsoCFDI' => 'G01', // Adquisición de mercancias
]);
$comprobante->addConcepto([
'ClaveProdServ' => '52161557', // Consola portátil de juegos de computador
'NoIdentificacion' => 'GAMEPAD007',
'Cantidad' => '4',
'ClaveUnidad' => 'H87', // Pieza
'Unidad' => 'PIEZA',
'Descripcion' => 'Portable tetris gamepad pro++',
'ValorUnitario' => '500',
'Importe' => '2000',
'Descuento' => '500', // hot sale: take 4, pay only 3
])->addTraslado([
'Base' => '1500',
'Impuesto' => '002', // IVA
'TipoFactor' => 'Tasa', // this is a catalog
'TasaOCuota' => '0.160000', // this is also a catalog
'Importe' => '240',
]);
$creator->addSumasConceptos(null, 2);
// agregar el primer complemento
$leyenda = new Node('leyendasFisc:LeyendasFiscales', [
'xmlns:leyendasFisc' => 'http://www.sat.gob.mx/leyendasFiscales',
'xsi:schemaLocation' => 'http://www.sat.gob.mx/leyendasFiscales'
. ' http://www.sat.gob.mx/sitio_internet/cfd/leyendasFiscales/leyendasFisc.xsd',
'version' => '1.0',
], [
new Node('leyendasFisc:Leyenda', ['textoLeyenda' => 'Esto es una prueba sobre un CFDI falso']),
]);
$comprobante->addComplemento($leyenda);
// sellar el archivo
$creator->addSello('file://' . $keyfile);
// validar que no tiene errores
$asserts = $creator->validate();
if ($asserts->hasErrors() || $asserts->hasWarnings()) {
print_r([
'warnings' => $asserts->warnings(),
'errors' => $asserts->errors(),
]);
throw new \RuntimeException('The PRECFDI created for testing has errors');
}
// agregar un timbre fiscal digital falso sobre un segundo nodo de complemento
$segundoComplemento = new Node('cfdi:Complemento', [], [
new TimbreFiscalDigital([
'UUID' => $uuid,
'FechaTimbrado' => Format::datetime($fecha + 60),
'selloCFD' => str_repeat('0', 344),
'noCertificadoSAT' => '00001000000000000001',
'selloSAT' => str_repeat('1', 344),
]),
]);
$comprobante->addChild($segundoComplemento);
return $creator->asXml();
}
protected function obtainSourceString(string $dirtyXml): string
{
return (new DOMBuilder())->build(
$dirtyXml,
$this->newResolver()->resolve(CfdiDefaultLocations::location('3.3'))
);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/TimbreFiscalDigital/TfdCadenaDeOrigenTest.php | tests/CfdiUtilsTests/TimbreFiscalDigital/TfdCadenaDeOrigenTest.php | <?php
namespace CfdiUtilsTests\TimbreFiscalDigital;
use CfdiUtils\Cfdi;
use CfdiUtils\Nodes\XmlNodeUtils;
use CfdiUtils\TimbreFiscalDigital\TfdCadenaDeOrigen;
use CfdiUtils\XmlResolver\XmlResolver;
use CfdiUtilsTests\TestCase;
final class TfdCadenaDeOrigenTest extends TestCase
{
public function testConstructorMinimal(): void
{
$tfdCO = new TfdCadenaDeOrigen();
$this->assertInstanceOf(XmlResolver::class, $tfdCO->getXmlResolver());
}
public function testConstructorWithXmlResolver(): void
{
$resolver = $this->newResolver();
$tfdCO = new TfdCadenaDeOrigen($resolver);
$this->assertSame($resolver, $tfdCO->getXmlResolver());
}
public function testObtainVersion11WithoutVersionArgument(): void
{
$cfdi = Cfdi::newFromString(strval(file_get_contents($this->utilAsset('cfdi33-valid.xml'))));
$tfd = $cfdi->getNode()->searchNode('cfdi:Complemento', 'tfd:TimbreFiscalDigital');
if (null === $tfd) {
$this->fail('Cannot get the tfd:TimbreFiscalDigital node');
}
$tfdXml = XmlNodeUtils::nodeToXmlString($tfd);
$tfdCO = new TfdCadenaDeOrigen();
$cadenaOrigen = $tfdCO->build($tfdXml);
$expected = '||' . str_replace('||', '|', implode('|', [
$tfd['Version'],
$tfd['UUID'],
$tfd['FechaTimbrado'],
$tfd['RfcProvCertif'],
$tfd['Leyenda'],
$tfd['SelloCFD'],
$tfd['NoCertificadoSAT'],
])) . '||';
$this->assertSame($expected, $cadenaOrigen);
}
public function testXsltLocation(): void
{
$this->assertStringContainsString('TFD_1_0.xslt', TfdCadenaDeOrigen::xsltLocation('1.0'));
$this->assertStringContainsString('TFD_1_1.xslt', TfdCadenaDeOrigen::xsltLocation('1.1'));
}
public function testXsltLocationException(): void
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Cannot get the xslt location');
TfdCadenaDeOrigen::xsltLocation('');
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/tests/CfdiUtilsTests/TimbreFiscalDigital/TfdVersionTest.php | tests/CfdiUtilsTests/TimbreFiscalDigital/TfdVersionTest.php | <?php
namespace CfdiUtilsTests\TimbreFiscalDigital;
use CfdiUtils\Nodes\Node;
use CfdiUtils\Nodes\XmlNodeUtils;
use CfdiUtils\TimbreFiscalDigital\TfdVersion;
use CfdiUtilsTests\TestCase;
final class TfdVersionTest extends TestCase
{
public function providerTfdVersion(): array
{
return [
'1.1' => ['1.1', 'Version', '1.1'],
'1.0' => ['1.0', 'version', '1.0'],
'1.1 bad case' => ['', 'version', '1.1'],
'1.0 bad case' => ['', 'Version', '1.0'],
'1.1 non set' => ['', 'Version', null],
'1.0 non set' => ['', 'version', null],
'1.1 empty' => ['', 'Version', ''],
'1.0 empty' => ['', 'version', ''],
'1.1 wrong number' => ['', 'Version', '2.1'],
'1.0 wrong number' => ['', 'version', '2.0'],
];
}
/**
* @dataProvider providerTfdVersion
*/
public function testTfdVersion(string $expected, string $attribute, ?string $value): void
{
$node = new Node('tfd', [$attribute => $value]);
$tfdVersion = new TfdVersion();
$this->assertSame($expected, $tfdVersion->getFromNode($node));
$this->assertSame($expected, $tfdVersion->getFromXmlString(XmlNodeUtils::nodeToXmlString($node)));
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/BaseCliApplication.php | development/BaseCliApplication.php | <?php
declare(strict_types=1);
namespace CfdiUtils\Development;
abstract class BaseCliApplication
{
/** @var string[] */
private array $arguments;
abstract public function printHelp(): void;
abstract public function execute(): int;
final public function __construct(private string $command, string ...$arguments)
{
$this->arguments = $arguments;
}
public function __invoke(): int
{
if ([] !== array_intersect(['-h', '--help'], $this->arguments)) {
$this->printHelp();
return 0;
}
try {
return $this->execute();
} catch (\Throwable $exception) {
file_put_contents('php://stderr', $exception->getMessage() . PHP_EOL, FILE_APPEND);
// file_put_contents('php://stderr', get_class($exception) . ': ' . $exception->getMessage() . PHP_EOL, FILE_APPEND);
// file_put_contents('php://stderr', $exception->getTraceAsString() . PHP_EOL, FILE_APPEND);
return min(1, $exception->getCode());
}
}
public function getCommand(): string
{
return $this->command;
}
/** @return string[] */
public function getArguments(): array
{
return $this->arguments;
}
public function getArgument(int $index): string
{
return $this->arguments[$index] ?? '';
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/ElementsMaker/SpecificationsReader.php | development/ElementsMaker/SpecificationsReader.php | <?php
declare(strict_types=1);
namespace CfdiUtils\Development\ElementsMaker;
use JsonException;
use RuntimeException;
use stdClass;
final class SpecificationsReader
{
public function __construct(private stdClass $data)
{
}
public static function fromFile(string $specFile): self
{
if (! file_exists($specFile)) {
throw new RuntimeException("Specification file '$specFile' does not exists");
}
$specContents = file_get_contents($specFile);
if (false === $specContents) {
throw new RuntimeException("Unable to read $specFile");
}
return self::fromJsonString($specContents);
}
public static function fromJsonString(string $specContents): self
{
try {
$data = json_decode($specContents, false, 512, JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
throw new RuntimeException('Unable to parse the JSON specification', 0, $exception);
}
if (! $data instanceof stdClass) {
throw new RuntimeException('The JSON specification does not contains a valid root object');
}
return new self($data);
}
public function keyAsString(string $name): string
{
if (! isset($this->data->{$name})) {
return '';
}
if (! is_string($this->data->{$name})) {
return '';
}
return $this->data->{$name};
}
public function keyAsStdClass(string $name): stdClass
{
if (! isset($this->data->{$name})) {
return (object) [];
}
if (! $this->data->{$name} instanceof stdClass) {
return (object) [];
}
return $this->data->{$name};
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/ElementsMaker/Specifications.php | development/ElementsMaker/Specifications.php | <?php
declare(strict_types=1);
namespace CfdiUtils\Development\ElementsMaker;
final class Specifications
{
public function __construct(private Structure $structure, private Dictionary $dictionary)
{
}
public static function makeFromFile(string $specFile): self
{
$specFileReader = SpecificationsReader::fromFile($specFile);
$structure = Structure::makeFromStdClass(
$specFileReader->keyAsString('root-element'),
$specFileReader->keyAsStdClass('structure')
);
$dictionary = new Dictionary([
'#php-namespace#' => $specFileReader->keyAsString('php-namespace'),
'#prefix#' => $specFileReader->keyAsString('prefix'),
'#xml-namespace#' => $specFileReader->keyAsString('xml-namespace'),
'#xml-schemalocation#' => $specFileReader->keyAsString('xml-schemalocation'),
'#version-attribute#' => $specFileReader->keyAsString('version-attribute'),
'#version-value#' => $specFileReader->keyAsString('version-value'),
]);
return new self($structure, $dictionary);
}
public function getStructure(): Structure
{
return $this->structure;
}
public function getDictionary(): Dictionary
{
return $this->dictionary;
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/ElementsMaker/ElementsMaker.php | development/ElementsMaker/ElementsMaker.php | <?php
declare(strict_types=1);
namespace CfdiUtils\Development\ElementsMaker;
final class ElementsMaker
{
/** @var array<string, string> */
private array $templates = [];
public function __construct(private Specifications $specs, private string $outputDir)
{
}
public static function make(string $specFile, string $outputDir): self
{
return new self(Specifications::makeFromFile($specFile), $outputDir);
}
public function write(): void
{
$this->createElement($this->specs->getStructure(), $this->specs->getDictionary(), true);
}
public function createElement(Structure $structure, Dictionary $dictionary, bool $isRoot = false): void
{
$prefix = $dictionary->get('#prefix#');
$dictionary = $dictionary->with('#element-name#', $structure->getName());
$sectionsContent = [];
$orderElements = $structure->getChildrenNames($prefix . ':');
if (count($orderElements) > 1) {
$sectionsContent[] = $this->template(
'get-children-order',
new Dictionary(['#elements#' => $this->elementsToString($orderElements)])
);
}
if ($isRoot) {
$sectionsContent[] = $this->template('get-fixed-attributes', $dictionary);
}
/** @var Structure $child */
foreach ($structure as $child) {
$childTemplate = ($child->isMultiple()) ? 'child-multiple' : 'child-single';
$sectionsContent[] = $this->template($childTemplate, new Dictionary(['#child-name#' => $child->getName()]));
$this->createElement($child, $dictionary);
}
$contents = $this->template('element', $dictionary->with('#sections#', implode('', $sectionsContent)));
$outputFile = $this->buildOutputFile($structure->getName());
file_put_contents($outputFile, $contents);
}
private function template(string $templateName, Dictionary $dictionary): string
{
if (! isset($this->templates[$templateName])) {
$fileName = __DIR__ . '/templates/' . $templateName . '.template';
$this->templates[$templateName] = file_get_contents($fileName) ?: '';
}
return $dictionary->interpolate($this->templates[$templateName]);
}
private function buildOutputFile(string $elementName): string
{
return $this->outputDir . DIRECTORY_SEPARATOR . $elementName . '.php';
}
/** @param string[] $array */
private function elementsToString(array $array): string
{
$parts = [];
foreach ($array as $value) {
$parts[] = var_export($value, true);
}
return "[\n" . implode(",\n", $parts) . "\n]";
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/ElementsMaker/Dictionary.php | development/ElementsMaker/Dictionary.php | <?php
declare(strict_types=1);
namespace CfdiUtils\Development\ElementsMaker;
final class Dictionary
{
/** @param array<string, string> $values */
public function __construct(private array $values)
{
}
public function get(string $key): string
{
return $this->values[$key] ?? '';
}
public function with(string $key, string $value): self
{
return new self(array_merge($this->values, [$key => $value]));
}
/** @return array<string, string> $values */
public function getValues(): array
{
return $this->values;
}
public function interpolate(string $subject): string
{
return strtr($subject, $this->values);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/ElementsMaker/Structure.php | development/ElementsMaker/Structure.php | <?php
declare(strict_types=1);
namespace CfdiUtils\Development\ElementsMaker;
use ArrayIterator;
use Countable;
use IteratorAggregate;
use stdClass;
use Traversable;
final class Structure implements Countable, IteratorAggregate
{
/** @var Structure[] */
private array $children;
public function __construct(private string $name, private bool $multiple, self ...$children)
{
$this->children = $children;
}
public static function makeFromStdClass(string $name, stdClass $data): self
{
$multiple = false;
if (isset($data->{'multiple'}) && is_bool($data->{'multiple'})) {
$multiple = $data->{'multiple'};
}
$children = [];
foreach (get_object_vars($data) as $key => $value) {
if ($value instanceof stdClass) {
$children[] = self::makeFromStdClass($key, $value);
}
}
return new self($name, $multiple, ...$children);
}
public function getName(): string
{
return $this->name;
}
public function isMultiple(): bool
{
return $this->multiple;
}
public function getChildren(): array
{
return $this->children;
}
/** @return Traversable<int, Structure> */
public function getIterator(): Traversable
{
return new ArrayIterator($this->children);
}
/** @return string[] */
public function getChildrenNames(string $prefix): array
{
return array_unique(
array_map(
fn (self $structure): string => $prefix . $structure->getName(),
$this->children
)
);
}
public function count(): int
{
return count($this->children);
}
}
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
eclipxe13/CfdiUtils | https://github.com/eclipxe13/CfdiUtils/blob/6786b3ee34831ef0d633302226414682a7a35aca/development/bin/elements-maker.php | development/bin/elements-maker.php | <?php
use CfdiUtils\Development\BaseCliApplication;
use CfdiUtils\Development\ElementsMaker\ElementsMaker;
require __DIR__ . '/../../vendor/autoload.php';
exit(call_user_func(new class (...$argv) extends BaseCliApplication {
public function printHelp(): void
{
$command = basename($this->getCommand());
echo implode(PHP_EOL, [
"$command - Creación de elementos a partir de una especificación.",
'Sintaxis: ',
"$command specification-file output-directory",
' specification-file: the location of the specification file',
' output-directory: the location where files should be written',
'',
]);
}
public function execute(): int
{
$specFile = $this->getArgument(0);
if ('' === $specFile) {
throw new RuntimeException('Argument specification-file not set');
}
$outputDir = $this->getArgument(1);
if ('' === $outputDir) {
throw new RuntimeException('Argument output-directory not set');
}
$elementsMaker = ElementsMaker::make($specFile, $outputDir);
$elementsMaker->write();
return 0;
}
}));
| php | MIT | 6786b3ee34831ef0d633302226414682a7a35aca | 2026-01-05T04:57:52.988826Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/aliases.php | src/aliases.php | <?php
declare(strict_types=1);
namespace DataDog\AuditBundle;
use DataDog\AuditBundle\DBAL\Middleware\ConnectionMiddleware;
use DataDog\AuditBundle\DBAL\Middleware\ConnectionMiddlewareForV3;
use DataDog\AuditBundle\DBAL\Middleware\ConnectionMiddlewareForV4;
use Doctrine\DBAL\VersionAwarePlatformDriver;
if (!class_exists(ConnectionMiddleware::class)) {
if (!interface_exists(VersionAwarePlatformDriver::class)) {
class_alias(ConnectionMiddlewareForV4::class, ConnectionMiddleware::class);
} else {
class_alias(ConnectionMiddlewareForV3::class, ConnectionMiddleware::class);
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DataDogAuditBundle.php | src/DataDogAuditBundle.php | <?php
namespace DataDog\AuditBundle;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class DataDogAuditBundle extends Bundle
{
public function build(ContainerBuilder $container): void
{
parent::build($container);
if (class_exists(DoctrineOrmMappingsPass::class)) {
$namespaces = [__DIR__.'/../config/doctrine' => 'DataDog\\AuditBundle\\Entity'];
$container->addCompilerPass(
DoctrineOrmMappingsPass::createXmlMappingDriver($namespaces)
);
}
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/Entity/AuditLog.php | src/Entity/AuditLog.php | <?php
namespace DataDog\AuditBundle\Entity;
class AuditLog
{
private ?string $id;
private string $action;
private string $tbl;
private Association $source;
private ?Association $target;
private ?Association $blame;
private ?array $diff;
private \DateTimeInterface $loggedAt;
public function getId(): ?string
{
return $this->id;
}
public function getAction(): string
{
return $this->action;
}
public function getTbl(): string
{
return $this->tbl;
}
public function getSource(): Association
{
return $this->source;
}
public function getTarget(): ?Association
{
return $this->target;
}
public function getBlame(): ?Association
{
return $this->blame;
}
public function getDiff(): ?array
{
return $this->diff;
}
public function getLoggedAt(): \DateTimeInterface
{
return $this->loggedAt;
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/Entity/Association.php | src/Entity/Association.php | <?php
namespace DataDog\AuditBundle\Entity;
class Association
{
private ?string $id;
private string $typ;
private ?string $tbl;
private ?string $label;
private int $fk;
private string $class;
public function getId(): ?string
{
return $this->id;
}
public function getTyp(): string
{
return $this->typ;
}
public function getTypLabel(): string
{
$words = \explode('.', $this->getTyp());
return \implode(' ', \array_map('ucfirst', \explode('_', \end($words))));
}
public function getTbl(): ?string
{
return $this->tbl;
}
public function getLabel(): ?string
{
return $this->label;
}
public function getFk(): int
{
return $this->fk;
}
public function getClass(): string
{
return $this->class;
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DependencyInjection/Configuration.php | src/DependencyInjection/Configuration.php | <?php
namespace DataDog\AuditBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
// @formatter:off
$treeBuilder = new TreeBuilder('data_dog_audit');
$treeBuilder->getRootNode()
->validate()
->ifTrue(fn ($v) => !empty($v['entities']) && (!empty($v['audited_entities']) || !empty($v['unaudited_entities'])))
->thenInvalid('If you use the "entities" config you cannot use "audited_entities" and/or "unaudited_entities"')
->end()
->children()
->arrayNode('entities')->canBeUnset()->useAttributeAsKey('key')
->arrayPrototype()
->children()
->enumNode('mode')->values(['include', 'exclude'])->isRequired()->cannotBeEmpty()->end()
->arrayNode('fields')
->prototype('scalar')->end()
->end()
->end()
->end()
->end()
->end()
->children()
->arrayNode('audited_entities')
->setDeprecated('data-dog/audit-bundle', 'v1.2', 'Not setting the "%node%" config option is deprecated. Use the "entities" option instead.')
->canBeUnset()
->performNoDeepMerging()
->scalarPrototype()->end()
->end()
->end()
->children()
->arrayNode('unaudited_entities')
->setDeprecated('data-dog/audit-bundle', 'v1.2', 'Not setting the "%node%" config option is deprecated. Use the "entities" option instead.')
->canBeUnset()
->performNoDeepMerging()
->scalarPrototype()->end()
->end()
->end()
->children()
->booleanNode('blame_impersonator')
->defaultFalse()
->end()
;
// @formatter:on
return $treeBuilder;
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DependencyInjection/DataDogAuditExtension.php | src/DependencyInjection/DataDogAuditExtension.php | <?php
namespace DataDog\AuditBundle\DependencyInjection;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
class DataDogAuditExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../../config'));
$loader->load('services.php');
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$auditListener = $container->getDefinition('data_dog_audit.listener.audit');
if (isset($config['entities'])) {
$auditListener->addMethodCall('addEntities', [$config['entities']]);
} elseif (isset($config['audited_entities']) && !empty($config['audited_entities'])) {
$auditListener->addMethodCall('addAuditedEntities', [$config['audited_entities']]);
} elseif (isset($config['unaudited_entities'])) {
$auditListener->addMethodCall('addUnauditedEntities', [$config['unaudited_entities']]);
}
if (isset($config['blame_impersonator'])) {
$auditListener->addMethodCall('setBlameImpersonator', [$config['blame_impersonator']]);
}
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DBAL/Middleware/AuditFlushMiddleware.php | src/DBAL/Middleware/AuditFlushMiddleware.php | <?php
namespace DataDog\AuditBundle\DBAL\Middleware;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsMiddleware;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Middleware;
#[AsMiddleware(connections: ['default'])]
class AuditFlushMiddleware implements Middleware
{
/**
* @var array<object, string>
*/
public ?array $flushHandler = null;
public function wrap(Driver $driver): Driver
{
return new DriverMiddleware($driver, $this);
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DBAL/Middleware/ConnectionMiddlewareForV3.php | src/DBAL/Middleware/ConnectionMiddlewareForV3.php | <?php
namespace DataDog\AuditBundle\DBAL\Middleware;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
class ConnectionMiddlewareForV3 extends AbstractConnectionMiddleware
{
public function __construct(
Connection $wrappedConnection,
private readonly AuditFlushMiddleware $auditFlushMiddleware
)
{
parent::__construct($wrappedConnection);
}
/**
* Override of the commit method
*
* @throws Exception
*/
public function commit()
{
// Call the flusher callback if it's available.
if ($this->auditFlushMiddleware->flushHandler !== null) {
($this->auditFlushMiddleware->flushHandler)();
$this->auditFlushMiddleware->flushHandler = null;
}
// Call the parent's commit method
return parent::commit();
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DBAL/Middleware/ConnectionMiddlewareForV4.php | src/DBAL/Middleware/ConnectionMiddlewareForV4.php | <?php
namespace DataDog\AuditBundle\DBAL\Middleware;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\Middleware\AbstractConnectionMiddleware;
class ConnectionMiddlewareForV4 extends AbstractConnectionMiddleware
{
public function __construct(
Connection $wrappedConnection,
private readonly AuditFlushMiddleware $auditFlushMiddleware
)
{
parent::__construct($wrappedConnection);
}
/**
* Override of the commit method
*
* @throws Exception
*/
public function commit(): void
{
// Call the flusher callback if it's available.
if ($this->auditFlushMiddleware->flushHandler !== null) {
($this->auditFlushMiddleware->flushHandler)();
$this->auditFlushMiddleware->flushHandler = null;
}
// Call the parent's commit method
parent::commit();
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
DATA-DOG/DataDogAuditBundle | https://github.com/DATA-DOG/DataDogAuditBundle/blob/c85c0cf8596181376a9f00e44da9950572067743/src/DBAL/Middleware/DriverMiddleware.php | src/DBAL/Middleware/DriverMiddleware.php | <?php
namespace DataDog\AuditBundle\DBAL\Middleware;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Driver\Middleware\AbstractDriverMiddleware;
class DriverMiddleware extends AbstractDriverMiddleware
{
public function __construct(
Driver $driver,
private readonly AuditFlushMiddleware $auditFlushMiddleware
)
{
parent::__construct($driver);
}
public function connect(array $params): Connection
{
return new ConnectionMiddleware(parent::connect($params), $this->auditFlushMiddleware);
}
}
| php | MIT | c85c0cf8596181376a9f00e44da9950572067743 | 2026-01-05T04:58:02.995658Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.