Skip to content

Commit ca6177f

Browse files
committed
Convert code style to PSR-2
1 parent 92b3e23 commit ca6177f

File tree

8 files changed

+88
-25
lines changed

8 files changed

+88
-25
lines changed

.php_cs.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$config = new Amp\CodeStyle\Config();
4+
$config->getFinder()
5+
->in(__DIR__ . '/src')
6+
->in(__DIR__ . '/test');
7+
8+
$cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__;
9+
10+
$config->setCacheFile($cacheDir . '/.php_cs.cache');
11+
12+
return $config;

.travis.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
sudo: false
2+
3+
language: php
4+
5+
php:
6+
- 7.0
7+
- 7.1
8+
- 7.2
9+
- 7.3
10+
- 7.4snapshot
11+
- nightly
12+
13+
matrix:
14+
allow_failures:
15+
- php: nightly
16+
fast_finish: true
17+
18+
env:
19+
- AMP_DEBUG=true
20+
21+
install:
22+
- composer update -n --prefer-dist
23+
- wget https://github.com/php-coveralls/php-coveralls/releases/download/v1.0.2/coveralls.phar
24+
- chmod +x coveralls.phar
25+
26+
script:
27+
- vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
28+
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
29+
30+
after_script:
31+
- ./coveralls.phar -v
32+
33+
cache:
34+
directories:
35+
- $HOME/.composer/cache/files
36+
- $HOME/.php-cs-fixer

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2017 amphp
3+
Copyright (c) 2017-2019 amphp
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"phpunit/phpunit": "^6"
1818
},
1919
"require-dev": {
20-
"amphp/amp": "^2"
20+
"amphp/amp": "^2",
21+
"amphp/php-cs-fixer-config": "dev-master"
2122
},
2223
"autoload": {
2324
"psr-4": {

src/CallbackStub.php

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

33
namespace Amp\PHPUnit;
44

5-
class CallbackStub {
6-
public function __invoke() {}
5+
class CallbackStub
6+
{
7+
public function __invoke()
8+
{
9+
// nothing
10+
}
711
}

src/LoopReset.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
use PHPUnit\Framework\BaseTestListener;
77
use PHPUnit\Framework\Test;
88

9-
class LoopReset extends BaseTestListener {
10-
public function endTest(Test $test, $time) {
9+
class LoopReset extends BaseTestListener
10+
{
11+
public function endTest(Test $test, $time)
12+
{
1113
Loop::set((new Loop\DriverFactory)->create());
1214
gc_collect_cycles(); // extensions using an event loop may otherwise leak the file descriptors to the loop
1315
}

src/TestCase.php

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/**
66
* Abstract test class with methods for creating callbacks and asserting runtimes.
77
*/
8-
abstract class TestCase extends \PHPUnit\Framework\TestCase {
8+
abstract class TestCase extends \PHPUnit\Framework\TestCase
9+
{
910
const RUNTIME_PRECISION = 2; // Number of decimals to use in runtime calculations/comparisons.
1011

1112
/**
@@ -16,7 +17,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase {
1617
* @return callable|\PHPUnit_Framework_MockObject_MockObject Object that is callable and expects to be called the
1718
* given number of times.
1819
*/
19-
public function createCallback(int $count): callable {
20+
public function createCallback(int $count): callable
21+
{
2022
$mock = $this->createMock(CallbackStub::class);
2123

2224
$mock->expects($this->exactly($count))
@@ -30,33 +32,24 @@ public function createCallback(int $count): callable {
3032
*
3133
* @param callable $callback
3234
* @param int $maxRunTime Max runtime allowed for the test to pass.
33-
* @param mixed[] $args Function arguments.
35+
* @param mixed[] $args Function arguments.
3436
*/
35-
public function assertRunTimeLessThan(callable $callback, int $maxRunTime, array $args = []) {
37+
public function assertRunTimeLessThan(callable $callback, int $maxRunTime, array $args = [])
38+
{
3639
$this->assertRunTimeBetween($callback, 0, $maxRunTime, $args);
3740
}
3841

39-
/**
40-
* Asserts that the given callback takes more than $minRunTime to run.
41-
*
42-
* @param callable $callback
43-
* @param int $minRunTime Minimum runtime allowed for the test to pass.
44-
* @param mixed[] $args Function arguments.
45-
*/
46-
public function assertRunTimeGreaterThan(callable $callback, int $minRunTime, array $args = []) {
47-
$this->assertRunTimeBetween($callback, $minRunTime, 0, $args);
48-
}
49-
5042
/**
5143
* Asserts that the given callback takes between $minRunTime and $maxRunTime to execute.
5244
* Rounds to the nearest 100 ms.
5345
*
5446
* @param callable $callback
5547
* @param int $minRunTime Minimum runtime allowed for the test to pass.
5648
* @param int $maxRunTime Max runtime allowed for the test to pass.
57-
* @param mixed[] $args Function arguments.
49+
* @param mixed[] $args Function arguments.
5850
*/
59-
public function assertRunTimeBetween(callable $callback, int $minRunTime, int $maxRunTime, array $args = []) {
51+
public function assertRunTimeBetween(callable $callback, int $minRunTime, int $maxRunTime, array $args = [])
52+
{
6053
$start = \microtime(true);
6154

6255
$callback(...$args);
@@ -80,14 +73,27 @@ public function assertRunTimeBetween(callable $callback, int $minRunTime, int $m
8073
}
8174
}
8275

76+
/**
77+
* Asserts that the given callback takes more than $minRunTime to run.
78+
*
79+
* @param callable $callback
80+
* @param int $minRunTime Minimum runtime allowed for the test to pass.
81+
* @param mixed[] $args Function arguments.
82+
*/
83+
public function assertRunTimeGreaterThan(callable $callback, int $minRunTime, array $args = [])
84+
{
85+
$this->assertRunTimeBetween($callback, $minRunTime, 0, $args);
86+
}
87+
8388
/**
8489
* Runs the given callback in a separate fork.
8590
*
8691
* @param callable $function
8792
*
8893
* @return int
8994
*/
90-
final protected function doInFork(callable $function) {
95+
final protected function doInFork(callable $function)
96+
{
9197
switch ($pid = \pcntl_fork()) {
9298
case -1:
9399
$this->fail('Failed to fork process.');

src/TestException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
* $this->assertSame($expectedExceptionInstance, $e);
1414
* }
1515
*/
16-
class TestException extends \Exception {
16+
class TestException extends \Exception
17+
{
18+
// nothing
1719
}

0 commit comments

Comments
 (0)