Skip to content

Commit

Permalink
Merge pull request #96 from marmichalski/fixes
Browse files Browse the repository at this point in the history
Update PHP to 7.2, fix tests & undefined index access, add gh actions
  • Loading branch information
tufanbarisyildirim authored Aug 20, 2021
2 parents caa98f6 + 3ac5662 commit f9e311a
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 37 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: tests

on: [push, pull_request]

jobs:
build:
strategy:
matrix:
php-version:
- '7.2'
- '7.3'
- '7.4'
- '8.0'

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: "Setup PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"

- name: Get composer cache directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.php-version }}-composer-
- name: Install dependencies
run: composer install

- name: Run tests
run: composer tests
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ vendor/
# Mac OS
.DS_Store
examples/extract_folder

# PHPUnit
.phpunit.result.cache
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The class can also extract the whole files contained in the APK file to a given

### Requirements

PHP 7.0+
PHP 7.2+

### Installation

Expand Down
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.2",
"ext-simplexml": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.4"
"phpunit/phpunit": "^8.5"
},
"repositories": [
{
Expand All @@ -38,5 +38,8 @@
"ApkParser": "lib"
}
},
"scripts": {
"tests": "@php phpunit --configuration=phpunit.xml"
},
"minimum-stability": "dev"
}
}
6 changes: 3 additions & 3 deletions lib/ApkParser/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class Config
/**
* @param array $config
*/
public function __construct(array $config = array())
public function __construct(array $config = [])
{
$this->config = array_merge(array(
$this->config = array_merge([
'tmp_path' => sys_get_temp_dir(),
'jar_path' => __DIR__ . '/Dex/dedexer.jar',
'manifest_only' => true
), $config);
], $config);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/ApkParser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Parser
* @param array $config
* @throws \Exception
*/
public function __construct($apkFile, array $config = array())
public function __construct($apkFile, array $config = [])
{
$this->config = new Config($config);
$this->apk = new Archive($apkFile);
Expand Down Expand Up @@ -70,7 +70,7 @@ public function getResources($key)
{
return is_null($this->resources) ? false : $this->resources->getResources($key);
}

/**
Get all resources as an array
*/
Expand Down
9 changes: 7 additions & 2 deletions lib/ApkParser/ResourcesParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,14 @@ public function __construct(SeekableStream $stream)
*/
public function getResources($key)
{
return $this->resources[strtolower($key)];
$key = strtolower($key);
if (array_key_exists($key, $this->resources)) {
return $this->resources[$key];
}

return false;
}

/**
All resources
*/
Expand Down
17 changes: 11 additions & 6 deletions test/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class ParserTest extends \PHPUnit\Framework\TestCase
/**
* @throws Exception
*/
public function setUp()
protected function setUp(): void
{
$file = __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'EBHS.apk';
$this->subject = new Parser($file);
$this->subject = new Parser($file, ['manifest_only' => false]);
}

/**
Expand All @@ -44,7 +44,7 @@ public function testPermissions()
{
$permissions = $this->subject->getManifest()->getPermissions();

$this->assertEquals(count($permissions), 4);
$this->assertCount(4, $permissions);
$this->assertArrayHasKey('INTERNET', $permissions, "INTERNET permission not found!");
$this->assertArrayHasKey('CAMERA', $permissions, "CAMERA permission not found!");
$this->assertArrayHasKey('BLUETOOTH', $permissions, "BLUETOOTH permission not found!");
Expand Down Expand Up @@ -75,10 +75,15 @@ public function testIconResources()
$application = $this->subject->getManifest()->getApplication();
$resources = $this->subject->getResources($application->getIcon());

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

public function testGetMissingResources()
{
$this->assertFalse($this->subject->getResources('missing'));
}

/**
* @throws \PHPUnit\Framework\ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
Expand All @@ -90,7 +95,7 @@ public function testIconStream()
$file = __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'ebhs.png';
$expected = file_get_contents($file);

$this->assertTrue(is_resource($stream));
$this->assertIsResource($stream);
$this->assertEquals(base64_encode($icon), base64_encode($expected));
}

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

$expected = array('EBHS');
$expected = ['EBHS'];
$this->assertEquals($resources, $expected);
}
}
5 changes: 2 additions & 3 deletions test/XmlParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
*/
class XmlParserTest extends \PHPUnit\Framework\TestCase
{
/**
* @expectedException ApkParser\Exceptions\XmlParserException
*/
public function testXmlObject()
{
$mock = $this->getMockBuilder('ApkParser\XmlParser')
Expand All @@ -18,6 +15,8 @@ public function testXmlObject()
$file = __DIR__ . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'invalid.xml';
$mock->expects($this->once())->method('getXmlString')->will($this->returnValue(file_get_contents($file)));

$this->expectException(\ApkParser\Exceptions\XmlParserException::class);

$mock->getXmlObject();
}
}

0 comments on commit f9e311a

Please sign in to comment.