Skip to content

Commit c6cca50

Browse files
committed
Fix issue #70
Check if composer require is setted and contains an array in differents Frameworks Presets Add tests on ConfigResolver::guess
1 parent a1a069a commit c6cca50

File tree

8 files changed

+257
-0
lines changed

8 files changed

+257
-0
lines changed

src/Application/Adapters/Laravel/Preset.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public static function get(): array
6464
*/
6565
public static function shouldBeApplied(array $composer): bool
6666
{
67+
if (empty($composer['require']) || ! is_array($composer['require'])) {
68+
return false;
69+
}
70+
6771
/** @var string[] $requirements */
6872
$requirements = $composer['require'];
6973

src/Application/Adapters/Symfony/Preset.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public static function get(): array
4848
*/
4949
public static function shouldBeApplied(array $composer): bool
5050
{
51+
if (empty($composer['require']) || ! is_array($composer['require'])) {
52+
return false;
53+
}
54+
5155
/** @var string[] $requirements */
5256
$requirements = $composer['require'];
5357

src/Application/Adapters/Yii/Preset.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public static function get(): array
4848
*/
4949
public static function shouldBeApplied(array $composer): bool
5050
{
51+
if (empty($composer['require']) || ! is_array($composer['require'])) {
52+
return false;
53+
}
54+
5155
/** @var string[] $requirements */
5256
$requirements = $composer['require'];
5357

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Application;
6+
7+
use NunoMaduro\PhpInsights\Application\ConfigResolver;
8+
use PHPUnit\Framework\TestCase;
9+
10+
final class ConfigResolverTest extends TestCase
11+
{
12+
private $baseFixturePath;
13+
14+
public function setUp(): void
15+
{
16+
parent::setUp();
17+
$this->baseFixturePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR . 'ConfigResolver' . DIRECTORY_SEPARATOR;
18+
}
19+
20+
public function testGuessDirectoryWithoutComposer(): void
21+
{
22+
$preset = ConfigResolver::guess($this->baseFixturePath);
23+
$this->assertSame('default', $preset);
24+
}
25+
26+
public function testGuessComposerWithoutRequire(): void
27+
{
28+
$preset = ConfigResolver::guess($this->baseFixturePath . 'ComposerWithoutRequire');
29+
$this->assertSame('default', $preset);
30+
}
31+
32+
public function testGuessSymfony(): void
33+
{
34+
$preset = ConfigResolver::guess($this->baseFixturePath . 'ComposerSymfony');
35+
$this->assertSame('symfony', $preset);
36+
}
37+
38+
public function testGuessLaravel(): void
39+
{
40+
$preset = ConfigResolver::guess($this->baseFixturePath . 'ComposerLaravel');
41+
$this->assertSame('laravel', $preset);
42+
}
43+
44+
public function testGuessYii(): void
45+
{
46+
$preset = ConfigResolver::guess($this->baseFixturePath . 'ComposerYii');
47+
$this->assertSame('yii', $preset);
48+
}
49+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"name": "laravel/laravel",
3+
"type": "project",
4+
"description": "The Laravel Framework.",
5+
"keywords": [
6+
"framework",
7+
"laravel"
8+
],
9+
"license": "MIT",
10+
"require": {
11+
"php": "^7.1.3",
12+
"fideloper/proxy": "^4.0",
13+
"laravel/framework": "5.8.*",
14+
"laravel/tinker": "^1.0"
15+
},
16+
"require-dev": {
17+
"beyondcode/laravel-dump-server": "^1.0",
18+
"filp/whoops": "^2.0",
19+
"fzaninotto/faker": "^1.4",
20+
"mockery/mockery": "^1.0",
21+
"nunomaduro/collision": "^3.0",
22+
"phpunit/phpunit": "^7.5"
23+
},
24+
"config": {
25+
"optimize-autoloader": true,
26+
"preferred-install": "dist",
27+
"sort-packages": true
28+
},
29+
"extra": {
30+
"laravel": {
31+
"dont-discover": []
32+
}
33+
},
34+
"autoload": {
35+
"psr-4": {
36+
"App\\": "app/"
37+
},
38+
"classmap": [
39+
"database/seeds",
40+
"database/factories"
41+
]
42+
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"Tests\\": "tests/"
46+
}
47+
},
48+
"minimum-stability": "dev",
49+
"prefer-stable": true,
50+
"scripts": {
51+
"post-autoload-dump": [
52+
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
53+
"@php artisan package:discover --ansi"
54+
],
55+
"post-root-package-install": [
56+
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
57+
],
58+
"post-create-project-cmd": [
59+
"@php artisan key:generate --ansi"
60+
]
61+
}
62+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"type": "project",
3+
"license": "proprietary",
4+
"require": {
5+
"php": "^7.1.3",
6+
"ext-ctype": "*",
7+
"ext-iconv": "*",
8+
"symfony/console": "4.2.*",
9+
"symfony/dotenv": "4.2.*",
10+
"symfony/flex": "^1.1",
11+
"symfony/framework-bundle": "4.2.*",
12+
"symfony/yaml": "4.2.*"
13+
},
14+
"config": {
15+
"preferred-install": {
16+
"*": "dist"
17+
},
18+
"sort-packages": true
19+
},
20+
"autoload": {
21+
"psr-4": {
22+
"App\\": "src/"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"App\\Tests\\": "tests/"
28+
}
29+
},
30+
"replace": {
31+
"paragonie/random_compat": "2.*",
32+
"symfony/polyfill-ctype": "*",
33+
"symfony/polyfill-iconv": "*",
34+
"symfony/polyfill-php71": "*",
35+
"symfony/polyfill-php70": "*",
36+
"symfony/polyfill-php56": "*"
37+
},
38+
"scripts": {
39+
"auto-scripts": {
40+
"cache:clear": "symfony-cmd",
41+
"assets:install %PUBLIC_DIR%": "symfony-cmd"
42+
},
43+
"post-install-cmd": [
44+
"@auto-scripts"
45+
],
46+
"post-update-cmd": [
47+
"@auto-scripts"
48+
]
49+
},
50+
"conflict": {
51+
"symfony/symfony": "*"
52+
},
53+
"extra": {
54+
"symfony": {
55+
"allow-contrib": false,
56+
"require": "4.2.*"
57+
}
58+
}
59+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "vendor/name",
3+
"description": "Test without require",
4+
"type": "project",
5+
"require-dev": {}
6+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"name": "yiisoft/yii2-app-basic",
3+
"description": "Yii 2 Basic Project Template",
4+
"keywords": ["yii2", "framework", "basic", "project template"],
5+
"homepage": "http://www.yiiframework.com/",
6+
"type": "project",
7+
"license": "BSD-3-Clause",
8+
"support": {
9+
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
10+
"forum": "http://www.yiiframework.com/forum/",
11+
"wiki": "http://www.yiiframework.com/wiki/",
12+
"irc": "irc://irc.freenode.net/yii",
13+
"source": "https://github.com/yiisoft/yii2"
14+
},
15+
"minimum-stability": "stable",
16+
"require": {
17+
"php": ">=5.4.0",
18+
"yiisoft/yii2": "~2.0.14",
19+
"yiisoft/yii2-bootstrap": "~2.0.0",
20+
"yiisoft/yii2-swiftmailer": "~2.0.0 || ~2.1.0"
21+
},
22+
"require-dev": {
23+
"yiisoft/yii2-debug": "~2.1.0",
24+
"yiisoft/yii2-gii": "~2.1.0",
25+
"yiisoft/yii2-faker": "~2.0.0",
26+
27+
"codeception/base": "~2.3.0",
28+
"codeception/verify": "~0.4.0",
29+
"codeception/specify": "~0.4.6",
30+
"symfony/browser-kit": ">=2.7 <=4.2.4"
31+
},
32+
"config": {
33+
"process-timeout": 1800,
34+
"fxp-asset": {
35+
"enabled": false
36+
}
37+
},
38+
"scripts": {
39+
"post-install-cmd": [
40+
"yii\\composer\\Installer::postInstall"
41+
],
42+
"post-create-project-cmd": [
43+
"yii\\composer\\Installer::postCreateProject",
44+
"yii\\composer\\Installer::postInstall"
45+
]
46+
},
47+
"extra": {
48+
"yii\\composer\\Installer::postCreateProject": {
49+
"setPermission": [
50+
{
51+
"runtime": "0777",
52+
"web/assets": "0777",
53+
"yii": "0755"
54+
}
55+
]
56+
},
57+
"yii\\composer\\Installer::postInstall": {
58+
"generateCookieValidationKey": [
59+
"config/web.php"
60+
]
61+
}
62+
},
63+
"repositories": [
64+
{
65+
"type": "composer",
66+
"url": "https://asset-packagist.org"
67+
}
68+
]
69+
}

0 commit comments

Comments
 (0)