Skip to content

Commit 03e276c

Browse files
author
Romain Monteil
committed
Update PHPUnit, Travis and Scrutinizer configuration
1 parent caadb94 commit 03e276c

File tree

16 files changed

+155
-191
lines changed

16 files changed

+155
-191
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
/phpunit.xml.dist export-ignore
99
/.scrutinizer.yml export-ignore
1010
/tests export-ignore
11-
/docs export-ignore

.php_cs.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
$finder = PhpCsFixer\Finder::create()
44
->in(__DIR__ . '/src')
5+
->in(__DIR__ . '/tests')
56
;
67

78
return PhpCsFixer\Config::create()

.scrutinizer.yml

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,11 @@
1-
imports:
2-
- php
1+
filter:
2+
excluded_paths: [vendor/*, tests/*]
33

44
checks:
55
php:
66
code_rating: true
77
duplication: true
88

9-
filter:
10-
excluded_paths:
11-
- "tests/"
12-
dependency_paths:
13-
- "vendor/"
14-
159
tools:
16-
php_mess_detector: true
17-
php_cpd:
18-
excluded_dirs:
19-
- tests/
20-
php_loc:
21-
excluded_dirs:
22-
- tests/
23-
php_pdepend:
24-
excluded_dirs:
25-
2: tests/
26-
27-
build:
28-
nodes:
29-
analysis:
30-
project_setup:
31-
override: true
32-
tests:
33-
override: [php-scrutinizer-run]
34-
coverage:
35-
tests:
36-
override:
37-
- command: 'vendor/bin/phpunit --coverage-clover=clover.xml'
38-
coverage:
39-
file: 'clover.xml'
40-
format: 'clover'
41-
environment:
42-
php:
43-
version: 7.1
10+
external_code_coverage:
11+
timeout: 1800 # Timeout in seconds.

.travis.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
11
language: php
22

3-
sudo: false
4-
53
cache:
64
directories:
7-
- $HOME/.composer/cache/files
5+
- $HOME/.composer/cache
86

97
php:
108
- 7.1
119
- 7.2
1210
- 7.3
1311
- 7.4
1412

15-
env:
16-
global:
17-
- secure: j+1g/twymlVnvpQlsdS+82IY3xR8GIBB7m8bEmpYP6J1ketRToJWANDre6Xb/33JHEzekcr5Kt0F2UDkNzR5rNbviHqYH4EyHA7VZTikqSSelY+lZF7qo1xTyGRnCJZV6c2bri/rPVSjw1FYngNFh5FGCh7PmpzzeQZkhyCG3Cs=
18-
1913
matrix:
2014
fast_finish: true
15+
include:
16+
# Run test with code coverage
17+
- php: 7.1
18+
env: COVERAGE=true
2119

2220
before_install:
2321
- composer self-update
24-
- if [ "$GITHUB_COMPOSER_AUTH" ]; then composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH; fi
2522

2623
install:
27-
- composer install --prefer-dist --no-interaction
28-
29-
before_script:
30-
- mkdir -p build/logs
24+
- composer update --prefer-dist --prefer-stable --no-interaction
3125

3226
script:
33-
- vendor/bin/php-cs-fixer fix --diff --dry-run
3427
- vendor/bin/phpstan --level=max --memory-limit="-1" --no-progress analyze
35-
- vendor/bin/phpunit --stderr --coverage-clover build/coverage/xml
28+
- vendor/bin/php-cs-fixer fix --diff --dry-run
29+
- vendor/bin/phpunit --stderr --coverage-clover=build/coverage.xml
30+
31+
after_success:
32+
- if [[ $COVERAGE = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi
33+
- if [[ $COVERAGE = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi
3634

3735
notifications:
3836
email: false

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@
3434
},
3535
"autoload": {
3636
"psr-4": {
37-
"Kerox\\Fcm\\": "src"
37+
"Kerox\\Fcm\\": "src/"
3838
}
3939
},
4040
"autoload-dev": {
4141
"psr-4": {
42-
"Kerox\\Fcm\\Test\\": "tests"
42+
"Tests\\Kerox\\Fcm\\": "tests/"
4343
}
4444
},
4545
"scripts": {
4646
"php-cs-fixer": "vendor/bin/php-cs-fixer fix --diff --verbose --config=.php_cs",
47-
"php-stan": "vendor/bin/phpstan --level=max --memory-limit=\"-1\" --no-progress analyze",
48-
"test": "vendor/bin/phpunit"
47+
"phpstan": "vendor/bin/phpstan --level=max --memory-limit=\"-1\" --no-progress analyze",
48+
"phpunit": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
4949
}
5050
}

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<phpunit processIsolation="false"
33
stopOnFailure="false"
4-
bootstrap="./tests/bootstrap.php">
4+
bootstrap="vendor/autoload.php">
55
<testsuites>
66
<testsuite name="Fcm Test Suite">
7-
<directory>./tests/TestCase</directory>
7+
<directory>./tests</directory>
88
</testsuite>
99
</testsuites>
1010

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
<?php
22

3-
namespace Kerox\Fcm\Test\TestCase\Api;
3+
declare(strict_types=1);
4+
5+
namespace Tests\Kerox\Fcm\Api;
46

57
use GuzzleHttp\Client;
68
use GuzzleHttp\Handler\MockHandler;
79
use GuzzleHttp\HandlerStack;
810
use GuzzleHttp\Psr7\Response;
911
use Kerox\Fcm\Api\Send;
1012
use Kerox\Fcm\Model\Message;
11-
use Kerox\Fcm\Test\TestCase\AbstractTestCase;
13+
use PHPUnit\Framework\TestCase;
1214

13-
class SendTest extends AbstractTestCase
15+
class SendTest extends TestCase
1416
{
15-
public function testSendMessage()
17+
public function testSendMessage(): void
1618
{
17-
$bodyResponse = file_get_contents(__DIR__ . '/../../Mocks/Response/Send/basic.json');
19+
$bodyResponse = file_get_contents(__DIR__ . '/../Mocks/Response/Send/basic.json');
1820
$mockedResponse = new MockHandler([
1921
new Response(200, [], $bodyResponse),
2022
]);
@@ -31,13 +33,13 @@ public function testSendMessage()
3133

3234
$response = $sendApi->message($message, true);
3335

34-
$this->assertEquals('projects/myproject-b5ae1/messages/0:1500415314455276%31bd1c9631bd1c96', $response->getName());
35-
$this->assertEquals('0:1500415314455276%31bd1c9631bd1c96', $response->getMessageId());
36+
$this->assertSame('projects/myproject-b5ae1/messages/0:1500415314455276%31bd1c9631bd1c96', $response->getName());
37+
$this->assertSame('0:1500415314455276%31bd1c9631bd1c96', $response->getMessageId());
3638
}
3739

38-
public function testSendMessageWithResponseError()
40+
public function testSendMessageWithResponseError(): void
3941
{
40-
$bodyResponse = file_get_contents(__DIR__ . '/../../Mocks/Response/Send/error.json');
42+
$bodyResponse = file_get_contents(__DIR__ . '/../Mocks/Response/Send/error.json');
4143
$mockedResponse = new MockHandler([
4244
new Response(200, [], $bodyResponse),
4345
]);
@@ -57,7 +59,7 @@ public function testSendMessageWithResponseError()
5759
$this->assertNull($response->getName());
5860
$this->assertNull($response->getMessageId());
5961
$this->assertTrue($response->hasError());
60-
$this->assertEquals('UNSPECIFIED_ERROR', $response->getErrorCode());
61-
$this->assertEquals('No more information is available about this error.', $response->getErrorMessage());
62+
$this->assertSame('UNSPECIFIED_ERROR', $response->getErrorCode());
63+
$this->assertSame('No more information is available about this error.', $response->getErrorMessage());
6264
}
6365
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<?php
22

3-
namespace Kerox\Fcm\Test\TestCase;
3+
declare(strict_types=1);
4+
5+
namespace Tests\Kerox\Fcm;
46

57
use Kerox\Fcm\Api\Send;
68
use Kerox\Fcm\Fcm;
9+
use PHPUnit\Framework\TestCase;
710

8-
class FcmTest extends AbstractTestCase
11+
class FcmTest extends TestCase
912
{
1013
/**
1114
* @var \Kerox\Fcm\Fcm
1215
*/
1316
protected $fcm;
1417

15-
public function setUp()
18+
public function setUp(): void
1619
{
1720
$this->fcm = new Fcm('4321dcba', 'abcd1234');
1821
}
@@ -22,7 +25,7 @@ public function testGetInstanceOfApi(): void
2225
$this->assertInstanceOf(Send::class, $this->fcm->send());
2326
}
2427

