Skip to content

Commit

Permalink
Merge pull request #129 from norkunas/upd
Browse files Browse the repository at this point in the history
Allow Symfony 5.0 and improve travis + tests compatibility
  • Loading branch information
norkunas authored Nov 26, 2019
2 parents 6359f32 + 9083195 commit 5ebc2ca
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 89 deletions.
18 changes: 12 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@ matrix:
fast_finish: true
include:
# Test minimum supported dependencies with the latest and oldest PHP version
- php: 5.6
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.2
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"
- php: 7.3
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest"

# Test the latest stable release
- php: 7.1
- php: 7.2
- php: 7.3
env: COVERAGE=true PHPUNIT_FLAGS="-v --coverage-text --coverage-clover=build/coverage.xml"

# Test forcing symfony components version
- php: 5.6
- php: 7.1
env: DEPENDENCIES="dunglas/symfony-lock:^3"
- php: 7.2
env: SYMFONY_VERSION=3.4.*
- php: 7.3
env: SYMFONY_VERSION=4.3.*
- php: 7.3
env: DEPENDENCIES="dunglas/symfony-lock:^4"
env: SYMFONY_VERSION=4.4.*
- php: 7.3
env: SYMFONY_VERSION=5.0.*

# Latest commit to master
- php: 7.3
env: STABILITY="dev"
Expand All @@ -42,7 +48,7 @@ matrix:
before_install:
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -v "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi

