diff --git a/.gitignore b/.gitignore index 592dce7..80956e3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /phpcs.xml /phpstan.neon /phpunit.xml +/tmp/ /vendor/ diff --git a/bin/update-schematron.php b/bin/update-schematron.php index c3903d3..3b93f2d 100755 --- a/bin/update-schematron.php +++ b/bin/update-schematron.php @@ -3,15 +3,22 @@ declare(strict_types=1); +use GitWrapper\GitWrapper; use Symfony\Component\Filesystem\Filesystem; require_once __DIR__.'/../vendor/autoload.php'; $filesystem = new Filesystem(); - -$target = __DIR__.'/../lib/schematron'; - -$base = 'https://github.com/Schematron/schematron/raw/master'; +$git = new GitWrapper(); +$git->streamOutput(); + +$repoUri = 'https://github.com/Schematron/schematron'; +$repoDir = __DIR__.'/../tmp/schematron'; +$patchesDir = __DIR__.'/../tmp/patches'; +$targetDir = __DIR__.'/../lib/schematron'; +$patches = [ + 'https://github.com/Schematron/schematron/pull/81.patch', // Fixes attribute paths. +]; $files = [ 'LICENSE', 'trunk/schematron/code/iso_schematron_skeleton_for_xslt1.xsl', @@ -20,8 +27,29 @@ 'trunk/converters/code/ToSchematron/ExtractSchFromXSD.xsl', ]; -$filesystem->remove(new FilesystemIterator($target)); +if (!$filesystem->exists($repoDir)) { + $filesystem->mkdir($repoDir); + $repo = $git->cloneRepository($repoUri, $repoDir, ['depth' => 1]); +} else { + $repo = $git->workingCopy($repoDir); + $repo->fetch('origin', 'master', ['depth' => 1]); + $repo->reset(['hard' => true], 'origin/master'); +} + +foreach ($patches as $patch) { + $patchTarget = "${patchesDir}/".md5($patch); + + echo "Downloading {$patch} to {$patchTarget}\n"; + $filesystem->copy($patch, $patchTarget); + $repo->apply($patchTarget, ['verbose' => true]); +} + +$filesystem->remove(new FilesystemIterator($targetDir)); foreach ($files as $file) { - $filesystem->copy("{$base}/${file}", "{$target}/".basename($file)); + $origin = "${repoDir}/${file}"; + $target = "${targetDir}/".basename($file); + + echo "Copying {$origin} to {$target}\n"; + $filesystem->copy($origin, $target); } diff --git a/composer.json b/composer.json index 9eb2f0d..3013233 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ }, "require-dev": { "ext-xsl": "*", + "cpliakas/git-wrapper": "^2.0", "libero/coding-standard": "^0.3", "phpstan/phpstan": "^0.10", "phpstan/phpstan-phpunit": "^0.10", diff --git a/lib/schematron/iso_schematron_skeleton_for_xslt1.xsl b/lib/schematron/iso_schematron_skeleton_for_xslt1.xsl index 9a764df..2093a01 100644 --- a/lib/schematron/iso_schematron_skeleton_for_xslt1.xsl +++ b/lib/schematron/iso_schematron_skeleton_for_xslt1.xsl @@ -692,6 +692,7 @@ THE SOFTWARE. + / diff --git a/tests/SchematronValidatorTest.php b/tests/SchematronValidatorTest.php index 9d2821a..18b5566 100644 --- a/tests/SchematronValidatorTest.php +++ b/tests/SchematronValidatorTest.php @@ -50,10 +50,15 @@ public function it_fails_on_invalid(string $format) : void $this->assertEquals( [ new Failure( - 'Must not be empty', + 'Element must not be empty', 6, $xpath->query('/example:parent/example:child')->item(0) ), + new Failure( + 'Attribute must not be empty', + 6, + $xpath->query('/example:parent/example:child/@attribute')->item(0) + ), ], $e->getFailures() ); diff --git a/tests/fixtures/invalid-empty-child.xml b/tests/fixtures/invalid-empty-child.xml index 96cbd1a..fa8a3b2 100644 --- a/tests/fixtures/invalid-empty-child.xml +++ b/tests/fixtures/invalid-empty-child.xml @@ -3,6 +3,6 @@ - + diff --git a/tests/fixtures/schema.dtd b/tests/fixtures/schema.dtd index 098c0a7..a601c07 100644 --- a/tests/fixtures/schema.dtd +++ b/tests/fixtures/schema.dtd @@ -4,4 +4,7 @@ - + diff --git a/tests/fixtures/schema.rng b/tests/fixtures/schema.rng index 92e995b..b86ad09 100644 --- a/tests/fixtures/schema.rng +++ b/tests/fixtures/schema.rng @@ -10,10 +10,20 @@ + + + - Must not be empty + Element must not be empty + + + + + + + Attribute must not be empty diff --git a/tests/fixtures/schema.sch b/tests/fixtures/schema.sch index d3890ff..914f744 100644 --- a/tests/fixtures/schema.sch +++ b/tests/fixtures/schema.sch @@ -7,7 +7,14 @@ - Must not be empty + Element must not be empty + + + + + + + Attribute must not be empty diff --git a/tests/fixtures/schema.xsd b/tests/fixtures/schema.xsd index fba1ce9..aea1451 100644 --- a/tests/fixtures/schema.xsd +++ b/tests/fixtures/schema.xsd @@ -12,18 +12,32 @@ - + - Must not be empty + Element must not be empty + + + + + + + Attribute must not be empty + + + + + + +