25-
public function tearDown()
28+
public function tearDown(): void
2629
{
2730
unset($this->fcm);
2831
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Kerox\Fcm\Model\Message;
6+
7+
use Kerox\Fcm\Model\Message\Condition;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ConditionTest extends TestCase
11+
{
12+
public function testConditionAndWithOnlyTopics(): void
13+
{
14+
$condition = (new Condition())->and('TopicA', 'TopicB', 'TopicC');
15+
16+
$this->assertSame("'TopicA' in topics && 'TopicB' in topics && 'TopicC' in topics", $condition);
17+
}
18+
19+
public function testConditionOrWithOnlyTopics(): void
20+
{
21+
$condition = (new Condition())->or('TopicA', 'TopicB', 'TopicC');
22+
23+
$this->assertSame("'TopicA' in topics || 'TopicB' in topics || 'TopicC' in topics", $condition);
24+
}
25+
26+
public function testConditionNotWithTopic(): void
27+
{
28+
$condition = (new Condition())->not('TopicA');
29+
30+
$this->assertSame("!('TopicA' in topics)", $condition);
31+
}
32+
33+
public function testConditionAndWithClosure(): void
34+
{
35+
$condition = (new Condition())->and('TopicA', static function () {
36+
return (new Condition())->or('TopicB', 'TopicC');
37+
});
38+
39+
$this->assertSame("'TopicA' in topics && ('TopicB' in topics || 'TopicC' in topics)", $condition);
40+
}
41+
42+
public function testConditionOrWithClosure(): void
43+
{
44+
$condition = (new Condition())->or('TopicA', static function () {
45+
return (new Condition())->and('TopicB', 'TopicC');
46+
});
47+
48+
$this->assertSame("'TopicA' in topics || ('TopicB' in topics && 'TopicC' in topics)", $condition);
49+
}
50+
51+
public function testConditionNotWithClosure(): void
52+
{
53+
$condition = (new Condition())->not(static function () {
54+
return (new Condition())->and('TopicA', 'TopicB');
55+
});
56+
57+
$this->assertSame("!('TopicA' in topics && 'TopicB' in topics)", $condition);
58+
}
59+
60+
public function testConditionWithMultipleClosure(): void
61+
{
62+
$condition = (new Condition())->and('TopicA', static function () {
63+
return (new Condition())->or('TopicB', static function () {
64+
return (new Condition())->and('TopicC', 'TopicD', static function () {
65+
return (new Condition())->not('TopicE');
66+
});
67+
});
68+
});
69+
70+
$this->assertSame("'TopicA' in topics && ('TopicB' in topics || ('TopicC' in topics && 'TopicD' in topics && (!('TopicE' in topics))))", $condition);
71+
}
72+
73+
public function testConditionAndWithInvalidTopics(): void
74+
{
75+
$this->expectException(\InvalidArgumentException::class);
76+
$this->expectExceptionMessage('"Topic A" is an invalid topic name.');
77+
78+
(new Condition())->and('Topic A', 'TopicB', 'TopicC');
79+
}
80+
}

tests/TestCase/Model/Message/Notification/AndroidNotificationTest.php renamed to tests/Model/Message/Notification/AndroidNotificationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
declare(strict_types=1);
44

5-
namespace Kerox\Fcm\Test\TestCase\Model\Message\Notification;
5+
namespace Tests\Kerox\Fcm\Model\Message\Notification;
66

77
use Kerox\Fcm\Model\Message\Notification\AndroidNotification\Color;
88
use Kerox\Fcm\Model\Message\Notification\AndroidNotification\LightSettings;
9-
use Kerox\Fcm\Test\TestCase\AbstractTestCase;
9+
use PHPUnit\Framework\TestCase;
1010

11-
class AndroidNotificationTest extends AbstractTestCase
11+
class AndroidNotificationTest extends TestCase
1212
{
1313
public function testLightSettingsWithInvalidColor(): void
1414
{

0 commit comments

Comments
 (0)