Skip to content

Commit fd4a5a7

Browse files
authored
Merge pull request #669 from andrey-helldar/patch-2020-01-13-10-27
Added support for the latest packages
2 parents 6fc4837 + 309f338 commit fd4a5a7

14 files changed

+98
-52
lines changed

.travis.yml

+29-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
1+
dist: bionic
12
language: php
23

3-
php:
4-
- 7.3
5-
- 7.2
6-
74
env:
8-
- PREFER_LOWEST=""
9-
- PREFER_LOWEST="--prefer-lowest"
5+
global:
6+
- SETUP=stable
107

11-
jobs:
8+
matrix:
9+
fast_finish: true
1210
include:
13-
- script: composer lint
11+
- php: 7.2
12+
- php: 7.2
13+
env: SETUP=lowest
14+
- php: 7.3
15+
- php: 7.3
16+
env: SETUP=lowest
17+
- php: 7.4
18+
- php: 7.4
19+
env: SETUP=lowest
20+
- php: 7.4
21+
env: SETUP=lint
1422
name: "Lint code"
15-
php: 7.3
16-
env: PREFER_LOWEST=""
1723

18-
script: composer test-ci
19-
before_script:
24+
cache:
25+
directories:
26+
- $HOME/.composer/cache
27+
28+
before_install:
2029
- travis_retry composer self-update
21-
- travis_retry composer update --no-interaction --prefer-dist $PREFER_LOWEST
30+
31+
install:
32+
- if [[ $SETUP = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi
33+
- if [[ $SETUP = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi
34+
- if [[ $SETUP = 'lint' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; travis_retry composer lint; fi
35+
36+
script:
37+
- vendor/bin/phpunit

composer.json

+16-10
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,26 @@
1616
],
1717
"require": {
1818
"php": ">=7.2.0",
19+
"ext-json": "*",
1920
"fzaninotto/faker": "^1.8",
20-
"illuminate/routing": "^5.7|^6.0",
21-
"illuminate/support": "^5.7|^6.0",
22-
"illuminate/console": "^5.7|^6.0",
21+
"illuminate/console": "^5.7|^6.0|^7.0",
22+
"illuminate/routing": "^5.7|^6.0|^7.0",
23+
"illuminate/support": "^5.7|^6.0|^7.0",
24+
"league/flysystem": "^1.0",
2325
"mpociot/documentarian": "^0.3.0",
2426
"mpociot/reflection-docblock": "^1.0.1",
27+
"nunomaduro/collision": "^3.0",
2528
"ramsey/uuid": "^3.8",
26-
"symfony/var-exporter": "^4.0",
27-
"league/flysystem": "^1.0",
28-
"nunomaduro/collision": "^3.0"
29+
"symfony/var-exporter": "^4.0|^5.0"
2930
},
3031
"require-dev": {
31-
"orchestra/testbench": "^3.7.0 || ^4.0",
32-
"phpunit/phpunit": "^7.5.0",
3332
"dingo/api": "^2.3.0",
34-
"mockery/mockery": "^1.2.0",
33+
"dms/phpunit-arraysubset-asserts": "^0.1.0",
3534
"league/fractal": "^0.17.0",
36-
"phpstan/phpstan": "^0.11.15"
35+
"mockery/mockery": "^1.2.0",
36+
"orchestra/testbench": "^3.7|^4.0",
37+
"phpstan/phpstan": "^0.11.15",
38+
"phpunit/phpunit": "^8.0"
3739
},
3840
"suggest": {
3941
"league/fractal": "Required for transformers support"
@@ -62,5 +64,9 @@
6264
"branch-alias": {
6365
"dev-v4": "4.x-dev"
6466
}
67+
},
68+
"config": {
69+
"preferred-install": "dist",
70+
"sort-packages": true
6571
}
6672
}

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
parameters:
22
level: 5
33
reportUnmatchedIgnoredErrors: false
4-
inferPrivatePropertyTypeFromConstructor:: true
4+
inferPrivatePropertyTypeFromConstructor: true
55
ignoreErrors:
66
- '#Call to an undefined static method Illuminate\\Support\\Facades\\Route::getRoutes().#'
77
- '#Call to an undefined static method Illuminate\\Support\\Facades\\URL::forceRootUrl()#'

src/Commands/GenerateDocumentation.php

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ public function handle(RouteMatcherInterface $routeMatcher)
8686
* @param \Mpociot\ApiDoc\Extracting\Generator $generator
8787
* @param Match[] $routes
8888
*
89+
* @throws \ReflectionException
90+
*
8991
* @return array
9092
*/
9193
private function processRoutes(Generator $generator, array $routes)

src/Extracting/Generator.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ public function getMethods(Route $route)
4747
* @param \Illuminate\Routing\Route $route
4848
* @param array $routeRules Rules to apply when generating documentation for this route
4949
*
50+
* @throws \ReflectionException
51+
*
5052
* @return array
5153
*/
5254
public function processRoute(Route $route, array $routeRules = [])
5355
{
54-
list($controllerName, $methodName) = Utils::getRouteClassAndMethodNames($route->getAction());
56+
[$controllerName, $methodName] = Utils::getRouteClassAndMethodNames($route->getAction());
5557
$controller = new ReflectionClass($controllerName);
5658
$method = $controller->getMethod($methodName);
5759

src/Extracting/ParamHelpers.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Mpociot\ApiDoc\Extracting;
44

55
use Faker\Factory;
6+
use stdClass;
67

78
trait ParamHelpers
89
{
@@ -32,7 +33,7 @@ protected function generateDummyValue(string $type)
3233
return [];
3334
},
3435
'object' => function () {
35-
return new \stdClass;
36+
return new stdClass;
3637
},
3738
];
3839

src/Extracting/RouteDocBlocker.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class RouteDocBlocker
2020
* @param Route $route
2121
*
2222
* @throws \ReflectionException
23+
* @throws \Exception
2324
*
2425
* @return array<string, DocBlock> Method and class docblocks
2526
*/

src/Extracting/Strategies/Responses/UseTransformerTags.php

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Model as IlluminateModel;
78
use Illuminate\Routing\Route;
89
use Illuminate\Support\Arr;
910
use League\Fractal\Manager;
@@ -34,7 +35,7 @@ class UseTransformerTags extends Strategy
3435
*
3536
* @return array|null
3637
*/
37-
public function __invoke(Route $route, \ReflectionClass $controller, \ReflectionMethod $method, array $rulesToApply, array $context = [])
38+
public function __invoke(Route $route, ReflectionClass $controller, ReflectionMethod $method, array $rulesToApply, array $context = [])
3839
{
3940
$docBlocks = RouteDocBlocker::getDocBlocksFromRoute($route);
4041
/** @var DocBlock $methodDocBlock */
@@ -47,6 +48,7 @@ public function __invoke(Route $route, \ReflectionClass $controller, \Reflection
4748
* Get a response from the transformer tags.
4849
*
4950
* @param array $tags
51+
* @param Route $route
5052
*
5153
* @return array|null
5254
*/
@@ -57,7 +59,7 @@ protected function getTransformerResponse(array $tags, Route $route)
5759
return null;
5860
}
5961

60-
list($statusCode, $transformer) = $this->getStatusCodeAndTransformerClass($transformerTag);
62+
[$statusCode, $transformer] = $this->getStatusCodeAndTransformerClass($transformerTag);
6163
$model = $this->getClassToBeTransformed($tags, (new ReflectionClass($transformer))->getMethod('transform'));
6264
$modelInstance = $this->instantiateTransformerModel($model);
6365

@@ -81,7 +83,7 @@ protected function getTransformerResponse(array $tags, Route $route)
8183
'content' => $response->getContent(),
8284
],
8385
];
84-
} catch (\Exception $e) {
86+
} catch (Exception $e) {
8587
echo 'Exception thrown when fetching transformer response for ['.implode(',', $route->methods)."] {$route->uri}.\n";
8688
if (Flags::$shouldBeVerbose) {
8789
Utils::dumpException($e);
@@ -112,6 +114,8 @@ private function getStatusCodeAndTransformerClass($tag): array
112114
* @param array $tags
113115
* @param ReflectionMethod $transformerMethod
114116
*
117+
* @throws Exception
118+
*
115119
* @return string
116120
*/
117121
private function getClassToBeTransformed(array $tags, ReflectionMethod $transformerMethod): string
@@ -125,9 +129,9 @@ private function getClassToBeTransformed(array $tags, ReflectionMethod $transfor
125129
$type = $modelTag->getContent();
126130
} else {
127131
$parameter = Arr::first($transformerMethod->getParameters());
128-
if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists((string) $parameter->getType())) {
132+
if ($parameter->hasType() && ! $parameter->getType()->isBuiltin() && class_exists($parameter->getType()->getName())) {
129133
// Ladies and gentlemen, we have a type!
130-
$type = (string) $parameter->getType();
134+
$type = $parameter->getType()->getName();
131135
}
132136
}
133137

@@ -153,20 +157,20 @@ protected function instantiateTransformerModel(string $type)
153157
$type = ltrim($type, '\\');
154158

155159
return factory($type)->make();
156-
} catch (\Exception $e) {
160+
} catch (Exception $e) {
157161
if (Flags::$shouldBeVerbose) {
158162
echo "Eloquent model factory failed to instantiate {$type}; trying to fetch from database.\n";
159163
}
160164

161165
$instance = new $type;
162-
if ($instance instanceof \Illuminate\Database\Eloquent\Model) {
166+
if ($instance instanceof IlluminateModel) {
163167
try {
164168
// we can't use a factory but can try to get one from the database
165169
$firstInstance = $type::first();
166170
if ($firstInstance) {
167171
return $firstInstance;
168172
}
169-
} catch (\Exception $e) {
173+
} catch (Exception $e) {
170174
// okay, we'll stick with `new`
171175
if (Flags::$shouldBeVerbose) {
172176
echo "Failed to fetch first {$type} from database; using `new` to instantiate.\n";

src/Tools/Utils.php

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public static function deleteDirectoryAndContents($dir)
9494
$fs->deleteDir($dir);
9595
}
9696

97+
/**
98+
* @param mixed $value
99+
* @param int $indentationLevel
100+
*
101+
* @throws \Symfony\Component\VarExporter\Exception\ExceptionInterface
102+
*
103+
* @return string
104+
*/
97105
public static function printPhpValue($value, $indentationLevel = 0)
98106
{
99107
$output = VarExporter::export($value);

tests/GenerateDocumentationTest.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public function console_command_does_not_work_with_closure()
6565
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
6666
$output = $this->artisan('apidoc:generate');
6767

68-
$this->assertContains('Skipping route: [GET] api/closure', $output);
69-
$this->assertContains('Processed route: [GET] api/test', $output);
68+
$this->assertStringContainsString('Skipping route: [GET] api/closure', $output);
69+
$this->assertStringContainsString('Processed route: [GET] api/test', $output);
7070
}
7171

7272
/** @test */
@@ -85,8 +85,8 @@ public function console_command_does_not_work_with_closure_using_dingo()
8585
config(['apidoc.routes.0.match.versions' => ['v1']]);
8686
$output = $this->artisan('apidoc:generate');
8787

88-
$this->assertContains('Skipping route: [GET] closure', $output);
89-
$this->assertContains('Processed route: [GET] test', $output);
88+
$this->assertStringContainsString('Skipping route: [GET] closure', $output);
89+
$this->assertStringContainsString('Processed route: [GET] test', $output);
9090
}
9191

9292
/** @test */
@@ -97,8 +97,8 @@ public function console_command_work_with_routes_callable_tuple()
9797
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
9898
$output = $this->artisan('apidoc:generate');
9999

100-
$this->assertNotContains('Skipping route: [GET] api/array/test', $output);
101-
$this->assertContains('Processed route: [GET] api/array/test', $output);
100+
$this->assertStringNotContainsString('Skipping route: [GET] api/array/test', $output);
101+
$this->assertStringContainsString('Processed route: [GET] api/array/test', $output);
102102
}
103103

104104
/** @test */
@@ -110,8 +110,8 @@ public function can_skip_single_routes()
110110
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
111111
$output = $this->artisan('apidoc:generate');
112112

113-
$this->assertContains('Skipping route: [GET] api/skip', $output);
114-
$this->assertContains('Processed route: [GET] api/test', $output);
113+
$this->assertStringContainsString('Skipping route: [GET] api/skip', $output);
114+
$this->assertStringContainsString('Processed route: [GET] api/test', $output);
115115
}
116116

117117
/** @test */
@@ -122,8 +122,8 @@ public function can_skip_non_existent_response_files()
122122
config(['apidoc.routes.0.match.prefixes' => ['api/*']]);
123123
$output = $this->artisan('apidoc:generate');
124124

125-
$this->assertContains('Skipping route: [GET] api/non-existent', $output);
126-
$this->assertContains('@responseFile i-do-not-exist.json does not exist', $output);
125+
$this->assertStringContainsString('Skipping route: [GET] api/non-existent', $output);
126+
$this->assertStringContainsString('@responseFile i-do-not-exist.json does not exist', $output);
127127
}
128128

129129
/** @test */
@@ -392,7 +392,7 @@ public function can_parse_utf8_response()
392392
$this->artisan('apidoc:generate');
393393

394394
$generatedMarkdown = file_get_contents(__DIR__.'/../resources/docs/source/index.md');
395-
$this->assertContains('Лорем ипсум долор сит амет', $generatedMarkdown);
395+
$this->assertStringContainsString('Лорем ипсум долор сит амет', $generatedMarkdown);
396396
}
397397

398398
/** @test */
@@ -437,7 +437,7 @@ public function supports_partial_resource_controller()
437437

438438
$this->assertNull($thrownException);
439439
$generatedMarkdown = file_get_contents(__DIR__.'/../resources/docs/source/index.md');
440-
$this->assertContains('Group A', $generatedMarkdown);
441-
$this->assertContains('Group B', $generatedMarkdown);
440+
$this->assertStringContainsString('Group A', $generatedMarkdown);
441+
$this->assertStringContainsString('Group B', $generatedMarkdown);
442442
}
443443
}

