Skip to content

Commit 49c0f65

Browse files
committed
refactor: modify method name of ParseArray trait
1 parent c3373f1 commit 49c0f65

File tree

2 files changed

+100
-10
lines changed

2 files changed

+100
-10
lines changed

tests/ParserTest.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,31 @@
33
use Xdevor\ComposerParser\Parser;
44

55
test('It can return correct value if key exist', function () {
6-
$package = 'doctrine/instantiator';
7-
$illuminateSupportName = (new Parser())->parse($package, 'name');
8-
expect($illuminateSupportName)->toBe($package);
6+
$packageName = 'doctrine/instantiator';
7+
$actual = (new Parser())->parse($packageName, 'name');
8+
expect($actual)->toBe($packageName);
99
});
1010

11-
test('It return default if key not exist', function () {
12-
$package = 'ooo/xxx';
13-
$illuminateSupportName = (new Parser())->parse($package, 'name', null);
14-
expect($illuminateSupportName)->toBe(null);
11+
test('It return null if key not exist', function () {
12+
$packageName = 'ooo/xxx';
13+
$actual = (new Parser())->parse($packageName, 'name');
14+
expect($actual)->toBe(null);
15+
});
16+
17+
test('It return default value if key not exist', function () {
18+
$packageName = 'ooo/xxx';
19+
$actual = (new Parser())->parse($packageName, 'name', 'this_is_default');
20+
expect($actual)->toBe('this_is_default');
1521
});
1622

1723
test('It can return correct value if array key exist', function () {
18-
$package = 'doctrine/instantiator';
19-
$illuminateSupportName = (new Parser())->parse($package, 'license.0');
20-
expect($illuminateSupportName)->toBe('MIT');
24+
$packageName = 'doctrine/instantiator';
25+
$actual = (new Parser())->parse($packageName, 'license.0');
26+
expect($actual)->toBe('MIT');
27+
});
28+
29+
test('It can use custom installed.json path', function () {
30+
$packageName = 'filp/whoops';
31+
$actual = (new Parser(__DIR__ . '/../tests/assets/fakeInstalled.json'))->parse($packageName, 'extra.branch-alias.dev-master');
32+
expect($actual)->toBe('2.7-dev');
2133
});

tests/assets/fakeInstalled.json

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"packages": [
3+
{
4+
"name": "filp/whoops",
5+
"version": "2.15.1",
6+
"version_normalized": "2.15.1.0",
7+
"source": {
8+
"type": "git",
9+
"url": "https://github.com/filp/whoops.git",
10+
"reference": "e864ac957acd66e1565f25efda61e37791a5db0b"
11+
},
12+
"dist": {
13+
"type": "zip",
14+
"url": "https://api.github.com/repos/filp/whoops/zipball/e864ac957acd66e1565f25efda61e37791a5db0b",
15+
"reference": "e864ac957acd66e1565f25efda61e37791a5db0b",
16+
"shasum": ""
17+
},
18+
"require": {
19+
"php": "^5.5.9 || ^7.0 || ^8.0",
20+
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
21+
},
22+
"require-dev": {
23+
"mockery/mockery": "^0.9 || ^1.0",
24+
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.3",
25+
"symfony/var-dumper": "^2.6 || ^3.0 || ^4.0 || ^5.0"
26+
},
27+
"suggest": {
28+
"symfony/var-dumper": "Pretty print complex values better with var-dumper available",
29+
"whoops/soap": "Formats errors as SOAP responses"
30+
},
31+
"time": "2023-03-06T18:09:13+00:00",
32+
"type": "library",
33+
"extra": {
34+
"branch-alias": {
35+
"dev-master": "2.7-dev"
36+
}
37+
},
38+
"installation-source": "dist",
39+
"autoload": {
40+
"psr-4": {
41+
"Whoops\\": "src/Whoops/"
42+
}
43+
},
44+
"notification-url": "https://packagist.org/downloads/",
45+
"license": [
46+
"MIT"
47+
],
48+
"authors": [
49+
{
50+
"name": "Filipe Dobreira",
51+
"homepage": "https://github.com/filp",
52+
"role": "Developer"
53+
}
54+
],
55+
"description": "php error handling for cool kids",
56+
"homepage": "https://filp.github.io/whoops/",
57+
"keywords": [
58+
"error",
59+
"exception",
60+
"handling",
61+
"library",
62+
"throwable",
63+
"whoops"
64+
],
65+
"support": {
66+
"issues": "https://github.com/filp/whoops/issues",
67+
"source": "https://github.com/filp/whoops/tree/2.15.1"
68+
},
69+
"funding": [
70+
{
71+
"url": "https://github.com/denis-sokolov",
72+
"type": "github"
73+
}
74+
],
75+
"install-path": "../filp/whoops"
76+
}
77+
]
78+
}

0 commit comments

Comments
 (0)