Skip to content
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
42 changes: 42 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests

on:
pull_request:
push:
branches:
- master
workflow_dispatch:

permissions:
contents: read

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']

name: PHP ${{ matrix.php }}

steps:
- name: Check out repository
uses: actions/checkout@v6

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: json, tokenizer, filter, mbstring
tools: composer:v2
coverage: none

- name: Validate Composer metadata
run: composer validate --strict

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

- name: Run tests
run: composer test
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

59 changes: 31 additions & 28 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
{
"name": "vanderlee/swaggergen",
"description": "Generate Swagger/OpenAPI documentation from simple PHPdoc-like comments in PHP source code.",
"type": "library",
"keywords": ["swagger", "openapi", "doc", "documentation", "rest", "api", "documentor", "comments", "generate", "generator"],
"homepage": "https://github.com/vanderlee/PHPSwaggerGen",
"license": "MIT",
"support": {
"issues": "https://github.com/vanderlee/PHPSwaggerGen/issues",
"source": "https://github.com/vanderlee/PHPSwaggerGen/"
},
"require": {
"php": ">=8.0",
"ext-json": "*",
"ext-tokenizer": "*",
"ext-filter": "*",
"ext-mbstring": "*"
},
"suggest": {
"ext-yaml": "Allows producing Swagger docs in Yaml format"
},
"autoload": {
"psr-4": {
"SwaggerGen\\": "SwaggerGen/"
}
},
"require-dev": {
"phpunit/phpunit": "10"
}
"name": "vanderlee/swaggergen",
"description": "Generate Swagger/OpenAPI documentation from simple PHPdoc-like comments in PHP source code.",
"type": "library",
"keywords": ["swagger", "openapi", "doc", "documentation", "rest", "api", "documentor", "comments", "generate", "generator"],
"homepage": "https://github.com/vanderlee/PHPSwaggerGen",
"license": "MIT",
"support": {
"issues": "https://github.com/vanderlee/PHPSwaggerGen/issues",
"source": "https://github.com/vanderlee/PHPSwaggerGen/"
},
"require": {
"php": ">=8.0",
"ext-json": "*",
"ext-tokenizer": "*",
"ext-filter": "*",
"ext-mbstring": "*"
},
"suggest": {
"ext-yaml": "Allows producing Swagger docs in YAML format"
},
"autoload": {
"psr-4": {
"SwaggerGen\\": "SwaggerGen/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^10.5 || ^11.5"
},
"scripts": {
"test": "phpunit"
}
}
22 changes: 10 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
colors="true"
processIsolation="false"
verbose="true"
debug="true">
<testsuites>
<testsuite name="SwaggerGen">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
colors="true"
processIsolation="false">
<testsuites>
<testsuite name="SwaggerGen">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
10 changes: 8 additions & 2 deletions tests/SwaggerGenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function testGetSwagger_JSON_Pretty()
response 202
'), array(), SwaggerGen::FORMAT_JSON_PRETTY);

$this->assertStringEqualsStringIgnoringLineEndings(<<<JSON
$expected = <<<JSON
{
"swagger": "2.0",
"info": {
Expand All @@ -111,7 +111,13 @@ public function testGetSwagger_JSON_Pretty()
}
}
}
JSON, $output);
JSON;

$normalizeLineEndings = static function ($value) {
return str_replace(array("\r\n", "\r"), "\n", $value);
};

$this->assertSame($normalizeLineEndings($expected), $normalizeLineEndings($output));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

if (!class_exists('SwaggerGen_TestCase', false)) {
class_alias('PHPUnit\\Framework\\TestCase', 'SwaggerGen_TestCase');
}

spl_autoload_register(function ($classname) {
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
if (is_file($file)) {
Expand Down
8 changes: 4 additions & 4 deletions tests/output/OutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function testAllCases($name, $files, $expected)
{
$SwaggerGen = new SwaggerGen('example.com', '/base');
$actual = $SwaggerGen->getSwagger($files, array(), SwaggerGen::FORMAT_JSON);
$this->assertJsonStringEqualsJsonString($expected, $this->normalizeJson($actual), $name);
$this->assertJsonStringEqualsJsonString($expected, self::normalizeJson($actual), $name);
}

/**
Expand All @@ -26,21 +26,21 @@ public function testAllCases($name, $files, $expected)
* @param string $json
* @return string
*/
private function normalizeJson($json)
private static function normalizeJson($json)
{
return json_encode(
json_decode($json),
PHP_VERSION_ID >= 50400 ? constant('JSON_PRETTY_PRINT') : 0
);
}

public function provideAllCases()
public static function provideAllCases()
{
$cases = array();

foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {
$path = realpath($dir);
$json = $this->normalizeJson(file_get_contents($path . '/expected.json'));
$json = self::normalizeJson(file_get_contents($path . '/expected.json'));

$files = array();
if (file_exists($path . '/source.php')) {
Expand Down