Skip to content

Commit

Permalink
Add support for PHP 8, Guzzle 7, Symfony 6, and PHP CS Fixer 2.19 (#28)
Browse files Browse the repository at this point in the history
* Update CHANGELOG

* Switch from travis-ci.org to travis-ci.com

* Bump branch-alias to 2.4

* Support PHP 8, Guzzle 7, and Symfony 6

* Replace phpunit with simple-phpunit

Added:
- Support for symfony/phpunit-bridge v6+

Removed:
- Dependency on phpunit/phpunit (provided by symfony/phpunit-bridge)

Changed:
- Replaced `@expectedException` annotations with equivalent methods.

* Require PHP CS Fixer 2.19

Changed:
- Initialization of `Config` object to match requirements for 3.0.
- Renamed file to match requirements for 3.0.
  • Loading branch information
mcaskill authored Jul 22, 2021
1 parent d5380ac commit 189522e
Show file tree
Hide file tree
Showing 13 changed files with 146 additions and 118 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.php_cs
.php_cs.cache
.phpunit.result.cache
composer.lock
phpunit.xml
vendor
2 changes: 1 addition & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);

$config = PhpCsFixer\Config::create()
$config = (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:
- php: 7.2
- php: 7.3
- php: 7.4
- php: 8.0
- php: nightly
allow_failures:
- php: nightly

cache:
directories:
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
# Changelog

## 2.4.0 (TBD)

* Add support for PHP 8+
* Add support for Guzzle 7+
* Add support for Symfony 6+
* Modernize tests

## 2.3.0 (2020-03-23)

* Bump minimum required PHP version to 5.6
* Add support for PHP 7.2+
* Drop support for HHVM (composer/composer#8127)
* Update [Bitly API](https://bitly.is/v4ing) version to 4
* Update [phpunit/phpunit](https://packagist.org/packages/phpunit/phpunit) version to ^5.7
* Update [symfony/phpunit-bridge](https://packagist.org/packages/symfony/phpunit-bridge) version to ^5.0
* Replace [fabpot/php-cs-fixer](https://packagist.org/packages/fabpot/php-cs-fixer) with [friendsofphp/php-cs-fixer v2.16](https://packagist.org/packages/friendsofphp/php-cs-fixer) version ^2.16

## 2.2.1 (2018-10-09)

* Update [symfony/console](https://github.com/symfony/console) version to ^4.1 (See [#14](https://github.com/mremi/UrlShortener/issues/14))

## 2.2.0 (2018-09-24)
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ install:
composer install

test:
@if [ ! -f vendor/bin/phpunit ]; then make install; fi
vendor/bin/phpunit
@if [ ! -f vendor/bin/simple-phpunit ]; then make install; fi
SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit

update:
composer update
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This library allows you to shorten a URL, reverse is also possible.

[![SensioLabsInsight](https://insight.sensiolabs.com/projects/c4e06c9d-547c-47bb-8abb-fccc68b7df7a/big.png)](https://insight.sensiolabs.com/projects/c4e06c9d-547c-47bb-8abb-fccc68b7df7a)

[![Build Status](https://api.travis-ci.org/mremi/UrlShortener.png?branch=master)](https://travis-ci.org/mremi/UrlShortener)
[![Build Status](https://api.travis-ci.com/mremi/UrlShortener.png?branch=master)](https://travis-ci.org/mremi/UrlShortener)
[![Total Downloads](https://poser.pugx.org/mremi/url-shortener/downloads.png)](https://packagist.org/packages/mremi/url-shortener)
[![Latest Stable Version](https://poser.pugx.org/mremi/url-shortener/v/stable.png)](https://packagist.org/packages/mremi/url-shortener)
[![Scrutinizer Quality Score](https://scrutinizer-ci.com/g/mremi/UrlShortener/badges/quality-score.png?s=34c4ba6b0cd272673fa121c32a63e1ce668b9b2a)](https://scrutinizer-ci.com/g/mremi/UrlShortener/)
Expand Down
17 changes: 8 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "mremi/url-shortener",
"type": "library",
"description": "A PHP5 library using API to shorten/expand URL",
"keywords": ["url", "shortener", "api"],
"description": "A PHP5/PHP7/PHP8 library using API to shorten/expand URL",
"keywords": [ "url", "shortener", "api" ],
"homepage": "https://github.com/mremi/UrlShortener",
"license": "MIT",
"authors": [
Expand All @@ -12,14 +12,13 @@
}
],
"require": {
"php": "^5.6 || ^7.0",
"guzzlehttp/guzzle": "^6.0",
"symfony/console": "^3.1 || ^4.1 || ^v5.0"
"php": "^5.6 || ^7.0 || ^8.0",
"guzzlehttp/guzzle": "^6.0 || ^7.0",
"symfony/console": "^3.1 || ^4.1 || ^5.0 || ^6.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "~5.7 || ~6.5 || ~7.5",
"symfony/phpunit-bridge": "^5.0"
"friendsofphp/php-cs-fixer": "^2.19",
"symfony/phpunit-bridge": "^5.0 || ^6.0"
},
"autoload": {
"psr-4": {
Expand All @@ -33,7 +32,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "2.3-dev"
"dev-master": "2.4-dev"
}
}
}
43 changes: 22 additions & 21 deletions tests/Mremi/UrlShortener/Tests/Provider/Baidu/BaiduProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Mremi\UrlShortener\Tests\Provider\Baidu;

use GuzzleHttp\ClientInterface;
use Mremi\UrlShortener\Exception\InvalidApiResponseException;
use Mremi\UrlShortener\Model\LinkInterface;
use Mremi\UrlShortener\Provider\Baidu\BaiduProvider;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -50,38 +51,38 @@ protected function tearDown()

/**
* Tests the shorten method throws exception if Baidu returns a string.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Baidu response is probably mal-formed because cannot be json-decoded.
*/
public function testShortenThrowsExceptionIfResponseApiIsString()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Baidu response is probably mal-formed because cannot be json-decoded.');

$this->mockClient($this->getMockResponseAsString(), 'post');

$this->provider->shorten($this->getBaseMockLink());
}

/**
* Tests the shorten method throws exception if Baidu returns an error response.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Baidu returned code error message "-1: long url is not valid
*/
public function testShortenThrowsExceptionIfApiResponseIsError()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Baidu returned code error message "-1: long url is not valid');

$this->mockClient($this->getMockResponseWithError(), 'post');

$this->provider->shorten($this->getBaseMockLink());
}

/**
* Tests the shorten method throws exception if Baidu returns a response with no short url.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Baidu returned code error message "-1: unsafe url
*/
public function testShortenThrowsExceptionIfApiResponseHasNoShortUrl()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Baidu returned code error message "-1: unsafe url');

$this->mockClient($this->getMockResponseWithNoShortUrl(), 'post');

$this->provider->shorten($this->getBaseMockLink());
Expand Down Expand Up @@ -127,51 +128,51 @@ public function testShortenWithValidApiResponse()

/**
* Tests the expand method throws exception if Baidu returns a string.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Baidu response is probably mal-formed because cannot be json-decoded.
*/
public function testExpandThrowsExceptionIfResponseApiIsString()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Baidu response is probably mal-formed because cannot be json-decoded.');

$this->mockClient($this->getMockResponseAsString(), 'post');

$this->provider->expand($this->getBaseMockLink());
}

/**
* Tests the expand method throws exception if Baidu returns an error response.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Baidu returned code error message "-1: long url is not valid
*/
public function testExpandThrowsExceptionIfApiResponseIsError()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Baidu returned code error message "-1: long url is not valid');

$this->mockClient($this->getMockResponseWithError(), 'post');

$this->provider->expand($this->getBaseMockLink());
}

/**
* Tests the expand method throws exception if Baidu returns a response with no longUrl.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Baidu returned code error message "-2: short url dose not exist
*/
public function testExpandThrowsExceptionIfApiResponseHasNoLongUrl()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Baidu returned code error message "-2: short url dose not exist');

$this->mockClient($this->getMockResponseWithNoLongUrl(), 'post');

$this->provider->expand($this->getBaseMockLink());
}

/**
* Tests the expand method throws exception if Baidu returns a response with no status.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Property "Code" does not exist within Baidu response.
*/
public function testExpandThrowsExceptionIfApiResponseHasNoStatus()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Property "Code" does not exist within Baidu response.');

$response = $this->getBaseMockResponse();

$apiRawResponse = <<<'JSON'
Expand Down
25 changes: 13 additions & 12 deletions tests/Mremi/UrlShortener/Tests/Provider/Bitly/BitlyProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Mremi\UrlShortener\Tests\Provider\Bitly;

use GuzzleHttp\ClientInterface;
use Mremi\UrlShortener\Exception\InvalidApiResponseException;
use Mremi\UrlShortener\Model\LinkInterface;
use Mremi\UrlShortener\Provider\Bitly\AuthenticationInterface;
use Mremi\UrlShortener\Provider\Bitly\BitlyProvider;
Expand All @@ -33,25 +34,25 @@ class BitlyProviderTest extends TestCase

/**
* Tests the shorten method throws exception if Bit.ly returns a string.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Bit.ly response is probably mal-formed because cannot be json-decoded.
*/
public function testShortenThrowsExceptionIfApiResponseIsString()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Bit.ly response is probably mal-formed because cannot be json-decoded.');

$this->mockClient($this->getMockResponseAsString());

$this->provider->shorten($this->getBaseMockLink());
}

/**
* Tests the shorten method throws exception if Bit.ly returns an invalid status code.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Bit.ly returned status code "404" with message "NOT_FOUND"
*/
public function testShortenThrowsExceptionIfApiResponseHasInvalidStatusCode()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Bit.ly returned status code "404" with message "NOT_FOUND"');

$this->mockClient($this->getMockResponseWithInvalidStatusCode());

$this->provider->shorten($this->getBaseMockLink());
Expand Down Expand Up @@ -107,25 +108,25 @@ public function testShortenWithValidApiResponse()

/**
* Tests the expand method throws exception if Bit.ly returns a string.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Bit.ly response is probably mal-formed because cannot be json-decoded.
*/
public function testExpandThrowsExceptionIfApiResponseIsString()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Bit.ly response is probably mal-formed because cannot be json-decoded.');

$this->mockClient($this->getMockResponseAsString());

$this->provider->expand($this->getBaseMockLink());
}

/**
* Tests the expand method throws exception if Bit.ly returns an invalid status code.
*
* @expectedException \Mremi\UrlShortener\Exception\InvalidApiResponseException
* @expectedExceptionMessage Bit.ly returned status code "404" with message "NOT_FOUND"
*/
public function testExpandThrowsExceptionIfApiResponseHasInvalidStatusCode()
{
$this->expectException(InvalidApiResponseException::class);
$this->expectExceptionMessage('Bit.ly returned status code "404" with message "NOT_FOUND"');

$this->mockClient($this->getMockResponseWithInvalidStatusCode());

$this->provider->expand($this->getBaseMockLink());
Expand Down
7 changes: 4 additions & 3 deletions tests/Mremi/UrlShortener/Tests/Provider/ChainProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Mremi\UrlShortener\Provider\Sina\SinaProvider;
use Mremi\UrlShortener\Provider\Wechat\WechatProvider;
use PHPUnit\Framework\TestCase;
use RuntimeException;

/**
* Tests ChainProvider class.
Expand All @@ -28,12 +29,12 @@ class ChainProviderTest extends TestCase
{
/**
* Tests that an unknown provider throws an exception.
*
* @expectedException \RuntimeException
* @expectedExceptionMessage Unable to retrieve the provider named: "foo"
*/
public function testUnknownProvider()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Unable to retrieve the provider named: "foo"');

$chainProvider = new ChainProvider();
$chainProvider->getProvider('foo');
}
Expand Down
Loading

0 comments on commit 189522e

Please sign in to comment.