Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[TASK] Replace Integration tests with xmllint #686

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ jobs:
with:
php-versions: "['8.1', '8.2']"
test-suite: "integration"

xml-lint:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"

- name: "Install libxml2-utils"
run: |
sudo apt-get update
sudo apt -y install libxml2-utils

- name: "Lint xml configs"
run: "tools/xmllint.sh"
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ psalm:
$(PHP_BIN) vendor/bin/psalm --update-baseline

.PHONY: test
test: test-unit test-functional test-integration test-docs## Runs all test suites with phpunit/phpunit
test: test-unit test-functional test-integration test-xml test-docs## Runs all test suites with phpunit/phpunit

.PHONY: test-unit
test-unit: ## Runs unit tests with phpunit/phpunit
Expand All @@ -42,6 +42,10 @@ test-functional: ## Runs functional tests with phpunit/phpunit
test-integration: ## Runs integration tests with phpunit/phpunit
$(PHP_BIN) vendor/bin/phpunit --testsuite=integration

.PHONY: test-xml
test-xml: ## Lint all guides.xml
./tools/xmllint.sh

.PHONY: test-docs
test-docs: ## Generate projects docs without warnings
$(PHP_BIN) vendor/bin/guides -vvv --no-progress docs --output="/tmp/test" --fail-on-log
Expand Down
64 changes: 0 additions & 64 deletions tests/Integration/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace phpDocumentor\Guides\Integration;

use DOMDocument;
use phpDocumentor\Guides\ApplicationTestCase;
use phpDocumentor\Guides\Cli\Command\Run;
use PHPUnit\Framework\Attributes\DataProvider;
Expand All @@ -22,11 +21,7 @@
use function file_exists;
use function file_get_contents;
use function implode;
use function libxml_clear_errors;
use function libxml_get_errors;
use function libxml_use_internal_errors;
use function setlocale;
use function sprintf;
use function str_ends_with;
use function str_replace;
use function system;
Expand Down Expand Up @@ -174,65 +169,6 @@ public static function getTestsForLatex(): array
return self::getTestsForDirectory(__DIR__ . '/tests-latex');
}

#[DataProvider('getTestsWithGuidesXmlForDirectoryTest')]
public function testXmlValidation(string $xmlFile): void
{
$xsdFile = 'packages/guides-cli/resources/schema/guides.xsd';
libxml_use_internal_errors(true);
// Create a DOMDocument for XML validation
$dom = new DOMDocument();
$dom->load($xmlFile);

// Validate against XSD schema
$isValid = $dom->schemaValidate($xsdFile);
$errorString = '';

if (!$isValid) {
$errors = libxml_get_errors();

foreach ($errors as $error) {
$errorString .= sprintf("Validation Error at line %s: %s\n", $error->line, $error->message);
}

libxml_clear_errors();
}

self::assertTrue($isValid, 'XML of ' . $xmlFile . ' does not validate against the schema: ' . $errorString);
}

/** @return mixed[] */
public static function getTestsWithGuidesXmlForDirectoryTest(): array
{
return self::getTestsWithGuidesXmlForSubDirectoryTest('tests/Integration/tests');
}

/** @return mixed[] */
private static function getTestsWithGuidesXmlForSubDirectoryTest(string $directory = 'tests'): array
{
$finder = new SymfonyFinder();
$finder
->directories()
->in($directory)
->depth('== 0');

$tests = [];

foreach ($finder as $dir) {
if (!file_exists($dir->getPathname() . '/input')) {
$tests = array_merge($tests, self::getTestsWithGuidesXmlForSubDirectoryTest($dir->getPathname()));
continue;
}

if (!file_exists($dir->getPathname() . '/input/guides.xml')) {
continue;
}

$tests[$dir->getRelativePathname()] = [$dir->getPathname() . '/input/guides.xml'];
}

return $tests;
}

/** @return mixed[] */
private static function getTestsForDirectory(string $directory): array
{
Expand Down
10 changes: 10 additions & 0 deletions tools/xmllint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

schema="packages/guides-cli/resources/schema/guides.xsd"
directory="."

for file in $(find "$directory" -type f -name "guides.xml"); do
xmllint --noout --schema "$schema" "$file"
done