Skip to content

Commit 90fd2e6

Browse files
committed
tests still need some work.
1 parent 6b9fa90 commit 90fd2e6

File tree

6 files changed

+66
-30
lines changed

6 files changed

+66
-30
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
1-
# These are supported funding model platforms
2-
31
github: dcarbone
4-
patreon: # Replace with a single Patreon username
5-
open_collective: # Replace with a single Open Collective username
6-
ko_fi: dcarbone
7-
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9-
liberapay: # Replace with a single Liberapay username
10-
issuehunt: # Replace with a single IssueHunt username
11-
otechie: # Replace with a single Otechie username
12-
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
13-
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
2+
ko_fi: dcarbone

files/constants.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@
155155
const PHPFHIR_TEST_CLASSNAME_TYPE_MAP = PHPFHIR_CLASSNAME_VERSION_TYPE_MAP . 'Test';
156156
const PHPFHIR_TEST_CLASSNAME_FACTORY_CONFIG = PHPFHIR_CLASSNAME_FACTORY_CONFIG . 'Test';
157157

158+
// Test constant names
159+
const PHPFHIR_TEST_CONSTANT_INTEGRATION_ENDPOINT = 'PHPFHIR_TEST_INTEGRATION_ENDPOINT';
160+
const PHPFHIR_TEST_CONSTANT_RESOURCE_DOWNLOAD_DIR = 'PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR';
161+
158162
// Date & time formats
159163
const PHPFHIR_DATE_FORMAT_YEAR = 'Y';
160164
const PHPFHIR_DATE_FORMAT_YEAR_MONTH = 'Y-m';

phpunit/bootstrap.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,34 @@
1818
* limitations under the License.
1919
*/
2020

21-
const COMPOSER_AUTOLOADER_PATH = __DIR__ . '/../vendor/autoload.php';
22-
const GENERATED_AUTOLOADER_PATH = __DIR__ . '/../output/DCarbone/PHPFHIRGenerated/Autoloader.php';
21+
const PHPFHIR_TEST_CONFIG_ROOT_DIR = __DIR__;
22+
const PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR = PHPFHIR_TEST_CONFIG_ROOT_DIR . '/../output/tests/resources';
2323

24-
$composerAutoloader = realpath(COMPOSER_AUTOLOADER_PATH);
25-
$generatedAutoloader = realpath(GENERATED_AUTOLOADER_PATH);
24+
echo 'Creating test resource download dir: ' . PHPFHIR_TEST_CONFIG_ROOT_DIR . '/../output/tests/resources' . PHP_EOL;
25+
26+
if (!mkdir(PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR, 0755, true)) {
27+
throw new \RuntimeException(sprintf('Failed to create test resource download directory: %s', PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR));
28+
}
29+
30+
# define env to be used in tests
31+
putenv('PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR='.PHPFHIR_TEST_RESOURCE_DOWNLOAD_DIR);
32+
33+
const PHPFHIR_TEST_COMPOSER_AUTOLOADER_PATH = __DIR__ . '/../vendor/autoload.php';
34+
const PHPFHIR_TETS_GENERATED_AUTOLOADER_PATH = __DIR__ . '/../output/DCarbone/PHPFHIRGenerated/Autoloader.php';
35+
36+
$composerAutoloader = realpath(PHPFHIR_TEST_COMPOSER_AUTOLOADER_PATH);
37+
$generatedAutoloader = realpath(PHPFHIR_TETS_GENERATED_AUTOLOADER_PATH);
2638

2739
if (!$composerAutoloader) {
28-
throw new \RuntimeException(sprintf('Copmoser autoloader class file not found at expected path: %s', COMPOSER_AUTOLOADER_PATH));
40+
throw new \RuntimeException(sprintf('Copmoser autoloader class file not found at expected path: %s', PHPFHIR_TEST_COMPOSER_AUTOLOADER_PATH));
2941
}
3042
if (!$generatedAutoloader) {
31-
throw new \RuntimeException(sprintf('Generated autoloader class file not found at expected path: %s', GENERATED_AUTOLOADER_PATH));
43+
throw new \RuntimeException(sprintf('Generated autoloader class file not found at expected path: %s', PHPFHIR_TETS_GENERATED_AUTOLOADER_PATH));
3244
}
3345

