Skip to content

Commit

Permalink
Upgrade phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Jul 22, 2019
1 parent 7a7515b commit 52fb9ab
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 41 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"symfony/options-resolver": "^3.4|^4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36",
"phpunit/phpunit": "^7.5",
"php-http/guzzle6-adapter": "^1.1"
},
"autoload": {
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
Expand Down
28 changes: 12 additions & 16 deletions tests/OneSignal/Tests/AbstractApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,28 @@ abstract class AbstractApiTest extends TestCase

public function setUp()
{
/* Mock resolverFactory */
$mockResolver = $this->getMockBuilder(ResolverInterface::class)->getMock();
$mockResolver->method('resolve')->will($this->returnArgument(0));

$resolverFactory = $this->getMockBuilder(ResolverFactory::class)
->disableOriginalConstructor()
->getMock();
foreach (get_class_methods($resolverFactory) as $method) {
$mockResolver = $this->createMock(ResolverInterface::class);
$mockResolver->method('resolve')->willReturnArgument(0);

$resolverFactory = $this->createMock(ResolverFactory::class);
$resolverMethods = array_filter(get_class_methods($resolverFactory), function ($method) {
return strpos($method, 'create') === 0;
});
foreach ($resolverMethods as $method) {
$resolverFactory->method($method)->willReturn($mockResolver);
}

$this->resolverFactory = $resolverFactory;

/* Mock api */
$api = $this->getMockBuilder(OneSignal::class)->getMock();
$api->method('request')->will($this->returnCallback([$this, 'requestCallback']));
$api = $this->createMock(OneSignal::class);
$api->method('request')->willReturnCallback([$this, 'requestCallback']);
$api->method('getConfig')->willReturn($this->createMockedConfig());
$this->api = $api;
}

public function requestCallback()
{
$args = func_get_args();
$method = $args[0];
$url = $args[1];
$header = $args[2];
$body = $args[3];
list($method, $url, $header, $body) = func_get_args();

return [$method, $url, $header, $body];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/OneSignal/Tests/ConfigMockerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait ConfigMockerTrait
{
public function createMockedConfig()
{
$config = $this->getMockBuilder(Config::class)->getMock();
$config = $this->createMock(Config::class);
$config->method('getApplicationId')->willReturn('fakeApplicationId');
$config->method('getApplicationAuthKey')->willReturn('fakeApplicationAuthKey');
$config->method('getUserAuthKey')->willReturn('fakeUserAuthKey');
Expand Down
39 changes: 17 additions & 22 deletions tests/OneSignal/Tests/OneSignalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace OneSignal\Tests;

use Http\Client\Common\HttpMethodsClient;
use OneSignal\Apps;
use OneSignal\Config;
use OneSignal\Devices;
use OneSignal\Notifications;
use OneSignal\OneSignal;
use Psr\Http\Message\ResponseInterface;
use PHPUnit\Framework\TestCase;
Expand All @@ -21,15 +25,15 @@ public function setUp()

public function testInstances()
{
$this->assertInstanceOf('OneSignal\Apps', $this->api->apps);
$this->assertInstanceOf('OneSignal\Devices', $this->api->devices);
$this->assertInstanceOf('OneSignal\Notifications', $this->api->notifications);
$this->assertInstanceOf(Apps::class, $this->api->apps);
$this->assertInstanceOf(Devices::class, $this->api->devices);
$this->assertInstanceOf(Notifications::class, $this->api->notifications);
}

public function testIfInstanceIsCached()
{
$this->assertInstanceOf('OneSignal\Apps', $this->api->apps);
$this->assertInstanceOf('OneSignal\Apps', $this->api->apps);
$this->assertInstanceOf(Apps::class, $this->api->apps);
$this->assertInstanceOf(Apps::class, $this->api->apps);
}

/**
Expand All @@ -42,31 +46,27 @@ public function testBadInstance()

public function testClientSetFromConstructor()
{
$client = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient')
->disableOriginalConstructor()
->getMock();
$client = $this->createMock(HttpMethodsClient::class);

$api = new OneSignal(null, $client);

$this->assertInstanceOf('Http\Client\Common\HttpMethodsClient', $api->getClient());
$this->assertInstanceOf(HttpMethodsClient::class, $api->getClient());
}

public function testClientWithSetterAndGetter()
{
$client = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient')
->disableOriginalConstructor()
->getMock();
$client = $this->createMock(HttpMethodsClient::class);

$this->api->setClient($client);

$this->assertInstanceOf('Http\Client\Common\HttpMethodsClient', $this->api->getClient());
$this->assertInstanceOf(HttpMethodsClient::class, $this->api->getClient());
}

public function testConfigWithSetterAndGetter()
{
$this->api->setConfig(new Config());

$this->assertInstanceOf('OneSignal\Config', $this->api->getConfig());
$this->assertInstanceOf(Config::class, $this->api->getConfig());
}

public function testRequestParseJSONResponse()
Expand All @@ -75,13 +75,10 @@ public function testRequestParseJSONResponse()
'content' => 'jsondata',
];

$fakeResponse = $this->getMockBuilder(ResponseInterface::class)
->getMock();
$fakeResponse = $this->createMock(ResponseInterface::class);
$fakeResponse->method('getBody')->willReturn(json_encode($expectedData));

$client = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient')
->disableOriginalConstructor()
->getMock();
$client = $this->createMock(HttpMethodsClient::class);
$client->method('send')->willReturn($fakeResponse);

$this->api->setClient($client);
Expand All @@ -94,9 +91,7 @@ public function testRequestParseJSONResponse()
*/
public function testRequestHandleExceptions()
{
$client = $this->getMockBuilder('Http\Client\Common\HttpMethodsClient')
->disableOriginalConstructor()
->getMock();
$client = $this->createMock(HttpMethodsClient::class);
$client->method('send')->will($this->throwException(new \Exception()));

$this->api->setClient($client);
Expand Down

0 comments on commit 52fb9ab

Please sign in to comment.