Skip to content

Commit

Permalink
working on core tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Dec 26, 2024
1 parent 53c965f commit 5308eb3
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 80 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -68,7 +68,8 @@ jobs:
- '8.2'
- '8.3'
- '8.4'
fhir-version:
test-target:
- 'Core'
- 'DSTU1'
- 'DSTU2'
- 'STU3'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
1 change: 0 additions & 1 deletion phpunit/Core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
stopOnFailure="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
Expand Down
1 change: 0 additions & 1 deletion phpunit/DSTU1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
stopOnFailure="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
Expand Down
1 change: 0 additions & 1 deletion phpunit/DSTU2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
stopOnFailure="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
Expand Down
1 change: 0 additions & 1 deletion phpunit/R4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
stopOnFailure="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
Expand Down
1 change: 0 additions & 1 deletion phpunit/R5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
stopOnFailure="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
Expand Down
1 change: 0 additions & 1 deletion phpunit/STU3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
colors="true"
stopOnFailure="false"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerErrors="true"
Expand Down
10 changes: 10 additions & 0 deletions template/core/classes/class_factory_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,15 @@ public function setVersions(array $versions): self
}
return $this;
}

/**
* Return iterator containing all registered versions.
*
* @return <?php echo $config->getFullyQualifiedName(true, PHPFHIR_INTERFACE_VERSION_CONFIG); ?>[]
*/
public function getVersionsIterator(): \Iterator
{
return new \ArrayIterator($this->_versions);
}
}
<?php return ob_get_clean();
65 changes: 0 additions & 65 deletions template/core/tests/test_class_config.php

This file was deleted.

77 changes: 77 additions & 0 deletions template/core/tests/test_class_factory_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php declare(strict_types=1);

/*
* Copyright 2024 Daniel Carbone ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

use DCarbone\PHPFHIR\Enum\TestTypeEnum;

/** @var \DCarbone\PHPFHIR\Config $config */

ob_start();

echo '<?php'; ?>

namespace <?php echo $config->getFullyQualifiedTestsName(TestTypeEnum::BASE, false); ?>;

<?php echo $config->getBasePHPFHIRCopyrightComment(false); ?>


use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_CONSTANTS); ?>;
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_FACTORY_CONFIG); ?>;
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_ENUM_FACTORY_CONFIG_KEY); ?>;
use PHPUnit\Framework\TestCase;

class <?php echo PHPFHIR_TEST_CLASSNAME_FACTORY_CONFIG; ?> extends TestCase
{
public function testFactoryConfigEmpty(): void
{
$config = new <?php echo PHPFHIR_CLASSNAME_FACTORY_CONFIG; ?>();
$this->assertCount(0, $config->getVersionsIterator());
}

public function testFactoryConfigVersionArrayMissingName(): void
{
$this->expectException(\InvalidArgumentException::class);
$config = new <?php echo PHPFHIR_CLASSNAME_FACTORY_CONFIG; ?>([
'versions' => [
'class' => 'some class',
]
]);
}

public function testFactoryConfigVersionArrayMissingClass(): void
{
$this->expectException(\InvalidArgumentException::class);
$config = new <?php echo PHPFHIR_CLASSNAME_FACTORY_CONFIG; ?>([
'versions' => [
'name' => 'FHIRTEST',
]
]);
}

public function testFactoryConfigVersionArrayInvalidClass(): void
{
$this->expectException(\InvalidArgumentException::class);
$config = new <?php echo PHPFHIR_CLASSNAME_FACTORY_CONFIG; ?>([
'versions' => [
'name' => 'FHIRTEST',
'class' => \stdClass::class,
]
]);
}
}
<?php
return ob_get_clean();

0 comments on commit 5308eb3

Please sign in to comment.