Skip to content

Commit 95a7cab

Browse files
committed
tests: refactor
1 parent 677f6d5 commit 95a7cab

File tree

10 files changed

+39
-45
lines changed

10 files changed

+39
-45
lines changed

tests/Github/Api.expandColonParameters.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare(strict_types=1);
99
require __DIR__ . '/../bootstrap.php';
1010

1111

12-
class TestApi extends Milo\Github\Api
12+
class TestExpandColonApi extends Milo\Github\Api
1313
{
1414
public function expandColonParameters(string $url, array $parameters, array $defaultParameters = []): string
1515
{
@@ -20,7 +20,7 @@ class TestApi extends Milo\Github\Api
2020

2121
# URL parameters like :name
2222
test(function() {
23-
$api = new TestApi;
23+
$api = new TestExpandColonApi;
2424

2525
$urls = [
2626
'' => '?a=A&b=B',
@@ -50,15 +50,15 @@ test(function() {
5050

5151
# Parameters escaping
5252
test(function() {
53-
$api = new TestApi;
53+
$api = new TestExpandColonApi;
5454

5555
Assert::same('/with%20space', $api->expandColonParameters('/:name', ['name' => 'with space']));
5656
});
5757

5858

5959
# Default parameters expanding
6060
test(function() {
61-
$api = new TestApi;
61+
$api = new TestExpandColonApi;
6262

6363
Assert::same('/default', $api->expandColonParameters('/:var', [], ['var' => 'default']));
6464
Assert::same('/set', $api->expandColonParameters('/:var', ['var' => 'set'], ['var' => 'default']));

tests/Github/Api.expandUriTemplate.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ declare(strict_types=1);
99
require __DIR__ . '/../bootstrap.php';
1010

1111

12-
class TestApi extends Milo\Github\Api
12+
class TestExpandUriTemplateApi extends Milo\Github\Api
1313
{
1414
public function expandUriTemplate(string $url, array $parameters, array $defaultParameters = []): string
1515
{
1616
return parent::expandUriTemplate($url, $parameters, $defaultParameters);
1717
}
1818
}
1919

20-
$api = new TestApi;
20+
$api = new TestExpandUriTemplateApi;
2121

2222
# NULL (aka undefined)
2323
$cases = [

tests/Github/Api.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ declare(strict_types=1);
99
require __DIR__ . '/../bootstrap.php';
1010

1111

12-
class MockIClient implements Milo\Github\Http\IClient
12+
class LogicExceptionMockClient implements Milo\Github\Http\IClient
1313
{
1414
public function request(Milo\Github\Http\Request $request): Milo\Github\Http\Response
1515
{
1616
throw new \LogicException;
1717
}
1818

1919

20-
public function onRequest(?callable $cb): static
20+
public function onRequest(?callable $callback): static
2121
{
2222
return $this;
2323
}
2424

2525

26-
public function onResponse(?callable $cb): static
26+
public function onResponse(?callable $callback): static
2727
{
2828
return $this;
2929
}
@@ -32,7 +32,7 @@ class MockIClient implements Milo\Github\Http\IClient
3232

3333
# Basics
3434
test(function() {
35-
$client = new MockIClient;
35+
$client = new LogicExceptionMockClient;
3636
$api = new Milo\Github\Api($client);
3737

3838
Assert::same($client, $api->getClient());
@@ -58,7 +58,7 @@ test(function() {
5858

5959
# createRequest()
6060
test(function() {
61-
$client = new MockIClient;
61+
$client = new LogicExceptionMockClient;
6262
$api = new Milo\Github\Api($client);
6363

6464
# All slashes in URL
@@ -87,7 +87,7 @@ test(function() {
8787

8888
# Default parameters
8989
test(function() {
90-
$client = new MockIClient;
90+
$client = new LogicExceptionMockClient;
9191
$api = new Milo\Github\Api($client);
9292
$api->setUrl('url://test');
9393

@@ -110,7 +110,7 @@ test(function() {
110110

111111
# Api called with absolute URL
112112
test(function() {
113-
$client = new MockIClient;
113+
$client = new LogicExceptionMockClient;
114114
$api = new Milo\Github\Api($client);
115115
$api->setUrl('url://test');
116116

@@ -137,7 +137,7 @@ test(function() {
137137

138138
# Paginator
139139
test(function() {
140-
$client = new MockIClient;
140+
$client = new LogicExceptionMockClient;
141141
$api = new Milo\Github\Api($client);
142142

143143
Assert::type(Milo\Github\Paginator::class, $api->paginator(''));

tests/Github/Api.request.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class MockIClient implements Milo\Github\Http\IClient
2121
}
2222

2323

24-
public function onRequest(?callable $cb): static
24+
public function onRequest(?callable $callback): static
2525
{
2626
return $this;
2727
}
2828

2929

30-
public function onResponse(?callable $cb): static
30+
public function onResponse(?callable $callback): static
3131
{
3232
return $this;
3333
}

tests/Github/Http/AbstractClient.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare(strict_types=1);
1010
require __DIR__ . '/../../bootstrap.php';
1111

1212

13-
class TestClient extends Milo\Github\Http\AbstractClient
13+
final class TestAbstractClient extends Milo\Github\Http\AbstractClient
1414
{
1515
/** @var callable */
1616
public $onProcess;
@@ -32,7 +32,7 @@ test(function() {
3232
new Milo\Github\Http\Response(200, ['Location' => ''], ''),
3333
];
3434

35-
$client = new TestClient;
35+
$client = new TestAbstractClient;
3636
$client->onProcess = function (Milo\Github\Http\Request $request) use (&$responses) {
3737
return array_shift($responses);
3838
};
@@ -56,7 +56,7 @@ test(function() {
5656

5757
# onRequest(), onResponse()
5858
test(function() {
59-
$client = new TestClient;
59+
$client = new TestAbstractClient;
6060
$client->onProcess = function() { return new Milo\Github\Http\Response(200, [], '{response}'); };
6161

6262
$onRequest = null;
@@ -78,7 +78,7 @@ test(function() {
7878

7979
# Additional headers
8080
test(function(){
81-
$client = new TestClient;
81+
$client = new TestAbstractClient;
8282
$client->onProcess = function(Milo\Github\Http\Request $request) {
8383
Assert::same([
8484
'expect' => '',

tests/Github/Http/CachedClient.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require __DIR__ . '/../../bootstrap.php';
1414
use Milo\Github\Http;
1515

1616

17-
class MockClient implements Http\IClient
17+
class MockClientCounter implements Http\IClient
1818
{
1919
/** @var callable */
2020
public $onRequest;
@@ -29,15 +29,15 @@ class MockClient implements Http\IClient
2929
return $response;
3030
}
3131

32-
public function onRequest(?callable $foo): static
32+
public function onRequest(?callable $callback): static
3333
{
34-
trigger_error('Inner onRequest called: ' . var_export($foo, true), E_USER_NOTICE);
34+
trigger_error('Inner onRequest called: ' . var_export($callback, true), E_USER_NOTICE);
3535
return $this;
3636
}
3737

38-
public function onResponse(?callable $foo): static
38+
public function onResponse(?callable $callback): static
3939
{
40-
trigger_error('Inner onResponse called: ' . var_export($foo, true), E_USER_NOTICE);
40+
trigger_error('Inner onResponse called: ' . var_export($callback, true), E_USER_NOTICE);
4141
return $this;
4242
}
4343
}
@@ -63,13 +63,13 @@ class CachingTestCase extends Tester\TestCase
6363
{
6464
private Http\CachedClient $client;
6565

66-
private MockClient $innerClient;
66+
private MockClientCounter $innerClient;
6767

6868

6969
public function setup()
7070
{
7171
$cache = new MockCache;
72-
$this->innerClient = new MockClient;
72+
$this->innerClient = new MockClientCounter;
7373
$this->client = new Http\CachedClient($cache, $this->innerClient);
7474

7575
$this->innerClient->onRequest = function (Http\Request $request) {

tests/Github/Http/StreamClient.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare(strict_types=1);
1010
require __DIR__ . '/../../bootstrap.php';
1111

1212

13-
class TestClient extends Milo\Github\Http\StreamClient
13+
class TestStreamClient extends Milo\Github\Http\StreamClient
1414
{
1515
/** @var callable */
1616
public $onFileGetContents;
@@ -21,13 +21,13 @@ class TestClient extends Milo\Github\Http\StreamClient
2121
}
2222

2323

24-
public function onRequest(?callable $cb): static
24+
public function onRequest(?callable $callback): static
2525
{
2626
return $this;
2727
}
2828

2929

30-
public function onResponse(?callable $cb): static
30+
public function onResponse(?callable $callback): static
3131
{
3232
return $this;
3333
}
@@ -36,7 +36,7 @@ class TestClient extends Milo\Github\Http\StreamClient
3636

3737
# Common
3838
test(function() {
39-
$client = new TestClient;
39+
$client = new TestStreamClient;
4040
$client->onFileGetContents = function($url, array $contextOptions) {
4141
Assert::same('http://example.com', $url);
4242
Assert::same([
@@ -68,7 +68,7 @@ test(function() {
6868

6969
# SSL options
7070
test(function() {
71-
$client = new TestClient(['option' => 'value']);
71+
$client = new TestStreamClient(['option' => 'value']);
7272
$client->onFileGetContents = function($url, array $contextOptions) {
7373
Assert::type('array', $contextOptions['ssl']);
7474
Assert::same([

tests/Github/OAuth/Login.phpt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ class MockClient implements Milo\Github\Http\IClient
2222
}
2323

2424

25-
public function onRequest(?callable $cb): static
25+
public function onRequest(?callable $callback): static
2626
{
2727
return $this;
2828
}
2929

3030

31-
public function onResponse(?callable $cb): static
31+
public function onResponse(?callable $callback): static
3232
{
3333
return $this;
3434
}
@@ -38,17 +38,11 @@ class MockClient implements Milo\Github\Http\IClient
3838

3939
class LoginTestCase extends Tester\TestCase
4040
{
41-
/** @var Milo\Github\OAuth\Configuration */
42-
private $config;
41+
private Milo\Github\Storages\SessionStorage $storage;
4342

44-
/** @var Milo\Github\Storages\SessionStorage */
45-
private $storage;
43+
private MockClient $client;
4644

47-
/** @var MockClient */
48-
private $client;
49-
50-
/** @var Milo\Github\OAuth\Login */
51-
private $login;
45+
private Milo\Github\OAuth\Login $login;
5246

5347

5448
public function setup()

tests/Github/Storages/FileCache.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $e = Assert::exception(function() {
1616
Assert::null($e->getPrevious());
1717

1818

19-
define('TEMP_DIR', __DIR__ . '/temp.FileCache');
19+
const TEMP_DIR = __DIR__ . '/temp.FileCache';
2020
@mkdir(TEMP_DIR); # @ = directory may exist
2121
Tester\Helpers::purge(TEMP_DIR);
2222

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
class Assert extends Tester\Assert
1717
{}
1818

19-
function test(\closure $cb) {
19+
function test(\Closure $cb) {
2020
$cb();
2121
}

0 commit comments

Comments
 (0)