3446
echo "Requiring composer autoloader: {$composerAutoloader}\n";
3547
require $composerAutoloader;
3648
echo "Requiring generated autoloader: {$generatedAutoloader}\n";
3749
require $generatedAutoloader;
50+
51+
unset($composerAutoloader, $generatedAutoloader);

src/Version/Definition/Decorator/ChoiceElementElementPropertyDecorator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public static function decorate(
4545
Types $types,
4646
Type $type,
4747
\SimpleXMLElement $element,
48-
?string $minOccurs,
49-
?string $maxOccurs,
50-
\SimpleXMLElement $annotationElement = null
48+
null|string $minOccurs,
49+
null|string $maxOccurs,
50+
null|\SimpleXMLElement $annotationElement = null
5151
): void {
5252
$property = new Property($type, $element, $type->getSourceFilename());
5353

src/Version/Definition/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function __construct(
114114
Config $config,
115115
Version $version,
116116
string $fhirName,
117-
SimpleXMLElement $sourceSXE = null,
117+
null|SimpleXMLElement $sourceSXE = null,
118118
string $sourceFilename = ''
119119
) {
120120
if ('' === ($fhirName = trim($fhirName))) {

template/versions/types/tests/integration/class.php

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@
6767
?>
6868

6969

70-
use <?php echo $bundleType->getFullyQualifiedClassName(false); ?>;
71-
use <?php echo $type->getFullyQualifiedClassName(false); ?>;
7270
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_API_CLIENT); ?>;
71+
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_API_CLIENT_CONFIG); ?>;
7372
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_ENUM_API_FORMAT); ?>;
73+
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_RESPONSE_PARSER); ?>;
74+
use <?php echo $bundleType->getFullyQualifiedClassName(false); ?>;
75+
use <?php echo $type->getFullyQualifiedClassName(false); ?>;
7476
use <?php echo $version->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_VERSION_API_CLIENT); ?>;
7577
use <?php echo $version->getFullyQualifiedName(false, PHPFHIR_ENUM_VERSION_TYPE); ?>;
76-
use <?php echo $config->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_RESPONSE_PARSER); ?>;
7778
use <?php echo $version->getFullyQualifiedName(false, PHPFHIR_CLASSNAME_VERSION); ?>;
7879
use PHPUnit\Framework\AssertionFailedError;
7980
use PHPUnit\Framework\TestCase;
@@ -92,6 +93,9 @@ class <?php echo $testClassname; ?> extends TestCase
9293
/** @var <?php echo $version->getFullyQualifiedName(true, PHPFHIR_CLASSNAME_VERSION); ?> */
9394
private <?php echo PHPFHIR_CLASSNAME_VERSION; ?> $_version;
9495

96+
/** @var <?php echo $config->getFullyQualifiedName(true, PHPFHIR_CLASSNAME_API_CLIENT_CONFIG); ?> */
97+
private <?php echo PHPFHIR_CLASSNAME_API_CLIENT_CONFIG; ?> $_clientConfig;
98+
9599
/** @var <?php echo $config->getFullyQualifiedName(true, PHPFHIR_CLASSNAME_API_CLIENT); ?> */
96100
private <?php echo PHPFHIR_CLASSNAME_API_CLIENT; ?> $_baseClient;
97101

@@ -103,13 +107,14 @@ class <?php echo $testClassname; ?> extends TestCase
103107

