Skip to content

Commit f9e311a

Browse files
Merge pull request #96 from marmichalski/fixes
Update PHP to 7.2, fix tests & undefined index access, add gh actions
2 parents caa98f6 + 3ac5662 commit f9e311a

File tree

10 files changed

+75
-37
lines changed

10 files changed

+75
-37
lines changed

.github/workflows/tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
php-version:
10+
- '7.2'
11+
- '7.3'
12+
- '7.4'
13+
- '8.0'
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: "Setup PHP"
21+
uses: "shivammathur/setup-php@v2"
22+
with:
23+
php-version: "${{ matrix.php-version }}"
24+
25+
- name: Get composer cache directory
26+
id: composer-cache
27+
run: |
28+
echo "::set-output name=dir::$(composer config cache-files-dir)"
29+
- uses: actions/cache@v2
30+
with:
31+
path: ${{ steps.composer-cache.outputs.dir }}
32+
key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-${{ matrix.php-version }}-composer-
35+
36+
- name: Install dependencies
37+
run: composer install
38+
39+
- name: Run tests
40+
run: composer tests

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ vendor/
1313
# Mac OS
1414
.DS_Store
1515
examples/extract_folder
16+
17+
# PHPUnit
18+
.phpunit.result.cache

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The class can also extract the whole files contained in the APK file to a given
77

88
### Requirements
99

10-
PHP 7.0+
10+
PHP 7.2+
1111

1212
### Installation
1313

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">=7.0",
21+
"php": ">=7.2",
2222
"ext-simplexml": "*",
2323
"ext-json": "*",
2424
"ext-libxml": "*",
2525
"ext-mbstring": "*"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^7.4"
28+
"phpunit/phpunit": "^8.5"
2929
},
3030
"repositories": [
3131
{
@@ -38,5 +38,8 @@
3838
"ApkParser": "lib"
3939
}
4040
},
41+
"scripts": {
42+
"tests": "@php phpunit --configuration=phpunit.xml"
43+
},
4144
"minimum-stability": "dev"
42-
}
45+
}

lib/ApkParser/Config.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ class Config
2727
/**
2828
* @param array $config
2929
*/
30-
public function __construct(array $config = array())
30+
public function __construct(array $config = [])
3131
{
32-
$this->config = array_merge(array(
32+
$this->config = array_merge([
3333
'tmp_path' => sys_get_temp_dir(),
3434
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
3535
'manifest_only' => true
36-
), $config);
36+
], $config);
3737
}
3838

3939
/**

lib/ApkParser/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Parser
2525
* @param array $config
2626
* @throws \Exception
2727
*/
28-
public function __construct($apkFile, array $config = array())
28+
public function __construct($apkFile, array $config = [])
2929
{
3030
$this->config = new Config($config);
3131
$this->apk = new Archive($apkFile);
@@ -70,7 +70,7 @@ public function getResources($key)
7070
{
7171
return is_null($this->resources) ? false : $this->resources->getResources($key);
7272
}
73-
73+
7474
/**
7575
Get all resources as an array
7676
*/

lib/ApkParser/ResourcesParser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ public function __construct(SeekableStream $stream)
5151
*/
5252
public function getResources($key)
5353
{
54-
return $this->resources[strtolower($key)];
54+
$key = strtolower($key);
55+
if (array_key_exists($key, $this->resources)) {
56+
return $this->resources[$key];
57+
}
58+
59+
return false;
5560
}
56-
61+
5762
/**
5863
All resources
5964
*/

test/ParserTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class ParserTest extends \PHPUnit\Framework\TestCase
2020
/**
2121
* @throws Exception
2222
*/
23-
public function setUp()
23+
protected function setUp(): void
2424
{
2525
$file = __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'EBHS.apk';
26-
$this->subject = new Parser($file);
26+
$this->subject = new Parser($file, ['manifest_only' => false]);
2727
}
2828

2929
/**
@@ -44,7 +44,7 @@ public function testPermissions()
4444
{
4545
$permissions = $this->subject->getManifest()->getPermissions();
4646

47-
$this->assertEquals(count($permissions), 4);
47+
$this->assertCount(4, $permissions);
4848
$this->assertArrayHasKey('INTERNET', $permissions, "INTERNET permission not found!");
4949
$this->assertArrayHasKey('CAMERA', $permissions, "CAMERA permission not found!");
5050
$this->assertArrayHasKey('BLUETOOTH', $permissions, "BLUETOOTH permission not found!");
@@ -75,10 +75,15 @@ public function testIconResources()
7575
$application = $this->subject->getManifest()->getApplication();
7676
$resources = $this->subject->getResources($application->getIcon());
7777

78-
$expected = array('res/drawable-ldpi/ebhs.png', 'res/drawable-mdpi/ebhs.png', 'res/drawable-hdpi/ebhs.png');
78+
$expected = ['res/drawable-ldpi/ebhs.png', 'res/drawable-mdpi/ebhs.png', 'res/drawable-hdpi/ebhs.png'];
7979
$this->assertEquals($resources, $expected);
8080
}
8181

82+
public function testGetMissingResources()
83+
{
84+
$this->assertFalse($this->subject->getResources('missing'));
85+
}
86+
8287
/**
8388
* @throws \PHPUnit\Framework\ExpectationFailedException
8489
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
@@ -90,7 +95,7 @@ public function testIconStream()
9095
$file = __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'ebhs.png';
9196
$expected = file_get_contents($file);
9297

93-
$this->assertTrue(is_resource($stream));
98+
$this->assertIsResource($stream);
9499
$this->assertEquals(base64_encode($icon), base64_encode($expected));
95100
}
96101

@@ -104,7 +109,7 @@ public function testLabelResources()
104109
$application = $this->subject->getManifest()->getApplication();
105110
$resources = $this->subject->getResources($application->getLabel());
106111

107-
$expected = array('EBHS');
112+
$expected = ['EBHS'];
108113
$this->assertEquals($resources, $expected);
109114
}
110115
}

test/XmlParserTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
*/
66
class XmlParserTest extends \PHPUnit\Framework\TestCase
77
{
8-
/**
9-
* @expectedException ApkParser\Exceptions\XmlParserException
10-
*/
118
public function testXmlObject()
129
{
1310
$mock = $this->getMockBuilder('ApkParser\XmlParser')
@@ -18,6 +15,8 @@ public function testXmlObject()
1815
$file = __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'invalid.xml';
1916
$mock->expects($this->once())->method('getXmlString')->will($this->returnValue(file_get_contents($file)));
2017

18+
$this->expectException(\ApkParser\Exceptions\XmlParserException::class);
19+
2120
$mock->getXmlObject();
2221
}
2322
}

0 commit comments

Comments
 (0)