Skip to content

Commit

Permalink
Version 2.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
eclipxe13 committed Sep 4, 2018
2 parents 4eea7a0 + b20a499 commit 352184d
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 49 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ script:
- vendor/bin/php-cs-fixer fix --using-cache=no --dry-run --verbose
- |
if [[ $TRAVIS_PHP_VERSION == $FULL_BUILD_PHP_VERSION ]]; then
php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-text --coverage-clover=build/tests/coverage.xml
php -dzend_extension=xdebug.so vendor/bin/phpunit --verbose --coverage-text --coverage-clover=build/tests/coverage.xml
else
vendor/bin/phpunit
vendor/bin/phpunit --verbose
fi
- vendor/bin/phpstan.phar --no-progress analyse --level max src/ tests/
- node node_modules/markdownlint-cli/markdownlint.js *.md docs/
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
"ext-openssl": "*",
"ext-soap": "*",
"ext-iconv": "*",
"eclipxe/xmlresourceretriever": "^1.2",
"eclipxe/xmlschemavalidator": "^2.0.1"
"eclipxe/xmlresourceretriever": "^1.2.1",
"eclipxe/xmlschemavalidator": "^2.0.2"
},
"suggest": {
"genkgo/xsl": "^0.5.20"
},
"require-dev": {
"genkgo/xsl": "^0.5.20",
"phpunit/phpunit": "^6.2",
"phpunit/phpunit": "^6.2|^7.3",
"overtrue/phplint": "^1.0",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^2.4",
Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
The test that are consuming <https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc?singleWsdl>
was moved to a different test case class `WebServiceConsumingTest` and are marked as skipped when `\SoapFault`
is thrown instead of fail
- Fix `xmlns:xsi` definition case to `XMLSchema`
- Allow install phpunit 7 if php >= 7.1
- Fix `phpunit.xml.dist` configuration file removing redundant options and setting missing options
- Solve phpstan 0.10.x issues, not yet upgraded since it contains several bugfixes


## Version 2.6.3 2018-08-21

Expand Down
13 changes: 2 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
verbose="true"
stopOnFailure="false"
processIsolation="false"
backupGlobals="false"
syntaxCheck="true">
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
<testsuites>
<testsuite>
<testsuite name="default">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
Expand Down
22 changes: 15 additions & 7 deletions src/CfdiUtils/Certificado/Certificado.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ public function __construct(string $filename)
}

