1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
<?php
declare(strict_types = 1);
namespace Williamdes\MariaDBMySQLKBS\Test;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
use Swaggest\JsonSchema\Schema;
use stdClass;
class DataTest extends TestCase
{
/**
* Validate json data
*
* @param stdClass $contents The file contents
* @param string $id The schema path
* @example validate($slimData, __DIR__ . '/../schemas/merged-slim.json');
* @return bool
*/
public static function validate(stdClass $contents, string $id): bool
{
$schema = Schema::import($id);
$schema->in($contents);
return true;// No exception occurred
}
/**
* test that the vendor class can be found
* if not found the test is marked as skipped
* That will allow packagers to run tests without the vendor (Debian :wink:)
*
* @return void
*/
public function testVendorFound(): void
{
if (class_exists(Schema::class)) {
// tests that depend on the vendor can be run
$this->assertTrue(true);
} else {
$this->markTestSkipped('vnf');
}
}
/**
* test files
*
* @return void
*/
#[Depends('testVendorFound')]
public function testFileSample(): void
{
$slimDataTestData = (object) json_decode(
(string) file_get_contents(__DIR__ . '/data/ultraSlimDataTestWithVariables.json')
);
$this->assertTrue(
self::validate($slimDataTestData, __DIR__ . '/../schemas/merged-ultraslim.json')
);
}
/**
* test slim data
*
* @return void
*/
#[Depends('testVendorFound')]
public function testFileSlim(): void
{
$slimData = (object) json_decode((string) file_get_contents(__DIR__ . '/../dist/merged-slim.json'));
$this->assertTrue(self::validate($slimData, __DIR__ . '/../schemas/merged-slim.json'));
}
/**
* test ultra slim data
*
* @return void
*/
#[Depends('testVendorFound')]
public function testFileUltraSlim(): void
{
$slimData = (object) json_decode((string) file_get_contents(__DIR__ . '/../dist/merged-ultraslim.json'));
$this->assertTrue(self::validate($slimData, __DIR__ . '/../schemas/merged-ultraslim.json'));
}
/**
* test ultra slim data
*
* @return void
*/
#[Depends('testVendorFound')]
public function testFileRaw(): void
{
$slimData = (object) json_decode((string) file_get_contents(__DIR__ . '/../dist/merged-raw.json'));
$this->assertTrue(self::validate($slimData, __DIR__ . '/../schemas/merged-raw.json'));
}
}
|