From 5308eb3d9b05eb6ad9492e0c47346457695d68f5 Mon Sep 17 00:00:00 2001 From: Daniel Carbone Date: Thu, 26 Dec 2024 10:19:41 -0600 Subject: [PATCH] working on core tests a bit --- .github/workflows/tests.yaml | 19 ++--- phpunit/Core.xml | 1 - phpunit/DSTU1.xml | 1 - phpunit/DSTU2.xml | 1 - phpunit/R4.xml | 1 - phpunit/R5.xml | 1 - phpunit/STU3.xml | 1 - .../core/classes/class_factory_config.php | 10 +++ template/core/tests/test_class_config.php | 65 ---------------- .../core/tests/test_class_factory_config.php | 77 +++++++++++++++++++ 10 files changed, 97 insertions(+), 80 deletions(-) delete mode 100644 template/core/tests/test_class_config.php create mode 100644 template/core/tests/test_class_factory_config.php diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index bd670d44..2208a57b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,20 +31,20 @@ jobs: strategy: fail-fast: true matrix: - fhir-version: + test-target: - 'DSTU1' - 'DSTU2' - 'STU3' - 'R4' - 'R5' - name: 'Download ${{ matrix.fhir-version }} Source' + name: 'Download ${{ matrix.test-target }} Source' steps: - uses: actions/checkout@v4 - uses: ./.github/actions/load-fhir-xsd with: - version: '${{ matrix.fhir-version }}' + version: '${{ matrix.test-target }}' # load-fhir-validator: @@ -68,7 +68,8 @@ jobs: - '8.2' - '8.3' - '8.4' - fhir-version: + test-target: + - 'Core' - 'DSTU1' - 'DSTU2' - 'STU3' @@ -84,15 +85,15 @@ jobs: - php-version: '8.3' phpunit-version: '11.1' - name: '${{ matrix.fhir-version }} - PHP ${{ matrix.php-version }} - PHPUnit ${{ matrix.phpunit-version }}' + name: '${{ matrix.test-target }} - PHP ${{ matrix.php-version }} - PHPUnit ${{ matrix.phpunit-version }}' steps: - name: 'Check the stuff out' uses: actions/checkout@v4 - - name: 'Load FHIR ${{ matrix.fhir-version }} Source' + - name: 'Load FHIR ${{ matrix.test-target }} Source' uses: ./.github/actions/load-fhir-xsd with: - version: '${{ matrix.fhir-version }}' + version: '${{ matrix.test-target }}' # - name: 'Install FHIR validator' # uses: ./.github/actions/load-fhir-validator @@ -145,7 +146,7 @@ jobs: - name: 'Generate code' # language=sh run: | - ./bin/generate.sh --useExisting --versions '${{ matrix.fhir-version }}' + ./bin/generate.sh --useExisting --versions '${{ matrix.test-target }}' # - name: 'Install Java' # uses: actions/setup-java@v4 @@ -156,4 +157,4 @@ jobs: - name: 'Run tests' # language=sh run: | - ./vendor/bin/phpunit -c 'phpunit/${{ matrix.fhir-version }}.xml' --display-warnings --display-skipped + ./vendor/bin/phpunit -c 'phpunit/${{ matrix.test-target }}.xml' --display-warnings --display-skipped diff --git a/phpunit/Core.xml b/phpunit/Core.xml index d21ad4b2..5589aaae 100644 --- a/phpunit/Core.xml +++ b/phpunit/Core.xml @@ -5,7 +5,6 @@ colors="true" stopOnFailure="false" displayDetailsOnIncompleteTests="true" - displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/phpunit/DSTU1.xml b/phpunit/DSTU1.xml index 10f81712..71205f67 100644 --- a/phpunit/DSTU1.xml +++ b/phpunit/DSTU1.xml @@ -5,7 +5,6 @@ colors="true" stopOnFailure="false" displayDetailsOnIncompleteTests="true" - displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/phpunit/DSTU2.xml b/phpunit/DSTU2.xml index f08e342e..bde12798 100644 --- a/phpunit/DSTU2.xml +++ b/phpunit/DSTU2.xml @@ -5,7 +5,6 @@ colors="true" stopOnFailure="false" displayDetailsOnIncompleteTests="true" - displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/phpunit/R4.xml b/phpunit/R4.xml index f850991a..d6a81381 100644 --- a/phpunit/R4.xml +++ b/phpunit/R4.xml @@ -5,7 +5,6 @@ colors="true" stopOnFailure="false" displayDetailsOnIncompleteTests="true" - displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/phpunit/R5.xml b/phpunit/R5.xml index 05e3b057..dd294fb3 100644 --- a/phpunit/R5.xml +++ b/phpunit/R5.xml @@ -5,7 +5,6 @@ colors="true" stopOnFailure="false" displayDetailsOnIncompleteTests="true" - displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/phpunit/STU3.xml b/phpunit/STU3.xml index a636dea4..27ce8260 100644 --- a/phpunit/STU3.xml +++ b/phpunit/STU3.xml @@ -5,7 +5,6 @@ colors="true" stopOnFailure="false" displayDetailsOnIncompleteTests="true" - displayDetailsOnSkippedTests="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" diff --git a/template/core/classes/class_factory_config.php b/template/core/classes/class_factory_config.php index 927c6946..4ed05bab 100644 --- a/template/core/classes/class_factory_config.php +++ b/template/core/classes/class_factory_config.php @@ -118,5 +118,15 @@ public function setVersions(array $versions): self } return $this; } + + /** + * Return iterator containing all registered versions. + * + * @return getFullyQualifiedName(true, PHPFHIR_INTERFACE_VERSION_CONFIG); ?>[] + */ + public function getVersionsIterator(): \Iterator + { + return new \ArrayIterator($this->_versions); + } } getFullyQualifiedTestsName(TestTypeEnum::BASE, false)};\n\n"; - -echo $config->getBasePHPFHIRCopyrightComment(false); - -echo "\n\n"; -echo "use PHPUnit\\Framework\\TestCase;\n"; -echo "use {$config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_FACTORY_CONFIG)};\n"; -echo "use {$config->getFullyQualifiedName(false, PHPFHIR_ENUM_FACTORY_CONFIG_KEY)};\n"; -echo "use {$config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CONSTANTS)};\n"; - -?> - -class extends TestCase -{ - public function testConfigDefaults(): void - { - $config = new (); - $this->assertFalse($config->getRegisterAutoloader()); - $this->assertEquals(::DEFAULT_LIBXML_OPTS, $config->getLibxmlOpts()); - $this->assertNull($config->getRootXMLNS()); - $this->assertFalse($config->getOverrideSourceXMLNS()); - } - - public function testConfigWithkeys(): void - { - $data = [ - ::REGISTER_AUTOLOADER->value => true, - ::LIBXML_OPTS->value => 12345, - ::ROOT_XMLNS->value => 'xmlns://example.org', - ::OVERRIDE_SOURCE_XMLNS->value => true, - ]; - $config = new ($data); - foreach($data as $k => $v) { - $this->assertEquals($v, $config->{"get{$k}"}()); - } - } -} - + +namespace getFullyQualifiedTestsName(TestTypeEnum::BASE, false); ?>; + +getBasePHPFHIRCopyrightComment(false); ?> + + +use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CONSTANTS); ?>; +use getFullyQualifiedName(false, PHPFHIR_CLASSNAME_FACTORY_CONFIG); ?>; +use getFullyQualifiedName(false, PHPFHIR_ENUM_FACTORY_CONFIG_KEY); ?>; +use PHPUnit\Framework\TestCase; + +class extends TestCase +{ + public function testFactoryConfigEmpty(): void + { + $config = new (); + $this->assertCount(0, $config->getVersionsIterator()); + } + + public function testFactoryConfigVersionArrayMissingName(): void + { + $this->expectException(\InvalidArgumentException::class); + $config = new ([ + 'versions' => [ + 'class' => 'some class', + ] + ]); + } + + public function testFactoryConfigVersionArrayMissingClass(): void + { + $this->expectException(\InvalidArgumentException::class); + $config = new ([ + 'versions' => [ + 'name' => 'FHIRTEST', + ] + ]); + } + + public function testFactoryConfigVersionArrayInvalidClass(): void + { + $this->expectException(\InvalidArgumentException::class); + $config = new ([ + 'versions' => [ + 'name' => 'FHIRTEST', + 'class' => \stdClass::class, + ] + ]); + } +} +