tests/TestHelpers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,6 @@ private function assertContainsIgnoringWhitespace($needle, $haystack)
4848
{
4949
$haystack = preg_replace('/\s/', '', $haystack);
5050
$needle = preg_replace('/\s/', '', $needle);
51-
$this->assertContains($needle, $haystack);
51+
$this->assertStringContainsString($needle, $haystack);
5252
}
5353
}

tests/Unit/GeneratorPluginSystemTestCase.php

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Mpociot\ApiDoc\Tests\Unit;
44

5+
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
56
use Illuminate\Routing\Route;
67
use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider;
78
use Mpociot\ApiDoc\Extracting\Generator;
@@ -13,6 +14,8 @@
1314

1415
class GeneratorPluginSystemTestCase extends LaravelGeneratorTest
1516
{
17+
use ArraySubsetAsserts;
18+
1619
/**
1720
* @var \Mpociot\ApiDoc\Extracting\Generator
1821
*/

tests/Unit/GeneratorTestCase.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Mpociot\ApiDoc\Tests\Unit;
66

7+
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
78
use Illuminate\Support\Arr;
89
use Mpociot\ApiDoc\ApiDocGeneratorServiceProvider;
910
use Mpociot\ApiDoc\Extracting\Generator;
@@ -14,6 +15,8 @@
1415

1516
abstract class GeneratorTestCase extends TestCase
1617
{
18+
use ArraySubsetAsserts;
19+
1720
/**
1821
* @var \Mpociot\ApiDoc\Extracting\Generator
1922
*/

0 commit comments

Comments
 (0)