Skip to content
This repository was archived by the owner on Mar 15, 2020. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: humbug/phar-updater
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: laravel-zero/phar-updater
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Jul 12, 2017

  1. Copy the full SHA
    ac8802d View commit details

Commits on Feb 20, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    fb9d3b1 View commit details

Commits on Mar 30, 2018

  1. Copy the full SHA
    d01d3b8 View commit details

Commits on Oct 30, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    a6ad32a View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    cde8467 View commit details
  3. docs: add notice of fork

    owenvoke committed Oct 30, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    ee75242 View commit details

Commits on Dec 15, 2020

  1. docs: update changelog

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    ce6c555 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    f78ff9c View commit details
  3. feat: drop support for PHP <=7.2

    Only support the versions that Laravel Zero supports.
    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    646c693 View commit details
  4. feat: update to PHPUnit 9.4

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    fe5cfcc View commit details
  5. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    3f25cdb View commit details
  6. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    d3dcae5 View commit details
  7. docs: update badges

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    868a07c View commit details
  8. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    34b4c7b View commit details
  9. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    8dfc432 View commit details
  10. feat: add support for PHP 8

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    6744e59 View commit details
  11. ci: add support for PHP 8

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    2c1851a View commit details
  12. chore: remove unused files

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    f5dbf8c View commit details
  13. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    98b069e View commit details
  14. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    69834bf View commit details
  15. chore: update dotfiles

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    3fb5489 View commit details
  16. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    bea1362 View commit details
  17. docs: update line-wrapping

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    c83f763 View commit details
  18. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    6e12f3d View commit details
  19. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    7f404f0 View commit details
  20. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    71f20d1 View commit details
  21. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    7737a2f View commit details
  22. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    f69b0b8 View commit details
  23. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    76bf4d2 View commit details
  24. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    0162e42 View commit details
  25. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    d1c36d9 View commit details
  26. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    802b510 View commit details
  27. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    d6a078d View commit details
  28. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    830a460 View commit details
  29. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    2e30430 View commit details
  30. style: add array generics

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    87e60f4 View commit details
  31. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    683f3ba View commit details
  32. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    7632ea0 View commit details
  33. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    82374fb View commit details
  34. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    644d513 View commit details
  35. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    35c8254 View commit details
  36. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    5097b52 View commit details
  37. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    436b937 View commit details
  38. docs: update description

    owenvoke committed Dec 15, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    2ca6853 View commit details

Commits on Feb 8, 2021

  1. feat: add SHA-512 strategy

    owenvoke committed Feb 8, 2021

    Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    425fc30 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    9f41128 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    65d27f2 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    1432b06 View commit details

Commits on Mar 9, 2021

  1. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    c3e94f7 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    owenvoke Owen Voke
    Copy the full SHA
    47610b5 View commit details
Showing with 1,192 additions and 725 deletions.
  1. +18 −0 .editorconfig
  2. +15 −0 .gitattributes
  3. +63 −0 .github/workflows/static.yml
  4. +38 −0 .github/workflows/tests.yml
  5. +5 −4 .gitignore
  6. +0 −10 .php_cs
  7. +0 −1 .styleci.yml
  8. +0 −32 .travis.yml
  9. +72 −0 CHANGELOG.md
  10. +157 −115 README.md
  11. +24 −8 composer.json
  12. +0 −11 humbug.json.dist
  13. +19 −0 phpstan-baseline.neon
  14. +7 −0 phpstan.neon.dist
  15. +6 −16 phpunit.xml.dist
  16. +4 −5 src/Exception/ExceptionInterface.php
  17. +4 −5 src/Exception/FilesystemException.php
  18. +4 −5 src/Exception/HttpRequestException.php
  19. +4 −5 src/Exception/InvalidArgumentException.php
  20. +4 −5 src/Exception/JsonParsingException.php
  21. +4 −5 src/Exception/NoSignatureException.php
  22. +4 −5 src/Exception/RuntimeException.php
  23. +47 −0 src/Strategy/DirectDownloadStrategyAbstract.php
  24. +44 −50 src/Strategy/GithubStrategy.php
  25. +13 −20 src/Strategy/Sha256Strategy.php
  26. +44 −0 src/Strategy/Sha512Strategy.php
  27. +14 −22 src/Strategy/ShaStrategy.php
  28. +21 −24 src/Strategy/ShaStrategyAbstract.php
  29. +3 −6 src/Strategy/StrategyInterface.php
  30. +112 −73 src/Updater.php
  31. +37 −31 src/VersionParser.php
  32. +53 −55 tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php
  33. +49 −58 tests/Humbug/Test/SelfUpdate/UpdaterSha256StrategyTest.php
  34. +154 −0 tests/Humbug/Test/SelfUpdate/UpdaterSha512StrategyTest.php
  35. +98 −105 tests/Humbug/Test/SelfUpdate/UpdaterTest.php
  36. +42 −43 tests/Humbug/Test/SelfUpdate/VersionParserTest.php
  37. +1 −0 tests/Humbug/Test/SelfUpdate/_files/build/new.sha512.version
  38. +1 −0 tests/Humbug/Test/SelfUpdate/_files/build/src/new/run.php
  39. +1 −0 tests/Humbug/Test/SelfUpdate/_files/build/src/old/run.php
  40. +1 −0 tests/Humbug/Test/SelfUpdate/_files/good.sha512.version
  41. +5 −6 tests/bootstrap.php
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_size = 4
indent_style = space
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml, yaml}]
indent_size = 2
15 changes: 15 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
* text=auto

# Path-based git attributes
# https://git-scm.com/docs/gitattributes

# Ignore all test and documentation with "export-ignore".
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.styleci.yml export-ignore
/docs export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
63 changes: 63 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Static Analysis

on: ['push', 'pull_request']

jobs:
pint:
runs-on: ubuntu-latest

name: Pint

steps:

- name: Set git to use LF
run: |
git config --global core.autocrlf false
git config --global core.eol lf
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: zip
coverage: none

- name: Install PHP dependencies
uses: ramsey/composer-install@v3
with:
dependency-versions: highest
composer-options: "--prefer-dist"

- name: Run Pint
run: vendor/bin/pint --test --ansi

phpstan:
runs-on: ubuntu-latest

strategy:
matrix:
dependency-version: [prefer-lowest, prefer-stable]

name: PHPStan (${{ matrix.dependency-version }})

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
coverage: none

- name: Install PHP dependencies
uses: ramsey/composer-install@v3
with:
dependency-versions: highest
composer-options: "--prefer-dist"

- name: Run PHPStan
run: vendor/bin/phpstan analyse --no-progress --ansi
38 changes: 38 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tests

on: ['push', 'pull_request']

jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
php: ['8.4', '8.3', '8.2']
dependency-version: [highest, lowest]

name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Setup Problem Matches
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install PHP dependencies
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependency-version }}
composer-options: --prefer-dist

- name: Unit Tests
run: ./vendor/bin/phpunit --colors=always
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
composer.lock
vendor
humbuglog.txt
humbuglog.json
/vendor
/.phpunit.result.cache
/.php_cs.cache
/composer.lock
/phpunit.xml
10 changes: 0 additions & 10 deletions .php_cs

This file was deleted.

1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

32 changes: 0 additions & 32 deletions .travis.yml

This file was deleted.

72 changes: 72 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## Unreleased

## [v1.4.2 - 2025-04-07](https://github.com/laravel-zero/phar-updater/compare/v1.4.1...v1.4.2)