install:
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
}
],
"require": {
"php": ">=5.6|>=7.1",
"php": "^7.1",
"ext-json": "*",
"php-http/client-common": "^1.9|^2.0",
"php-http/client-implementation": "^1.0",
"php-http/message": "^1.7",
"symfony/options-resolver": "^3.4|^4.0"
"symfony/options-resolver": "^3.4|^4.0|^5.0"
},
"require-dev": {
"php-http/guzzle6-adapter": "^1.1",
"symfony/phpunit-bridge": "^4.3"
"symfony/phpunit-bridge": "^5.0"
},
"autoload": {
"psr-4": { "OneSignal\\": "src/" }
Expand Down
4 changes: 3 additions & 1 deletion tests/OneSignal/Tests/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use OneSignal\Resolver\ResolverFactory;
use OneSignal\Resolver\ResolverInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

abstract class AbstractApiTest extends TestCase
{
use ConfigMockerTrait;
use SetUpTearDownTrait;

/**
* @var OneSignal
Expand All @@ -21,7 +23,7 @@ abstract class AbstractApiTest extends TestCase
*/
protected $resolverFactory;

public function setUp()
public function doSetUp()
{
$mockResolver = $this->createMock(ResolverInterface::class);
$mockResolver->method('resolve')->willReturnArgument(0);
Expand Down
7 changes: 5 additions & 2 deletions tests/OneSignal/Tests/AppsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace OneSignal\Tests;

use OneSignal\Apps;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class AppsTest extends AbstractApiTest
{
use SetUpTearDownTrait;

/**
* @var Apps
*/
private $apps;

public function setUp()
public function doSetUp()
{
parent::setUp();
parent::doSetUp();

$this->apps = new Apps($this->api, $this->resolverFactory);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/OneSignal/Tests/ConfigMockerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace OneSignal\Tests;

use OneSignal\Config;
use PHPUnit\Framework\MockObject\MockObject;

trait ConfigMockerTrait
{
public function createMockedConfig()
{
/** @var MockObject $config */
$config = $this->createMock(Config::class);
$config->method('getApplicationId')->willReturn('fakeApplicationId');
$config->method('getApplicationAuthKey')->willReturn('fakeApplicationAuthKey');
Expand Down
5 changes: 4 additions & 1 deletion tests/OneSignal/Tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@

use OneSignal\Config;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class ConfigTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var Config
*/
private $config;

public function setUp()
public function doSetUp()
{
$this->config = new Config();
}
Expand Down
7 changes: 5 additions & 2 deletions tests/OneSignal/Tests/DevicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace OneSignal\Tests;

use OneSignal\Devices;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class DevicesTest extends AbstractApiTest
{
use SetUpTearDownTrait;

/**
* @var Devices;
*/
private $devices;

public function setUp()
public function doSetUp()
{
parent::setUp();
parent::doSetUp();

$this->devices = new Devices($this->api, $this->resolverFactory);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/OneSignal/Tests/NotificationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace OneSignal\Tests;

use OneSignal\Notifications;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class NotificationsTest extends AbstractApiTest
{
use SetUpTearDownTrait;

/**
* @var Notifications
*/
private $notifications;

public function setUp()
public function doSetUp()
{
parent::setUp();
parent::doSetUp();

$this->notifications = new Notifications($this->api, $this->resolverFactory);
}
Expand Down
21 changes: 11 additions & 10 deletions tests/OneSignal/Tests/OneSignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
use OneSignal\Apps;
use OneSignal\Config;
use OneSignal\Devices;
use OneSignal\Exception\OneSignalException;
use OneSignal\Notifications;
use OneSignal\OneSignal;
use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;

class OneSignalTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var OneSignal
*/
private $api;

public function setUp()
public function doSetUp()
{
$this->api = new OneSignal();
}
Expand All @@ -36,11 +40,10 @@ public function testIfInstanceIsCached()
$this->assertInstanceOf(Apps::class, $this->api->apps);
}

/**
* @expectedException \OneSignal\Exception\OneSignalException
*/
public function testBadInstance()
{
$this->expectException(OneSignalException::class);

$this->api->unknownInstance;
}

Expand Down Expand Up @@ -86,23 +89,21 @@ public function testRequestParseJSONResponse()
$this->assertEquals($expectedData, $this->api->request('fakeMethod', 'fakeURI'));
}

/**
* @expectedException \OneSignal\Exception\OneSignalException
*/
public function testRequestHandleExceptions()
{
$this->expectException(OneSignalException::class);

$client = $this->createMock(HttpMethodsClient::class);
$client->method('send')->will($this->throwException(new \Exception()));

$this->api->setClient($client);
$this->api->request('DummyMethod', 'DummyURI');
}

/**
* @expectedException \OneSignal\Exception\OneSignalException
*/
public function testMagicGetHandleRequest()
{
$this->expectException(OneSignalException::class);

$this->api->unexistingService;
}
}
21 changes: 13 additions & 8 deletions tests/OneSignal/Tests/Resolver/AppResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

use OneSignal\Resolver\AppResolver;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;

class AppResolverTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var AppResolver
*/
private $appResolver;

public function setUp()
public function doSetUp()
{
$this->appResolver = new AppResolver();
}
Expand Down Expand Up @@ -47,11 +53,10 @@ public function testResolveWithValidValues()
$this->assertEquals($expectedData, $this->appResolver->resolve($expectedData));
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
*/
public function testResolveWithMissingRequiredValue()
{
$this->expectException(MissingOptionsException::class);

$this->appResolver->resolve([]);
}

Expand Down Expand Up @@ -85,22 +90,22 @@ public function wrongValueTypesProvider()

/**
* @dataProvider wrongValueTypesProvider
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveWithWrongValueTypes($wrongOption)
{
$this->expectException(InvalidOptionsException::class);

$requiredOptions = [
'name' => 'fakeName',
];

$this->appResolver->resolve(array_merge($requiredOptions, $wrongOption));
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testResolveWithWrongOption()
{
$this->expectException(UndefinedOptionsException::class);

$this->appResolver->resolve(['wrongOption' => 'wrongValue']);
}
}
21 changes: 13 additions & 8 deletions tests/OneSignal/Tests/Resolver/DeviceFocusResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

use OneSignal\Resolver\DeviceFocusResolver;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;

class DeviceFocusResolverTest extends TestCase
{
use SetUpTearDownTrait;

/**
* @var DeviceFocusResolver
*/
private $deviceFocusResolver;

public function setUp()
public function doSetUp()
{
$this->deviceFocusResolver = new DeviceFocusResolver();
}
Expand All @@ -37,11 +43,10 @@ public function testResolveDefaultValues()
$this->assertEquals($expectedData, $this->deviceFocusResolver->resolve(['active_time' => 23]));
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException
*/
public function testResolveWithMissingRequiredValue()
{
$this->expectException(MissingOptionsException::class);

$this->deviceFocusResolver->resolve([]);
}

Expand All @@ -55,22 +60,22 @@ public function wrongValueTypesProvider()

/**
* @dataProvider wrongValueTypesProvider
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/
public function testResolveWithWrongValueTypes($wrongOption)
{
$this->expectException(InvalidOptionsException::class);

$requiredOptions = [
'active_time' => 234,
];

$this->deviceFocusResolver->resolve(array_merge($requiredOptions, $wrongOption));
}

/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testResolveWithWrongOption()
{
$this->expectException(UndefinedOptionsException::class);

$this->deviceFocusResolver->resolve(['active_time' => 23, 'wrongOption' => 'wrongValue']);
}
}
Loading

0 comments on commit 5ebc2ca

Please sign in to comment.