// get the public key
$pubkey = openssl_get_publickey($contents);
$pubkey = false;
$pubData = false;
try {
$pubData = openssl_pkey_get_details($pubkey);
if (false === $pubData) {
$pubData = ['key' => ''];
$pubkey = openssl_get_publickey($contents);
if (is_resource($pubkey)) {
$pubData = openssl_pkey_get_details($pubkey);
}
} finally {
openssl_free_key($pubkey);
if (is_resource($pubkey)) {
openssl_free_key($pubkey);
}
}
if (false === $pubData) {
$pubData = ['key' => ''];
}

// set all the values
Expand Down Expand Up @@ -104,7 +110,8 @@ public function belongsTo(string $pemKeyFile, string $passPhrase = ''): bool
&& 0 !== strpos($keyContents, '-----BEGIN RSA PRIVATE KEY-----')) {
throw new \UnexpectedValueException("The file $pemKeyFile is not a PEM private key");
}
if (false === $privateKey = openssl_get_privatekey($keyContents, $passPhrase)) {
$privateKey = openssl_get_privatekey($keyContents, $passPhrase);
if (false === $privateKey) {
throw new \RuntimeException("Cannot open the private key file $pemKeyFile");
}
$belongs = openssl_x509_check_private_key($this->getPemContents(), $privateKey);
Expand Down Expand Up @@ -166,7 +173,8 @@ public function getPemContents(): string
*/
public function verify(string $data, string $signature, int $algorithm = OPENSSL_ALGO_SHA256): bool
{
if (false === $pubKey = openssl_get_publickey($this->getPubkey())) {
$pubKey = openssl_get_publickey($this->getPubkey());
if (false === $pubKey) {
throw new \RuntimeException('Cannot open public key from certificate');
}
try {
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/CfdiCreator33.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function putCertificado(Certificado $certificado, bool $putEmisorRfcNombr
$cerfile = $certificado->getFilename();
$this->comprobante['NoCertificado'] = $certificado->getSerial();
if (file_exists($cerfile)) {
$this->comprobante['Certificado'] = base64_encode(file_get_contents($cerfile));
$this->comprobante['Certificado'] = base64_encode((string) file_get_contents($cerfile));
}
if ($putEmisorRfcNombre) {
$this->comprobante->addEmisor([
Expand Down
8 changes: 7 additions & 1 deletion src/CfdiUtils/Cleaner/Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public function removeAddenda()
$addendas = $this->xpathQuery($query);
for ($i = 0; $i < $addendas->length; $i++) {
$addenda = $addendas->item($i);
if (null === $addenda) {
continue;
}
$addenda->parentNode->removeChild($addenda);
}
}
Expand All @@ -169,7 +172,10 @@ public function removeNonSatNSschemaLocations()
}
$schemaLocations = $this->xpathQuery("//@$xsi:schemaLocation");
for ($s = 0; $s < $schemaLocations->length; $s++) {
$this->removeNonSatNSschemaLocation($schemaLocations->item($s));
$element = $schemaLocations->item($s);
if (null !== $element) {
$this->removeNonSatNSschemaLocation($element);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/Nodes/XmlNodeImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function import(DOMElement $element): NodeInterface
$node = new Node($element->tagName);
if ('' !== $element->prefix) {
$this->registerNamespace($node, 'xmlns:' . $element->prefix, $element->namespaceURI);
$this->registerNamespace($node, 'xmlns:xsi', 'http://www.w3.org/2001/xmlschema-instance');
$this->registerNamespace($node, 'xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
}

/** @var \DOMNode $attribute */
Expand Down
2 changes: 1 addition & 1 deletion src/CfdiUtils/PemPrivateKey/PemPrivateKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(string $key)
$contents = '';
$filename = substr($key, 7);
if ('' !== $filename && file_exists($filename) && is_readable($filename) && ! is_dir($filename)) {
$contents = file_get_contents($filename);
$contents = (string) file_get_contents($filename);
}
} else {
$contents = $key;
Expand Down
20 changes: 8 additions & 12 deletions src/CfdiUtils/Validate/Cfdi33/Xml/XmlFollowSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use CfdiUtils\XmlResolver\XmlResolverPropertyInterface;
use CfdiUtils\XmlResolver\XmlResolverPropertyTrait;
use XmlSchemaValidator\Schema;
use XmlSchemaValidator\Schemas;
use XmlSchemaValidator\SchemaValidator;
use XmlSchemaValidator\SchemaValidatorException;

/**
* XmlFollowSchema
Expand Down Expand Up @@ -50,14 +52,12 @@ public function validate(NodeInterface $comprobante, Asserts $asserts)

// validate using resolver->retriever or using the simple method
try {
$schemas = $schemaValidator->buildSchemas();
if ($this->hasXmlResolver() && $this->getXmlResolver()->hasLocalPath()) {
$this->validateUsingRetriever($schemaValidator);
} else {
if (! $schemaValidator->validate()) {
throw new \Exception($schemaValidator->getLastError());
}
$schemas = $this->changeSchemasUsingRetriever($schemas);
}
} catch (\Exception $exception) {
$schemaValidator->validateWithSchemas($schemas);
} catch (SchemaValidatorException $exception) {
// validate failure
$assert->setStatus(Status::error(), $exception->getMessage());
$asserts->mustStop(true);
Expand All @@ -68,14 +68,11 @@ public function validate(NodeInterface $comprobante, Asserts $asserts)
$assert->setStatus(Status::ok());
}

private function validateUsingRetriever(SchemaValidator $schemaValidator)
private function changeSchemasUsingRetriever(Schemas $schemas): Schemas
{
// obtain the retriever, throw its own exception if non set
$retriever = $this->getXmlResolver()->newXsdRetriever();

// obtain the list of schemas
$schemas = $schemaValidator->buildSchemas();

// replace the schemas locations with the retrieved local path
/** @var Schema $schema */
foreach ($schemas as $schema) {
Expand All @@ -88,7 +85,6 @@ private function validateUsingRetriever(SchemaValidator $schemaValidator)
$schemas->insert(new Schema($schema->getNamespace(), $localPath));
}

// validate using the modified schemas
$schemaValidator->validateWithSchemas($schemas);
return $schemas;
}
}
8 changes: 6 additions & 2 deletions tests/CfdiUtilsTests/Nodes/XmlNodeUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function testImportFromSimpleXmlElement()
$this->assertCount(1, $node);
$this->assertSame('1', $node['id']);
$child = $node->children()->firstNodeWithName('child');
$this->assertSame('2', $child['id']);
$this->assertCount(0, $child);
if (null === $child) {
$this->fail('firstNodeWithName did not return a Node');
} else {
$this->assertSame('2', $child['id']);
$this->assertCount(0, $child);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function testSamplesFiles($sampleName)

$validator = new CfdiValidator33();
$asserts = $validator->validateXml(file_get_contents($sampleFile));
// Remove this tests! we are using manipulated cfdi
// Remove this assertions because we are using manipulated cfdi
$asserts->removeByCode('SELLO08');
$asserts->removeByCode('EMISORRFC01');
/* // Developer, use this to check what fail
foreach ($asserts->errors() as $error) {
echo sprintf("\t%s: %s => %s" . PHP_EOL, $error->getCode(), $error->getTitle(), $error->getExplanation());
$errors = $asserts->errors();
if (count($errors)) { // display errors!
foreach ($asserts->errors() as $error) {
echo PHP_EOL, ' *** ', strval($error), ' => ', $error->getExplanation();
}
}
// */
$this->assertFalse($asserts->hasErrors());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/estadosat.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$webService = new WebService();

foreach ($files as $file) {
$cfdi = \CfdiUtils\Cfdi::newFromString(file_get_contents($file));
$cfdi = \CfdiUtils\Cfdi::newFromString((string) file_get_contents($file));
$request = \CfdiUtils\ConsultaCfdiSat\RequestParameters::createFromCfdi($cfdi);
$response = $webService->request($request);

Expand Down
2 changes: 1 addition & 1 deletion tests/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$validator->getXmlResolver()->setLocalPath('');
}
foreach ($files as $file) {
$asserts = $validator->validateXml(file_get_contents($file));
$asserts = $validator->validateXml((string) file_get_contents($file));
print_r(array_filter([
'file' => $file,
'asserts' => $asserts->count(),
Expand Down

0 comments on commit 352184d

Please sign in to comment.