### Changed
- Update Packagist repository URL ([#15](https://github.com/laravel-zero/phar-updater/pull/15))

## [v1.4.1 - 2025-03-31](https://github.com/laravel-zero/phar-updater/compare/v1.4.0...v1.4.1)

### Changed
- Update to Pint 1.21.x ([#14](https://github.com/laravel-zero/phar-updater/pull/14))
- Update to PHPStan 2.x ([#14](https://github.com/laravel-zero/phar-updater/pull/14))
- Update to PHPUnit 11.x ([#14](https://github.com/laravel-zero/phar-updater/pull/14))

### Removed
- Drop support for PHP 8.1 ([#14](https://github.com/laravel-zero/phar-updater/pull/14))

## [v1.4.0 - 2023-09-01](https://github.com/laravel-zero/phar-updater/compare/v1.3.0...v1.4.0)

### Changed
- Update to Pint 1.12.x ([#13](https://github.com/laravel-zero/phar-updater/pull/13))

### Fixed
- Resolve `getCurrentRemoteVersion()` when latest is unstable ([#12](https://github.com/laravel-zero/phar-updater/pull/12))

### Removed
- Drop support for PHP 8.0 ([#13](https://github.com/laravel-zero/phar-updater/pull/13))

## [v1.3.0 - 2022-02-04](https://github.com/laravel-zero/phar-updater/compare/v1.2.0...v1.3.0)

### Added
- Add a new abstract Direct Download class ([#8](https://github.com/laravel-zero/phar-updater/pull/8))

## [v1.2.0 - 2022-02-04](https://github.com/laravel-zero/phar-updater/compare/v1.1.1...v1.2.0)

### Added
- Add support for PHP 8.1 ([#7](https://github.com/laravel-zero/phar-updater/pull/7))

### Removed
- Drop support for PHP `<8.0` ([#7](https://github.com/laravel-zero/phar-updater/pull/7))

## [v1.1.1 - 2021-08-03](https://github.com/laravel-zero/phar-updater/compare/v1.1.0...v1.1.1)

### Fixed
- Apply packagist changes to GithubStrategy ([#5](https://github.com/laravel-zero/phar-updater/pull/5))

## [v1.1.0 - 2021-06-29](https://github.com/laravel-zero/phar-updater/compare/v1.0.6...v1.1.0)

### Added
- Add support for PHP 8 ([#1](https://github.com/laravel-zero/phar-updater/pull/1))
- Add PHPStan for static analysis ([#3](https://github.com/laravel-zero/phar-updater/pull/3))
- Add new SHA-256 strategy ([7632ea0](https://github.com/laravel-zero/phar-updater/commit/7632ea05325049700463743bffdadb29d072bb94))
- Add new SHA-512 strategy ([#4](https://github.com/laravel-zero/phar-updater/pull/4))

### Changed
- Update to use PHPUnit 9.4 ([fe5cfcc](https://github.com/laravel-zero/phar-updater/commit/fe5cfccb47b91920fc7cecb327c77e28650f3815))
- Update to use Packagist Composer 2.x API for `GitHubStrategy` ([162c9af](https://github.com/laravel-zero/phar-updater/commit/162c9af6cf53fabb4985c6e402e00fda3ed51654))

### Removed
- Drop support for PHP `<7.3` ([646c693](https://github.com/laravel-zero/phar-updater/commit/646c693f4fc03a2e1ec65eaf399a6eb014519397))
- Remove `humbug_get_contents` ([7737a2f](https://github.com/laravel-zero/phar-updater/commit/7737a2f6c2e2414252e89f0163be843f23615f28))

## v1.0.6 - 2020-10-29

### Added
- Initial version (the same as [`padraic/phar-updater:v1.0.6`](https://github.com/humbug/phar-updater))
272 changes: 157 additions & 115 deletions README.md

Large diffs are not rendered by default.

32 changes: 24 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "padraic/phar-updater",
"name": "laravel-zero/phar-updater",
"description": "A thing to make PHAR self-updating easy and secure.",
"type": "library",
"keywords": ["phar", "self-update", "update", "humbug"],
@@ -9,21 +9,37 @@
"name": "Padraic Brady",
"email": "padraic.brady@gmail.com",
"homepage": "http://blog.astrumfutura.com"
},
{
"name": "Owen Voke",
"email": "development@voke.dev",
"homepage": "https://voke.dev"
}
],
"require": {
"php": "^5.6|^7.0",
"padraic/humbug_get_contents": "^1.0"
"php": "^8.2"
},
"require-dev": {
"phpunit/phpunit": "^5.5|^6.0"
"ext-json": "*",
"laravel/pint": "^1.21",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^11.0"
},
"autoload": {
"psr-4": { "Humbug\\SelfUpdate\\": "src/" }
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
"scripts": {
"test:types": "phpstan analyse --ansi --memory-limit=-1",
"test:unit": "phpunit --colors=always",
"test": [
"@test:types",
"@test:unit"
]
},
"conflict": {
"padraic/phar-updater": "*"
},
"config": {
"sort-packages": true
}
}
11 changes: 0 additions & 11 deletions humbug.json.dist

This file was deleted.

19 changes: 19 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
parameters:
ignoreErrors:
-
message: '#^Method Humbug\\SelfUpdate\\Strategy\\Sha256Strategy\:\:getCurrentRemoteVersion\(\) never returns bool so it can be removed from the return type\.$#'
identifier: return.unusedType
count: 1
path: src/Strategy/Sha256Strategy.php

-
message: '#^Method Humbug\\SelfUpdate\\Strategy\\Sha512Strategy\:\:getCurrentRemoteVersion\(\) never returns bool so it can be removed from the return type\.$#'
identifier: return.unusedType
count: 1
path: src/Strategy/Sha512Strategy.php

-
message: '#^Call to function is_bool\(\) with bool will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/Updater.php
7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src/
22 changes: 6 additions & 16 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.4/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php">

<testsuites>
<testsuite name="Phar-Updater Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<source>
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
</include>
</source>
</phpunit>
9 changes: 4 additions & 5 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

interface ExceptionInterface
{
}
interface ExceptionInterface {}
9 changes: 4 additions & 5 deletions src/Exception/FilesystemException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

class FilesystemException extends RuntimeException
{
}
class FilesystemException extends RuntimeException {}
9 changes: 4 additions & 5 deletions src/Exception/HttpRequestException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

class HttpRequestException extends RuntimeException
{
}
class HttpRequestException extends RuntimeException {}
9 changes: 4 additions & 5 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

class InvalidArgumentException extends \RuntimeException implements ExceptionInterface
{
}
class InvalidArgumentException extends \RuntimeException implements ExceptionInterface {}
9 changes: 4 additions & 5 deletions src/Exception/JsonParsingException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

class JsonParsingException extends RuntimeException
{
}
class JsonParsingException extends RuntimeException {}
9 changes: 4 additions & 5 deletions src/Exception/NoSignatureException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

class NoSignatureException extends RuntimeException
{
}
class NoSignatureException extends RuntimeException {}
9 changes: 4 additions & 5 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/humbug/blob/master/LICENSE New BSD License
*/

namespace Humbug\SelfUpdate\Exception;

class RuntimeException extends \RuntimeException implements ExceptionInterface
{
}
class RuntimeException extends \RuntimeException implements ExceptionInterface {}
47 changes: 47 additions & 0 deletions src/Strategy/DirectDownloadStrategyAbstract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Humbug\SelfUpdate\Strategy;

use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Updater;

abstract class DirectDownloadStrategyAbstract implements StrategyInterface
{
protected string $localVersion;

abstract public function getDownloadUrl(): string;

/** {@inheritdoc} */
public function download(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler([$updater, 'throwHttpRequestException']);
$result = file_get_contents($this->getDownloadUrl());
restore_error_handler();
if ($result === false) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s',
$this->getDownloadUrl()
));
}

file_put_contents($updater->getTempPharFile(), $result);
}

/** {@inheritdoc} */
public function getCurrentRemoteVersion(Updater $updater)
{
return 'latest';
}

public function setCurrentLocalVersion(string $version): void
{
$this->localVersion = $version;
}

/** {@inheritdoc} */
public function getCurrentLocalVersion(Updater $updater)
{
return $this->localVersion;
}
}
94 changes: 44 additions & 50 deletions src/Strategy/GithubStrategy.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*
@@ -12,16 +13,17 @@

namespace Humbug\SelfUpdate\Strategy;

use Humbug\SelfUpdate\Updater;
use Humbug\SelfUpdate\VersionParser;
use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Exception\InvalidArgumentException;
use Humbug\SelfUpdate\Exception\JsonParsingException;
use function Humbug\get_contents;
use Humbug\SelfUpdate\Updater;
use Humbug\SelfUpdate\VersionParser;

use function file_get_contents;

class GithubStrategy implements StrategyInterface
{
const API_URL = 'https://packagist.org/p/%s.json';
const API_URL = 'https://repo.packagist.org/p2/%s.json';

const STABLE = 'stable';

@@ -59,49 +61,40 @@ class GithubStrategy implements StrategyInterface
*/
private $stability = self::STABLE;

/**
* Download the remote Phar file.
*
* @param Updater $updater
* @return void
*/
/** {@inheritdoc} */
public function download(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler(array($updater, 'throwHttpRequestException'));
$result = get_contents($this->remoteUrl);
set_error_handler([$updater, 'throwHttpRequestException']);
$result = file_get_contents($this->remoteUrl);
restore_error_handler();
if (false === $result) {
if ($result === false) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s', $this->remoteUrl
'Request to URL failed: %s',
$this->remoteUrl
));
}

file_put_contents($updater->getTempPharFile(), $result);
}

/**
* Retrieve the current version available remotely.
*
* @param Updater $updater
* @return string|bool
*/
/** {@inheritdoc} */
public function getCurrentRemoteVersion(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler(array($updater, 'throwHttpRequestException'));
set_error_handler([$updater, 'throwHttpRequestException']);
$packageUrl = $this->getApiUrl();
$package = json_decode(get_contents($packageUrl), true);
$package = json_decode(file_get_contents($packageUrl), true);
restore_error_handler();

if (null === $package || json_last_error() !== JSON_ERROR_NONE) {
if ($package === null || json_last_error() !== JSON_ERROR_NONE) {
throw new JsonParsingException(
'Error parsing JSON package data'
. (function_exists('json_last_error_msg') ? ': ' . json_last_error_msg() : '')
.(function_exists('json_last_error_msg') ? ': '.json_last_error_msg() : '')
);
}

$versions = array_keys($package['packages'][$this->getPackageName()]);
$versions = array_column($package['packages'][$this->getPackageName()], 'version');
$versionParser = new VersionParser($versions);
if ($this->getStability() === self::STABLE) {
$this->remoteVersion = $versionParser->getMostRecentStable();
@@ -112,48 +105,48 @@ public function getCurrentRemoteVersion(Updater $updater)
}

/**
* Setup remote URL if there's an actual version to download
* Setup remote URL if there's an actual version to download.
*/
if (!empty($this->remoteVersion)) {
$this->remoteUrl = $this->getDownloadUrl($package);
if (! empty($this->remoteVersion)) {
$remoteVersionPackages = array_filter($package['packages'][$this->getPackageName()], function (array $package) {
return $package['version'] === $this->remoteVersion;
});
$chosenVersion = reset($remoteVersionPackages);

$this->remoteUrl = $this->getDownloadUrl($chosenVersion);
}

return $this->remoteVersion;
}

/**
* Retrieve the current version of the local phar file.
*
* @param Updater $updater
* @return string
*/
/** {@inheritdoc} */
public function getCurrentLocalVersion(Updater $updater)
{
return $this->localVersion;
}

/**
* Set version string of the local phar
* Set version string of the local phar.
*
* @param string $version
* @param string $version
*/
public function setCurrentLocalVersion($version)
{
$this->localVersion = $version;
}

/**
* Set Package name
* Set Package name.
*
* @param string $name
* @param string $name
*/
public function setPackageName($name)
{
$this->packageName = $name;
}

/**
* Get Package name
* Get Package name.
*
* @return string
*/
@@ -163,17 +156,17 @@ public function getPackageName()
}

/**
* Set phar file's name
* Set phar file's name.
*
* @param string $name
* @param string $name
*/
public function setPharName($name)
{
$this->pharName = $name;
}

/**
* Get phar file's name
* Get phar file's name.
*
* @return string
*/
@@ -183,9 +176,9 @@ public function getPharName()
}

/**
* Set target stability
* Set target stability.
*
* @param string $stability
* @param string $stability
*/
public function setStability($stability)
{
@@ -198,7 +191,7 @@ public function setStability($stability)
}

/**
* Get target stability
* Get target stability.
*
* @return string
*/
@@ -212,19 +205,20 @@ protected function getApiUrl()
return sprintf(self::API_URL, $this->getPackageName());
}

/** @param array<mixed, mixed> $package */
protected function getDownloadUrl(array $package)
{
$baseUrl = preg_replace(
'{\.git$}',
'',
$package['packages'][$this->getPackageName()][$this->remoteVersion]['source']['url']
$package['source']['url']
);
$downloadUrl = sprintf(

return sprintf(
'%s/releases/download/%s/%s',
$baseUrl,
$this->remoteVersion,
$this->getPharName()
);
return $downloadUrl;
}
}
33 changes: 13 additions & 20 deletions src/Strategy/Sha256Strategy.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2017 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*
@@ -14,33 +15,30 @@

use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Updater;
use function Humbug\get_contents;

use function file_get_contents;

final class Sha256Strategy extends ShaStrategyAbstract
{
/**
* Retrieve the current version available remotely.
*
* @param Updater $updater
* @return string|bool
*/
/** {@inheritdoc} */
public function getCurrentRemoteVersion(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler(array($updater, 'throwHttpRequestException'));
$version = get_contents($this->getVersionUrl());
set_error_handler([$updater, 'throwHttpRequestException']);
$version = file_get_contents($this->getVersionUrl());
restore_error_handler();
if (false === $version) {
if ($version === false) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s', $this->getVersionUrl()
'Request to URL failed: %s',
$this->getVersionUrl()
));
}
if (empty($version)) {
throw new HttpRequestException(
'Version request returned empty response.'
);
}
if (!preg_match('%^[a-z0-9]{64}%', $version, $matches)) {
if (! preg_match('%^[a-z0-9]{64}%', $version, $matches)) {
throw new HttpRequestException(
'Version request returned incorrectly formatted response.'
);
@@ -49,12 +47,7 @@ public function getCurrentRemoteVersion(Updater $updater)
return $matches[0];
}

/**
* Retrieve the current version of the local phar file.
*
* @param Updater $updater
* @return string
*/
/** {@inheritdoc} */
public function getCurrentLocalVersion(Updater $updater)
{
return hash_file('sha256', $updater->getLocalPharFile());
44 changes: 44 additions & 0 deletions src/Strategy/Sha512Strategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Humbug\SelfUpdate\Strategy;

use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Updater;

use function file_get_contents;

final class Sha512Strategy extends ShaStrategyAbstract
{
/** {@inheritdoc} */
public function getCurrentRemoteVersion(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler([$updater, 'throwHttpRequestException']);
$version = file_get_contents($this->getVersionUrl());
restore_error_handler();
if ($version === false) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s',
$this->getVersionUrl()
));
}
if (empty($version)) {
throw new HttpRequestException(
'Version request returned empty response.'
);
}
if (! preg_match('%^[a-z0-9]{128}%', $version, $matches)) {
throw new HttpRequestException(
'Version request returned incorrectly formatted response.'
);
}

return $matches[0];
}

/** {@inheritdoc} */
public function getCurrentLocalVersion(Updater $updater)
{
return hash_file('sha512', $updater->getLocalPharFile());
}
}
36 changes: 14 additions & 22 deletions src/Strategy/ShaStrategy.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*
@@ -14,37 +15,33 @@

use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Updater;
use function Humbug\get_contents;

use function file_get_contents;

/**
* @deprecated 1.0.4 SHA-1 is increasingly susceptible to collision attacks; use SHA-256
* @deprecated 1.0.4 SHA-1 is increasingly susceptible to collision attacks; use SHA-256 or SHA-512
*/
class ShaStrategy extends ShaStrategyAbstract
{

/**
* Retrieve the current version available remotely.
*
* @param Updater $updater
* @return string|bool
*/
/** {@inheritdoc} */
public function getCurrentRemoteVersion(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler(array($updater, 'throwHttpRequestException'));
$version = get_contents($this->getVersionUrl());
set_error_handler([$updater, 'throwHttpRequestException']);
$version = file_get_contents($this->getVersionUrl());
restore_error_handler();
if (false === $version) {
if ($version === false) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s', $this->getVersionUrl()
'Request to URL failed: %s',
$this->getVersionUrl()
));
}
if (empty($version)) {
throw new HttpRequestException(
'Version request returned empty response.'
);
}
if (!preg_match('%^[a-z0-9]{40}%', $version, $matches)) {
if (! preg_match('%^[a-z0-9]{40}%', $version, $matches)) {
throw new HttpRequestException(
'Version request returned incorrectly formatted response.'
);
@@ -53,12 +50,7 @@ public function getCurrentRemoteVersion(Updater $updater)
return $matches[0];
}

/**
* Retrieve the current version of the local phar file.
*
* @param Updater $updater
* @return string
*/
/** {@inheritdoc} */
public function getCurrentLocalVersion(Updater $updater)
{
return sha1_file($updater->getLocalPharFile());
45 changes: 21 additions & 24 deletions src/Strategy/ShaStrategyAbstract.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*
@@ -15,7 +16,8 @@
use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Exception\InvalidArgumentException;
use Humbug\SelfUpdate\Updater;
use function Humbug\get_contents;

use function file_get_contents;

abstract class ShaStrategyAbstract implements StrategyInterface
{
@@ -36,35 +38,31 @@ abstract class ShaStrategyAbstract implements StrategyInterface
*/
protected $pharUrl;

/**
* Download the remote Phar file.
*
* @param Updater $updater
* @return void
*/
/** {@inheritdoc} */
public function download(Updater $updater)
{
/** Switch remote request errors to HttpRequestExceptions */
set_error_handler(array($updater, 'throwHttpRequestException'));
$result = get_contents($this->getPharUrl());
set_error_handler([$updater, 'throwHttpRequestException']);
$result = file_get_contents($this->getPharUrl());
restore_error_handler();
if (false === $result) {
if ($result === false) {
throw new HttpRequestException(sprintf(
'Request to URL failed: %s', $this->getPharUrl()
'Request to URL failed: %s',
$this->getPharUrl()
));
}

file_put_contents($updater->getTempPharFile(), $result);
}

/**
* Set URL to phar file
* Set URL to phar file.
*
* @param string $url
* @param string $url
*/
public function setPharUrl($url)
{
if (!$this->validateAllowedUrl($url)) {
if (! $this->validateAllowedUrl($url)) {
throw new InvalidArgumentException(
sprintf('Invalid url passed as argument: %s.', $url)
);
@@ -73,7 +71,7 @@ public function setPharUrl($url)
}

/**
* Get URL for phar file
* Get URL for phar file.
*
* @return string
*/
@@ -83,13 +81,13 @@ public function getPharUrl()
}

/**
* Set URL to version file
* Set URL to version file.
*
* @param string $url
* @param string $url
*/
public function setVersionUrl($url)
{
if (!$this->validateAllowedUrl($url)) {
if (! $this->validateAllowedUrl($url)) {
throw new InvalidArgumentException(
sprintf('Invalid url passed as argument: %s.', $url)
);
@@ -98,7 +96,7 @@ public function setVersionUrl($url)
}

/**
* Get URL for version file
* Get URL for version file.
*
* @return string
*/
@@ -109,9 +107,8 @@ public function getVersionUrl()

protected function validateAllowedUrl($url)
{
return (
return
filter_var($url, FILTER_VALIDATE_URL)
&& in_array(parse_url($url, PHP_URL_SCHEME), self::SUPPORTED_SCHEMES)
);
&& in_array(parse_url($url, PHP_URL_SCHEME), self::SUPPORTED_SCHEMES);
}
}
9 changes: 3 additions & 6 deletions src/Strategy/StrategyInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*
@@ -16,27 +17,23 @@

interface StrategyInterface
{

/**
* Download the remote Phar file.
*
* @param Updater $updater
* @return void
*/
public function download(Updater $updater);

/**
* Retrieve the current version available remotely.
*
* @param Updater $updater
* @return string|bool
*/
public function getCurrentRemoteVersion(Updater $updater);

/**
* Retrieve the current version of the local phar file.
*
* @param Updater $updater
* @return string
*/
public function getCurrentLocalVersion(Updater $updater);
185 changes: 112 additions & 73 deletions src/Updater.php

Large diffs are not rendered by default.

68 changes: 37 additions & 31 deletions src/VersionParser.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*
@@ -14,9 +15,8 @@

class VersionParser
{

/**
* @var array
* @var array<int, string>
*/
private $versions;

@@ -26,16 +26,16 @@ class VersionParser
private $modifier = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?';

/**
* @param array $versions
* @param array<mixed, string> $versions
*/
public function __construct(array $versions = array())
public function __construct(array $versions = [])
{
$this->versions = $versions;
}

/**
* Get the most recent stable numbered version from versions passed to
* constructor (if any)
* constructor (if any).
*
* @return string
*/
@@ -46,7 +46,7 @@ public function getMostRecentStable()

/**
* Get the most recent unstable numbered version from versions passed to
* constructor (if any)
* constructor (if any).
*
* @return string
*/
@@ -57,7 +57,7 @@ public function getMostRecentUnStable()

/**
* Get the most recent stable or unstable numbered version from versions passed to
* constructor (if any)
* constructor (if any).
*
* @return string
*/
@@ -67,9 +67,9 @@ public function getMostRecentAll()
}

/**
* Checks if given version string represents a stable numbered version
* Checks if given version string represents a stable numbered version.
*
* @param string $version
* @param string $version
* @return bool
*/
public function isStable($version)
@@ -81,30 +81,30 @@ public function isStable($version)
* Checks if given version string represents a 'pre-release' version, i.e.
* it's unstable but not development level.
*
* @param string $version
* @param string $version
* @return bool
*/
public function isPreRelease($version)
{
return !$this->stable($version) && !$this->development($version);
return ! $this->stable($version) && ! $this->development($version);
}

/**
* Checks if given version string represents an unstable or dev-level
* numbered version
* numbered version.
*
* @param string $version
* @param string $version
* @return bool
*/
public function isUnstable($version)
{
return !$this->stable($version);
return ! $this->stable($version);
}

/**
* Checks if given version string represents a dev-level numbered version
* Checks if given version string represents a dev-level numbered version.
*
* @param string $version
* @param string $version
* @return bool
*/
public function isDevelopment($version)
@@ -114,22 +114,23 @@ public function isDevelopment($version)

private function selectRecentStable()
{
$candidates = array();
$candidates = [];
foreach ($this->versions as $version) {
if (!$this->stable($version)) {
if (! $this->stable($version)) {
continue;
}
$candidates[] = $version;
}
if (empty($candidates)) {
return false;
}

return $this->findMostRecent($candidates);
}

private function selectRecentUnstable()
{
$candidates = array();
$candidates = [];
foreach ($this->versions as $version) {
if ($this->stable($version) || $this->development($version)) {
continue;
@@ -139,12 +140,13 @@ private function selectRecentUnstable()
if (empty($candidates)) {
return false;
}

return $this->findMostRecent($candidates);
}

private function selectRecentAll()
{
$candidates = array();
$candidates = [];
foreach ($this->versions as $version) {
if ($this->development($version)) {
continue;
@@ -154,18 +156,20 @@ private function selectRecentAll()
if (empty($candidates)) {
return false;
}

return $this->findMostRecent($candidates);
}

/** @param array<mixed, string> $candidates */
private function findMostRecent(array $candidates)
{
$candidate = null;
$tracker = null;
$candidate = '';
foreach ($candidates as $version) {
if (version_compare($candidate, $version, '<')) {
$candidate = $version;
}
}

return $candidate;
}

@@ -176,27 +180,29 @@ private function stable($version)
return false;
}
preg_match('{'.$this->modifier.'$}i', strtolower($version), $match);
if (!empty($match[3])) {
if (! empty($match[3])) {
return false;
}
if (!empty($match[1])) {
if ('beta' === $match[1] || 'b' === $match[1]
|| 'alpha' === $match[1] || 'a' === $match[1]
|| 'rc' === $match[1]) {
if (! empty($match[1])) {
if ($match[1] === 'beta' || $match[1] === 'b'
|| $match[1] === 'alpha' || $match[1] === 'a'
|| $match[1] === 'rc') {
return false;
}
}

return true;
}

private function development($version)
{
if ('dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4)) {
if (substr($version, 0, 4) === 'dev-' || substr($version, -4) === '-dev') {
return true;
}
if (1 == preg_match("/-\d+-[a-z0-9]{8,}$/", $version)) {
if (preg_match("/-\d+-[a-z0-9]{8,}$/", $version) == 1) {
return true;
}

return false;
}
}
108 changes: 53 additions & 55 deletions tests/Humbug/Test/SelfUpdate/UpdaterGithubStrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
* @subpackage UnitTests
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/pharupdater/blob/master/LICENSE New BSD License
*/

namespace Humbug\Test\SelfUpdate;

use Humbug\SelfUpdate\Updater;
use Humbug\SelfUpdate\Exception\InvalidArgumentException;
use Humbug\SelfUpdate\Strategy\GithubStrategy;
use Humbug\SelfUpdate\Updater;
use PHPUnit\Framework\TestCase;

class UpdaterGithubStrategyTest extends TestCase
@@ -24,29 +25,25 @@ class UpdaterGithubStrategyTest extends TestCase

private $tmp;

private $data;

public function setUp()
protected function setUp(): void
{
$this->tmp = sys_get_temp_dir();
$this->files = __DIR__ . '/_files';
$this->updater = new Updater($this->files . '/test.phar', false, Updater::STRATEGY_GITHUB);
$this->files = __DIR__.'/_files';
$this->updater = new Updater($this->files.'/test.phar', false, Updater::STRATEGY_GITHUB);
}

public function tearDown()
protected function tearDown(): void
{
$this->deleteTempPhars();
}

public function testConstruction()
public function test_construction(): void
{
$updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
$this->assertTrue(
$updater->getStrategy() instanceof GithubStrategy
);
$this->assertInstanceOf(GithubStrategy::class, $updater->getStrategy());
}

public function testSetCurrentLocalVersion()
public function test_set_current_local_version(): void
{
$this->updater->getStrategy()->setCurrentLocalVersion('1.0');
$this->assertEquals(
@@ -55,7 +52,7 @@ public function testSetCurrentLocalVersion()
);
}

public function testSetPharName()
public function test_set_phar_name(): void
{
$this->updater->getStrategy()->setPharName('foo.phar');
$this->assertEquals(
@@ -64,7 +61,7 @@ public function testSetPharName()
);
}

public function testSetPackageName()
public function test_set_package_name(): void
{
$this->updater->getStrategy()->setPackageName('foo/bar');
$this->assertEquals(
@@ -73,7 +70,7 @@ public function testSetPackageName()
);
}

public function testSetStability()
public function test_set_stability(): void
{
$this->assertEquals(
'stable',
@@ -86,56 +83,52 @@ public function testSetStability()
);
}

public function testSetStabilityThrowsExceptionOnInvalidStabilityValue()
public function test_set_stability_throws_exception_on_invalid_stability_value(): void
{
$this->expectException(
'Humbug\\SelfUpdate\\Exception\\InvalidArgumentException'
);
$this->expectException(InvalidArgumentException::class);
$this->updater->getStrategy()->setStability('foo');
}

/**
* @runInSeparateProcess
*/
public function testUpdatePhar()
public function test_update_phar(): void
{
if (!extension_loaded('openssl')) {
if (! extension_loaded('openssl')) {
$this->markTestSkipped('This test requires the openssl extension to run.');
}

$this->createTestPharAndKey();
$this->assertEquals('old', $this->getPharOutput($this->tmp . '/old.phar'));
$this->assertEquals('old', $this->getPharOutput($this->tmp.'/old.phar'));

$updater = new Updater($this->tmp . '/old.phar');
$updater = new Updater($this->tmp.'/old.phar');
$updater->setStrategyObject(new GithubTestStrategy);
$updater->getStrategy()->setPharName('new.phar');
$updater->getStrategy()->setPackageName('humbug/test-phar');
$updater->getStrategy()->setCurrentLocalVersion('1.0.0');

$this->assertTrue($updater->update());
$this->assertEquals('new', $this->getPharOutput($this->tmp . '/old.phar'));
$this->assertEquals('new', $this->getPharOutput($this->tmp.'/old.phar'));
}

/**
* Helpers
*/
// Helpers

private function getPharOutput($path)
private function getPharOutput(string $path): string
{
return exec('php ' . escapeshellarg($path));
return exec('php '.escapeshellarg($path));
}

private function deleteTempPhars()
private function deleteTempPhars(): void
{
@unlink($this->tmp . '/old.phar');
@unlink($this->tmp . '/old.phar.pubkey');
@unlink($this->tmp . '/releases/download/1.0.1/new.phar');
@unlink($this->tmp . '/releases/download/1.0.1/new.phar.pubkey');
@unlink($this->tmp . '/old.1c7049180abee67826d35ce308c38272242b64b8.phar');
@unlink($this->tmp . '/packages.json');
@unlink($this->tmp.'/old.phar');
@unlink($this->tmp.'/old.phar.pubkey');
@unlink($this->tmp.'/releases/download/1.0.1/new.phar');
@unlink($this->tmp.'/releases/download/1.0.1/new.phar.pubkey');
@unlink($this->tmp.'/old.1c7049180abee67826d35ce308c38272242b64b8.phar');
@unlink($this->tmp.'/packages.json');
}

private function createTestPharAndKey()
private function createTestPharAndKey(): void
{
copy($this->files.'/build/old.phar', $this->tmp.'/old.phar');
chmod($this->tmp.'/old.phar', 0755);
@@ -145,26 +138,31 @@ private function createTestPharAndKey()
);
@mkdir($this->tmp.'/releases/download/1.0.1', 0755, true);
copy($this->files.'/build/new.phar', $this->tmp.'/releases/download/1.0.1/new.phar');
file_put_contents($this->tmp . '/packages.json', json_encode(array(
'packages' => array(
'humbug/test-phar' => array(
'1.0.1' => array(
'source' => array(
'url' => 'file://' . $this->tmp . '.git'
)
),
'1.0.0' => array(
)
)
)
)));
file_put_contents($this->tmp.'/packages.json', json_encode([
'packages' => [
'humbug/test-phar' => [
[
'version' => '2.0.0-beta.1',
],
[
'version' => '1.0.1',
'source' => [
'url' => 'file://'.$this->tmp.'.git',
],
],
[
'version' => '1.0.0',
],
],
],
], JSON_THROW_ON_ERROR));
}
}

class GithubTestStrategy extends GithubStrategy
{
protected function getApiUrl()
protected function getApiUrl(): string
{
return 'file://' . sys_get_temp_dir() . '/packages.json';
return 'file://'.sys_get_temp_dir().'/packages.json';
}
}
107 changes: 49 additions & 58 deletions tests/Humbug/Test/SelfUpdate/UpdaterSha256StrategyTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
* @subpackage UnitTests
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/pharupdater/blob/master/LICENSE New BSD License
*/

namespace Humbug\Test\SelfUpdate;

use Humbug\SelfUpdate\Updater;
use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Exception\InvalidArgumentException;
use Humbug\SelfUpdate\Strategy\Sha256Strategy;
use Humbug\SelfUpdate\Updater;
use PHPUnit\Framework\TestCase;

class UpdaterSha256StrategyTest extends TestCase
@@ -24,134 +26,123 @@ class UpdaterSha256StrategyTest extends TestCase

private $tmp;

private $data;

public function setup()
protected function setup(): void
{
$this->tmp = sys_get_temp_dir();
$this->files = __DIR__ . '/_files';
$this->updater = new Updater($this->files . '/test.phar', true, Updater::STRATEGY_SHA256);
$this->files = __DIR__.'/_files';
$this->updater = new Updater($this->files.'/test.phar', true, Updater::STRATEGY_SHA256);
}

public function teardown()
protected function teardown(): void
{
$this->deleteTempPhars();
}

public function testConstruction()
public function test_construction(): void
{
$updater = new Updater(null, false, Updater::STRATEGY_SHA256);
$this->assertTrue(
$updater->getStrategy() instanceof Sha256Strategy
);
$this->assertInstanceOf(Sha256Strategy::class, $updater->getStrategy());
}


public function testGetCurrentLocalVersion()
public function test_get_current_local_version(): void
{
$this->assertEquals(
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
$this->updater->getStrategy()->getCurrentLocalVersion($this->updater)
);
}

public function testSetPharUrlWithUrl()
public function test_set_phar_url_with_url(): void
{
$this->updater->getStrategy()->setPharUrl('http://www.example.com');
$this->assertEquals($this->updater->getStrategy()->getPharUrl(), 'http://www.example.com');
$this->assertEquals('http://www.example.com', $this->updater->getStrategy()->getPharUrl());

$this->updater->getStrategy()->setPharUrl('https://www.example.com');
$this->assertEquals($this->updater->getStrategy()->getPharUrl(), 'https://www.example.com');
$this->assertEquals('https://www.example.com', $this->updater->getStrategy()->getPharUrl());
}

public function testSetPharUrlThrowsExceptionOnInvalidUrl()
public function test_set_phar_url_throws_exception_on_invalid_url(): void
{
$this->expectException('Humbug\\SelfUpdate\\Exception\\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->updater->getStrategy()->setPharUrl('silly:///home/padraic');
}

public function testSetVersionUrlWithUrl()
public function test_set_version_url_with_url(): void
{
$this->updater->getStrategy()->setVersionUrl('http://www.example.com');
$this->assertEquals($this->updater->getStrategy()->getVersionUrl(), 'http://www.example.com');
$this->assertEquals('http://www.example.com', $this->updater->getStrategy()->getVersionUrl());

$this->updater->getStrategy()->setVersionUrl('https://www.example.com');
$this->assertEquals($this->updater->getStrategy()->getVersionUrl(), 'https://www.example.com');
$this->assertEquals('https://www.example.com', $this->updater->getStrategy()->getVersionUrl());
}

public function testSetVersionUrlThrowsExceptionOnInvalidUrl()
public function test_set_version_url_throws_exception_on_invalid_url(): void
{
$this->expectException('Humbug\\SelfUpdate\\Exception\\InvalidArgumentException');
$this->expectException(InvalidArgumentException::class);
$this->updater->getStrategy()->setVersionUrl('silly:///home/padraic');
}

public function testCanDetectNewRemoteVersionAndStoreVersions()
public function test_can_detect_new_remote_version_and_store_versions(): void
{
$this->updater->getStrategy()->setVersionUrl('file://' . $this->files . '/good.sha256.version');
$this->updater->getStrategy()->setVersionUrl('file://'.$this->files.'/good.sha256.version');
$this->assertTrue($this->updater->hasUpdate());
$this->assertEquals(
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
$this->updater->getOldVersion()
);
$this->assertEquals(
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b858', //5 => 8
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b858', // 5 => 8
$this->updater->getNewVersion()
);
}

public function testThrowsExceptionOnEmptyRemoteVersion()
public function test_throws_exception_on_empty_remote_version(): void
{
$this->expectException(
'Humbug\\SelfUpdate\\Exception\\HttpRequestException',
'Version request returned empty response'
);
$this->updater->getStrategy()->setVersionUrl('file://' . $this->files . '/empty.version');
$this->expectException(HttpRequestException::class);
$this->expectExceptionMessage('Version request returned empty response');
$this->updater->getStrategy()->setVersionUrl('file://'.$this->files.'/empty.version');
$this->assertTrue($this->updater->hasUpdate());
}

public function testThrowsExceptionOnInvalidRemoteVersion()
public function test_throws_exception_on_invalid_remote_version(): void
{
$this->expectException(
'Humbug\\SelfUpdate\\Exception\\HttpRequestException',
'Version request returned incorrectly formatted response'
);
$this->updater->getStrategy()->setVersionUrl('file://' . $this->files . '/bad.version');
$this->expectException(HttpRequestException::class);
$this->expectExceptionMessage('Version request returned incorrectly formatted response');
$this->updater->getStrategy()->setVersionUrl('file://'.$this->files.'/bad.version');
$this->assertTrue($this->updater->hasUpdate());
}

/**
* @runInSeparateProcess
*/
public function testUpdatePhar()
public function test_update_phar(): void
{
$this->createTestPharAndKey();
$this->assertEquals('old', $this->getPharOutput($this->tmp . '/old.phar'));
$this->assertEquals('old', $this->getPharOutput($this->tmp.'/old.phar'));

$updater = new Updater($this->tmp . '/old.phar', true, Updater::STRATEGY_SHA256);
$updater->getStrategy()->setPharUrl('file://' . $this->files . '/build/new.phar');
$updater->getStrategy()->setVersionUrl('file://' . $this->files . '/build/new.sha256.version');
$updater = new Updater($this->tmp.'/old.phar', true, Updater::STRATEGY_SHA256);
$updater->getStrategy()->setPharUrl('file://'.$this->files.'/build/new.phar');
$updater->getStrategy()->setVersionUrl('file://'.$this->files.'/build/new.sha256.version');
$this->assertTrue($updater->update());
$this->assertEquals('new', $this->getPharOutput($this->tmp . '/old.phar'));
$this->assertEquals('new', $this->getPharOutput($this->tmp.'/old.phar'));
}

/**
* Helpers
*/
// Helpers

private function getPharOutput($path)
private function getPharOutput(string $path): string
{
return exec('php ' . escapeshellarg($path));
return exec('php '.escapeshellarg($path));
}

private function deleteTempPhars()
private function deleteTempPhars(): void
{
@unlink($this->tmp . '/old.phar');
@unlink($this->tmp . '/old.phar.pubkey');
@unlink($this->tmp . '/old.phar.temp.pubkey');
@unlink($this->tmp . '/old-old.phar');
@unlink($this->tmp.'/old.phar');
@unlink($this->tmp.'/old.phar.pubkey');
@unlink($this->tmp.'/old.phar.temp.pubkey');
@unlink($this->tmp.'/old-old.phar');
}

private function createTestPharAndKey()
private function createTestPharAndKey(): void
{
copy($this->files.'/build/old.phar', $this->tmp.'/old.phar');
chmod($this->tmp.'/old.phar', 0755);
154 changes: 154 additions & 0 deletions tests/Humbug/Test/SelfUpdate/UpdaterSha512StrategyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php

/**
* Humbug.
*
* @category Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/pharupdater/blob/master/LICENSE New BSD License
*/

namespace Humbug\Test\SelfUpdate;

use Humbug\SelfUpdate\Exception\HttpRequestException;
use Humbug\SelfUpdate\Exception\InvalidArgumentException;
use Humbug\SelfUpdate\Strategy\Sha512Strategy;
use Humbug\SelfUpdate\Updater;
use PHPUnit\Framework\TestCase;

class UpdaterSha512StrategyTest extends TestCase
{
private $files;

/** @var Updater */
private $updater;

private $tmp;

protected function setup(): void
{
$this->tmp = sys_get_temp_dir();
$this->files = __DIR__.'/_files';
$this->updater = new Updater($this->files.'/test.phar', true, Updater::STRATEGY_SHA512);
}

protected function teardown(): void
{
$this->deleteTempPhars();
}

public function test_construction(): void
{
$updater = new Updater(null, false, Updater::STRATEGY_SHA512);
$this->assertInstanceOf(Sha512Strategy::class, $updater->getStrategy());
}

public function test_get_current_local_version(): void
{
$this->assertEquals(
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e',
$this->updater->getStrategy()->getCurrentLocalVersion($this->updater)
);
}

public function test_set_phar_url_with_url(): void
{
$this->updater->getStrategy()->setPharUrl('http://www.example.com');
$this->assertEquals('http://www.example.com', $this->updater->getStrategy()->getPharUrl());

$this->updater->getStrategy()->setPharUrl('https://www.example.com');
$this->assertEquals('https://www.example.com', $this->updater->getStrategy()->getPharUrl());
}

public function test_set_phar_url_throws_exception_on_invalid_url(): void
{
$this->expectException(InvalidArgumentException::class);
$this->updater->getStrategy()->setPharUrl('silly:///home/padraic');
}

public function test_set_version_url_with_url(): void
{
$this->updater->getStrategy()->setVersionUrl('http://www.example.com');
$this->assertEquals('http://www.example.com', $this->updater->getStrategy()->getVersionUrl());

$this->updater->getStrategy()->setVersionUrl('https://www.example.com');
$this->assertEquals('https://www.example.com', $this->updater->getStrategy()->getVersionUrl());
}

public function test_set_version_url_throws_exception_on_invalid_url(): void
{
$this->expectException(InvalidArgumentException::class);
$this->updater->getStrategy()->setVersionUrl('silly:///home/padraic');
}

public function test_can_detect_new_remote_version_and_store_versions(): void
{
$this->updater->getStrategy()->setVersionUrl('file://'.$this->files.'/good.sha512.version');
$this->assertTrue($this->updater->hasUpdate());
$this->assertEquals(
'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e',
$this->updater->getOldVersion()
);
$this->assertEquals(
'b8a705a7430e69f23594c4bf58e8110d0e00e2fe0eb88cfdb5980a825b5734dc4c54e4cebba44e0424b1a79303745b8fb662d65eb34b35da51fd3347e6302902',
$this->updater->getNewVersion()
);
}

public function test_throws_exception_on_empty_remote_version(): void
{
$this->expectException(HttpRequestException::class);
$this->expectExceptionMessage('Version request returned empty response');
$this->updater->getStrategy()->setVersionUrl('file://'.$this->files.'/empty.version');
$this->assertTrue($this->updater->hasUpdate());
}

public function test_throws_exception_on_invalid_remote_version(): void
{
$this->expectException(HttpRequestException::class);
$this->expectExceptionMessage('Version request returned incorrectly formatted response');
$this->updater->getStrategy()->setVersionUrl('file://'.$this->files.'/bad.version');
$this->assertTrue($this->updater->hasUpdate());
}

/**
* @runInSeparateProcess
*/
public function test_update_phar(): void
{
$this->createTestPharAndKey();
$this->assertEquals('old', $this->getPharOutput($this->tmp.'/old.phar'));

$updater = new Updater($this->tmp.'/old.phar', true, Updater::STRATEGY_SHA512);
$updater->getStrategy()->setPharUrl('file://'.$this->files.'/build/new.phar');
$updater->getStrategy()->setVersionUrl('file://'.$this->files.'/build/new.sha512.version');
$this->assertTrue($updater->update());
$this->assertEquals('new', $this->getPharOutput($this->tmp.'/old.phar'));
}

// Helpers

private function getPharOutput(string $path): string
{
return exec('php '.escapeshellarg($path));
}

private function deleteTempPhars(): void
{
@unlink($this->tmp.'/old.phar');
@unlink($this->tmp.'/old.phar.pubkey');
@unlink($this->tmp.'/old.phar.temp.pubkey');
@unlink($this->tmp.'/old-old.phar');
}

private function createTestPharAndKey(): void
{
copy($this->files.'/build/old.phar', $this->tmp.'/old.phar');
chmod($this->tmp.'/old.phar', 0755);
copy(
$this->files.'/build/old.phar.pubkey',
$this->tmp.'/old.phar.pubkey'
);
}
}
203 changes: 98 additions & 105 deletions tests/Humbug/Test/SelfUpdate/UpdaterTest.php

Large diffs are not rendered by default.

85 changes: 42 additions & 43 deletions tests/Humbug/Test/SelfUpdate/VersionParserTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
* @subpackage UnitTests
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/pharupdater/blob/master/LICENSE New BSD License
*/
@@ -16,123 +16,122 @@

class VersionParserTest extends TestCase
{

// Stable Versions

public function testShouldSelectNothingFromUnstablesIfStableRequested()
public function test_should_select_nothing_from_unstables_if_stable_requested(): void
{
$versions = array('1.0.0a', '1.0.0alpha', '1.0.0-dev', 'dev-1.0.0', '1.0.0b',
'1.0.0beta', '1.0.0rc', '1.0.0RC');
$versions = ['1.0.0a', '1.0.0alpha', '1.0.0-dev', 'dev-1.0.0', '1.0.0b',
'1.0.0beta', '1.0.0rc', '1.0.0RC', ];
$parser = new VersionParser($versions);
$this->assertSame(false, $parser->getMostRecentStable());
$this->assertFalse($parser->getMostRecentStable());
}

public function testShouldSelectMostRecentVersionFromStandardSelection()
public function test_should_select_most_recent_version_from_standard_selection(): void
{
$versions = array('1.0.0', '1.0.1', '1.1.0');
$versions = ['1.0.0', '1.0.1', '1.1.0'];
$parser = new VersionParser($versions);
$this->assertSame('1.1.0', $parser->getMostRecentStable());
}

public function testShouldSelectMostRecentVersionFromMixedSelection()
public function test_should_select_most_recent_version_from_mixed_selection(): void
{
$versions = array('1.0.0', '1.0.1', '1.1.0', '1.2.0a', '1.2.0b', '1.1.0rc');
$versions = ['1.0.0', '1.0.1', '1.1.0', '1.2.0a', '1.2.0b', '1.1.0rc'];
$parser = new VersionParser($versions);
$this->assertSame('1.1.0', $parser->getMostRecentStable());
}

public function testShouldSelectMostRecentVersionFromPrefixedSelection()
public function test_should_select_most_recent_version_from_prefixed_selection(): void
{
$versions = array('v1.0.0', 'v1.0.1', 'v1.1.0');
$versions = ['v1.0.0', 'v1.0.1', 'v1.1.0'];
$parser = new VersionParser($versions);
$this->assertSame('v1.1.0', $parser->getMostRecentStable());
}

public function testShouldSelectMostRecentVersionFromPartlyPrefixedSelection()
public function test_should_select_most_recent_version_from_partly_prefixed_selection(): void
{
$versions = array('v1.0.0', 'v1.0.1', '1.1.0');
$versions = ['v1.0.0', 'v1.0.1', '1.1.0'];
$parser = new VersionParser($versions);
$this->assertSame('1.1.0', $parser->getMostRecentStable());
}

public function testShouldSelectMostRecentVersionFromPatchLevels()
public function test_should_select_most_recent_version_from_patch_levels(): void
{
$versions = array('1.0.0', '1.0.0-pl2', '1.0.0-pl3', '1.0.0-pl1');
$versions = ['1.0.0', '1.0.0-pl2', '1.0.0-pl3', '1.0.0-pl1'];
$parser = new VersionParser($versions);
$this->assertSame('1.0.0-pl3', $parser->getMostRecentStable());
}

public function testShouldSelectMostRecentVersionFromPatchLevels2()
public function test_should_select_most_recent_version_from_patch_levels2(): void
{
$versions = array('1.0.0', '1.0.0pl2', '1.0.0pl3', '1.0.0pl1');
$versions = ['1.0.0', '1.0.0pl2', '1.0.0pl3', '1.0.0pl1'];
$parser = new VersionParser($versions);
$this->assertSame('1.0.0pl3', $parser->getMostRecentStable());
}

// Unstable

public function testShouldSelectNothingFromUnstablesIfUnstableRequested()
public function test_should_select_nothing_from_unstables_if_unstable_requested(): void
{
$versions = array('1.0.0', '1.0.1', '1.1.0');
$versions = ['1.0.0', '1.0.1', '1.1.0'];
$parser = new VersionParser($versions);
$this->assertSame(false, $parser->getMostRecentUnstable());
$this->assertFalse($parser->getMostRecentUnstable());
}

public function testShouldSelectNothingFromStablesOrDevsIfUnstableRequested()
public function test_should_select_nothing_from_stables_or_devs_if_unstable_requested(): void
{
$versions = array('1.0.0', '1.0.1', '1.1.0-dev', 'dev-1.1.1');
$versions = ['1.0.0', '1.0.1', '1.1.0-dev', 'dev-1.1.1'];
$parser = new VersionParser($versions);
$this->assertSame(false, $parser->getMostRecentUnstable());
$this->assertFalse($parser->getMostRecentUnstable());
}

public function testShouldSelectMostRecentUnstableVersionFromStandardSelection()
public function test_should_select_most_recent_unstable_version_from_standard_selection(): void
{
$versions = array('1.0.0a', '1.0.0alpha', '1.0.0-dev', 'dev-1.0.0', '1.0.0b',
'1.0.0beta', '1.0.0rc', '1.0.0RC');
$versions = ['1.0.0a', '1.0.0alpha', '1.0.0-dev', 'dev-1.0.0', '1.0.0b',
'1.0.0beta', '1.0.0rc', '1.0.0RC', ];
$parser = new VersionParser($versions);
$this->assertSame('1.0.0rc', $parser->getMostRecentUnstable());
}

public function testShouldSelectMostRecentUnstableVersionFromMixedSelection()
public function test_should_select_most_recent_unstable_version_from_mixed_selection(): void
{
$versions = array('1.0.0', '1.0.1', '1.1.0', '1.2.0a', '1.2.0b', '1.1.0rc');
$versions = ['1.0.0', '1.0.1', '1.1.0', '1.2.0a', '1.2.0b', '1.1.0rc'];
$parser = new VersionParser($versions);
$this->assertSame('1.2.0b', $parser->getMostRecentUnstable());
}

public function testShouldSelectMostRecentUnstableVersionFromPrefixedSelection()
public function test_should_select_most_recent_unstable_version_from_prefixed_selection(): void
{
$versions = array('v1.0.0b', 'v1.0.1', 'v1.1.0');
$versions = ['v1.0.0b', 'v1.0.1', 'v1.1.0'];
$parser = new VersionParser($versions);
$this->assertSame('v1.0.0b', $parser->getMostRecentUnstable());
}

public function testShouldSelectMostRecentUnstableVersionFromPartlyPrefixedSelection()
public function test_should_select_most_recent_unstable_version_from_partly_prefixed_selection(): void
{
$versions = array('v1.0.0b', 'v1.0.0a', '1.1.0a');
$versions = ['v1.0.0b', 'v1.0.0a', '1.1.0a'];
$parser = new VersionParser($versions);
$this->assertSame('1.1.0a', $parser->getMostRecentUnstable());
}

public function testShouldSelectMostRecentUnstableFromVaryingNumeralCounts()
public function test_should_select_most_recent_unstable_from_varying_numeral_counts(): void
{
$versions = array('1.0-dev', '1.0.0-alpha1');
$versions = ['1.0-dev', '1.0.0-alpha1'];
$parser = new VersionParser($versions);
$this->assertSame('1.0.0-alpha1', $parser->getMostRecentUnstable());
}

// All versions (ignoring stability)

public function testShouldSelectMostRecentIgnoringStabilityExceptDevFromPrefixedSelection()
public function test_should_select_most_recent_ignoring_stability_except_dev_from_prefixed_selection(): void
{
$versions = array('v1.0.0b', 'v1.0.1', 'v1.1.0a', 'v1.2.0-dev');
$versions = ['v1.0.0b', 'v1.0.1', 'v1.1.0a', 'v1.2.0-dev'];
$parser = new VersionParser($versions);
$this->assertSame('v1.1.0a', $parser->getMostRecentAll());
}

// Basic Version Category Checks

public function testIsStable()
public function test_is_stable(): void
{
$parser = new VersionParser;
$this->assertTrue($parser->isStable('1.0.0'));
@@ -141,7 +140,7 @@ public function testIsStable()
$this->assertFalse($parser->isStable('1.0.0-alpha1-5-g5b46ad8'));
}

public function testIsPreRelease()
public function test_is_pre_release(): void
{
$parser = new VersionParser;
$this->assertFalse($parser->isPreRelease('1.0.0'));
@@ -150,7 +149,7 @@ public function testIsPreRelease()
$this->assertFalse($parser->isPreRelease('1.0.0-alpha1-5-g5b46ad8'));
}

public function testIsUnstable()
public function test_is_unstable(): void
{
$parser = new VersionParser;
$this->assertFalse($parser->isUnstable('1.0.0'));
@@ -159,7 +158,7 @@ public function testIsUnstable()
$this->assertTrue($parser->isUnstable('1.0.0-alpha1-5-g5b46ad8'));
}

public function testIsDevelopment()
public function test_is_development(): void
{
$parser = new VersionParser;
$this->assertFalse($parser->isDevelopment('1.0.0'));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b8a705a7430e69f23594c4bf58e8110d0e00e2fe0eb88cfdb5980a825b5734dc4c54e4cebba44e0424b1a79303745b8fb662d65eb34b35da51fd3347e6302902 new.phar
1 change: 1 addition & 0 deletions tests/Humbug/Test/SelfUpdate/_files/build/src/new/run.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php

echo 'new';
1 change: 1 addition & 0 deletions tests/Humbug/Test/SelfUpdate/_files/build/src/old/run.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php

echo 'old';
1 change: 1 addition & 0 deletions tests/Humbug/Test/SelfUpdate/_files/good.sha512.version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b8a705a7430e69f23594c4bf58e8110d0e00e2fe0eb88cfdb5980a825b5734dc4c54e4cebba44e0424b1a79303745b8fb662d65eb34b35da51fd3347e6302902 build/humbug.phar
11 changes: 5 additions & 6 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php

/**
* Humbug
* Humbug.
*
* @category Humbug
* @package Humbug
*
* @copyright Copyright (c) 2015 Pádraic Brady (http://blog.astrumfutura.com)
* @license https://github.com/padraic/phar-updater/blob/master/LICENSE New BSD License
*/

error_reporting(E_ALL);

if (function_exists('date_default_timezone_set')
&& function_exists('date_default_timezone_get')) {
if (function_exists('date_default_timezone_set') && function_exists('date_default_timezone_get')) {
date_default_timezone_set(@date_default_timezone_get());
}

require __DIR__ . '/../vendor/autoload.php';
require __DIR__.'/../vendor/autoload.php';