104108
protected function setUp(): void
105109
{
106-
$endpoint = trim((string)getenv('PHPFHIR_TEST_INTEGRATION_ENDPOINT'));
110+
$endpoint = trim((string)getenv('<?php echo PHPFHIR_TEST_CONSTANT_INTEGRATION_ENDPOINT; ?>'));
107111
if ('' === $endpoint) {
108-
$this->markTestIncomplete('Environment variable PHPFHIR_TEST_INTEGRATION_ENDPOINT is not defined or empty');
112+
$this->markTestIncomplete('Environment variable <?php echo PHPFHIR_TEST_CONSTANT_INTEGRATION_ENDPOINT; ?> is not defined or empty');
109113
}
110114
$this->_testEndpoint = $endpoint;
111115
$this->_version = new <?php echo PHPFHIR_CLASSNAME_VERSION ?>();
112-
$this->_baseClient = new <?php echo PHPFHIR_CLASSNAME_API_CLIENT; ?>($endpoint);
116+
$this->_clientConfig = new <?php echo PHPFHIR_CLASSNAME_API_CLIENT_CONFIG ?>(address: $endpoint);
117+
$this->_baseClient = new <?php echo PHPFHIR_CLASSNAME_API_CLIENT; ?>($this->_clientConfig);
113118
$this->_client = new <?php echo PHPFHIR_CLASSNAME_VERSION_API_CLIENT ?>(
114119
$this->_baseClient,
115120
$this->_version,
@@ -119,6 +124,7 @@ protected function setUp(): void
119124
/**
120125
* @param string $format Either xml or json
121126
* @return string
127+
* @throws \Exception
122128
*/
123129
protected function fetchResourceBundle(string $format): string
124130
{
@@ -140,8 +146,13 @@ protected function fetchResourceBundle(string $format): string
140146
}
141147
$this->assertIsString($rc->resp);
142148
$this->_fetchedResources[$format] = $rc->resp;
143-
// $fname = sprintf('%s%s<?php echo $type->getFHIRName(); ?>-<?php echo $version->getSourceMetadata()->getFHIRVersion(false); ?>-source.%s', PHPFHIR_OUTPUT_TMP_DIR, DIRECTORY_SEPARATOR, $format);
144-
// file_put_contents($fname, $rc->resp);
149+
$dlDir = trim((string)getenv('<?php echo PHPFHIR_TEST_CONSTANT_RESOURCE_DOWNLOAD_DIR; ?>'));
150+
if ('' !== $dlDir) {
151+
$this->assertDirectoryExists($dlDir, sprintf('Configured test resource download directory "%s" does not exist.', $dlDir));
152+
$fname = sprintf('%s%s<?php echo $type->getFHIRName(); ?>-<?php echo $version->getSourceMetadata()->getFHIRVersion(false); ?>-source.%s', $dlDir, DIRECTORY_SEPARATOR, $format);
153+
file_put_contents($fname, $rc->resp);
154+
$this->assertFileExists($fname, sprintf('Failed to write fetched resource bundle to "%s"', $fname));
155+
}
145156
return $rc->resp;
146157
}
147158

@@ -164,6 +175,9 @@ function_exists('json_last_error_msg') ? json_last_error_msg() : ('Code: '.json_
164175
return $decoded;
165176
}
166177

178+
/**
179+
* @throws \Exception
180+
*/
167181
public function testXML(): void
168182
{
169183
$sourceXML = $this->fetchResourceBundle('xml');
@@ -222,6 +236,9 @@ public function testXML(): void
222236
}
223237
}
224238

239+
/**
240+
* @throws \Exception
241+
*/
225242
public function testJSON(): void
226243
{
227244
$sourceJSON = $this->fetchResourceBundle('json');
@@ -270,6 +287,9 @@ public function testJSON(): void
270287
}
271288
}
272289

290+
/**
291+
* @throws \Exception
292+
*/
273293
public function testValidationXML(): void
274294
{
275295
$sourceXML = $this->fetchResourceBundle('xml');
@@ -307,6 +327,9 @@ public function testValidationXML(): void
307327
}
308328
}
309329

330+
/**
331+
* @throws \Exception
332+
*/
310333
public function testValidationJSON(): void
311334
{
312335
$sourceJSON = $this->fetchResourceBundle('json');
@@ -345,6 +368,9 @@ public function testValidationJSON(): void
345368
}
346369
}
347370

371+
/**
372+
* @throws \Exception
373+
*/
348374
public function testResponseParserXML(): void
349375
{
350376
$sourceXML = $this->fetchResourceBundle('xml');
@@ -403,6 +429,9 @@ public function testResponseParserXML(): void
403429
}
404430
}
405431

432+
/**
433+
* @throws \Exception
434+
*/
406435
public function testResponseParserJSON(): void
407436
{
408437
$sourceJSON = $this->fetchResourceBundle('json');

0 commit comments

Comments
 (0)