Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit ebfe102

Browse files
authored
Merge pull request #107 from codedge/increase-test-coverage
Increase test coverage
2 parents 0a56843 + c9eaeb1 commit ebfe102

File tree

7 files changed

+29
-61
lines changed

7 files changed

+29
-61
lines changed

src/Contracts/GithubRepositoryTypeContract.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/SourceRepositoryTypes/GithubRepositoryType.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Codedge\Updater\SourceRepositoryTypes;
66

7-
use Codedge\Updater\Contracts\GithubRepositoryTypeContract;
7+
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
88
use Codedge\Updater\Events\UpdateAvailable;
99
use Codedge\Updater\Models\Release;
1010
use Codedge\Updater\Models\UpdateExecutor;
@@ -13,21 +13,17 @@
1313
use Codedge\Updater\Traits\SupportPrivateAccessToken;
1414
use Codedge\Updater\Traits\UseVersionFile;
1515
use Exception;
16-
use GuzzleHttp\Client;
16+
use GuzzleHttp\ClientInterface;
1717
use InvalidArgumentException;
1818

19-
/**
20-
* GithubRepositoryType.
21-
*
22-
* @author Holger Lösken <[email protected]>
23-
* @copyright See LICENSE file that was distributed with this source code.
24-
*/
2519
class GithubRepositoryType
2620
{
2721
use UseVersionFile, SupportPrivateAccessToken;
2822

23+
const GITHUB_API_URL = 'https://api.github.com';
24+
2925
/**
30-
* @var Client
26+
* @var ClientInterface
3127
*/
3228
protected $client;
3329

@@ -53,7 +49,7 @@ public function __construct(array $config, UpdateExecutor $updateExecutor)
5349
$this->updateExecutor = $updateExecutor;
5450
}
5551

56-
public function create(): GithubRepositoryTypeContract
52+
public function create(): SourceRepositoryTypeContract
5753
{
5854
if (empty($this->config['repository_vendor']) || empty($this->config['repository_name'])) {
5955
throw new \Exception('"repository_vendor" or "repository_name" are missing in config file.');
@@ -83,8 +79,6 @@ protected function useBranchForVersions(): bool
8379
}
8480

8581
/**
86-
* {@inheritdoc}
87-
*
8882
* @return string
8983
*/
9084
public function getVersionInstalled(): string

src/SourceRepositoryTypes/GithubRepositoryTypes/GithubBranchType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes;
66

7-
use Codedge\Updater\Contracts\GithubRepositoryTypeContract;
7+
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
88
use Codedge\Updater\Models\Release;
99
use Codedge\Updater\Models\UpdateExecutor;
1010
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryType;
@@ -14,7 +14,7 @@
1414
use Illuminate\Support\Str;
1515
use Psr\Http\Message\ResponseInterface;
1616

17-
final class GithubBranchType extends GithubRepositoryType implements GithubRepositoryTypeContract
17+
final class GithubBranchType extends GithubRepositoryType implements SourceRepositoryTypeContract
1818
{
1919
/**
2020
* @var ClientInterface

src/SourceRepositoryTypes/GithubRepositoryTypes/GithubTagType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes;
66

7-
use Codedge\Updater\Contracts\GithubRepositoryTypeContract;
7+
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
88
use Codedge\Updater\Models\Release;
99
use Codedge\Updater\Models\UpdateExecutor;
1010
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryType;
@@ -15,7 +15,7 @@
1515
use Illuminate\Support\Str;
1616
use Psr\Http\Message\ResponseInterface;
1717

18-
final class GithubTagType extends GithubRepositoryType implements GithubRepositoryTypeContract
18+
final class GithubTagType extends GithubRepositoryType implements SourceRepositoryTypeContract
1919
{
2020
/**
2121
* @var ClientInterface

src/SourceRepositoryTypes/HttpRepositoryType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Codedge\Updater\Traits\SupportPrivateAccessToken;
1212
use Codedge\Updater\Traits\UseVersionFile;
1313
use Exception;
14-
use GuzzleHttp\Client;
14+
use GuzzleHttp\ClientInterface;
1515
use Illuminate\Support\Collection;
1616
use Illuminate\Support\Facades\Log;
1717
use Illuminate\Support\Str;
@@ -23,7 +23,7 @@ class HttpRepositoryType implements SourceRepositoryTypeContract
2323
use UseVersionFile, SupportPrivateAccessToken;
2424

2525
/**
26-
* @var Client
26+
* @var ClientInterface
2727
*/
2828
protected $client;
2929

@@ -56,10 +56,10 @@ class HttpRepositoryType implements SourceRepositoryTypeContract
5656
* Github constructor.
5757
*
5858
* @param array $config
59-
* @param Client $client
59+
* @param ClientInterface $client
6060
* @param UpdateExecutor $updateExecutor
6161
*/
62-
public function __construct(array $config, Client $client, UpdateExecutor $updateExecutor)
62+
public function __construct(array $config, ClientInterface $client, UpdateExecutor $updateExecutor)
6363
{
6464
$this->client = $client;
6565
$this->config = $config;

src/UpdaterServiceProvider.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Codedge\Updater;
44

55
use Codedge\Updater\Commands\CheckForUpdate;
6-
use Codedge\Updater\Contracts\GithubRepositoryTypeContract;
6+
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
77
use Codedge\Updater\Models\Release;
88
use Codedge\Updater\Models\UpdateExecutor;
99
use Codedge\Updater\Notifications\EventHandler;
@@ -12,6 +12,7 @@
1212
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes\GithubTagType;
1313
use Codedge\Updater\SourceRepositoryTypes\HttpRepositoryType;
1414
use GuzzleHttp\Client;
15+
use GuzzleHttp\ClientInterface;
1516
use Illuminate\Filesystem\Filesystem;
1617
use Illuminate\Support\Facades\App;
1718
use Illuminate\Support\ServiceProvider;
@@ -102,33 +103,38 @@ protected function registerManager()
102103
return new UpdateExecutor();
103104
});
104105

106+
$this->app->bind(ClientInterface::class, Client::class);
107+
$this->app->bind(Client::class, function () {
108+
return new Client(['base_uri' => GithubRepositoryType::GITHUB_API_URL]);
109+
});
110+
105111
$this->app->bind(GithubRepositoryType::class, function (): GithubRepositoryType {
106112
return new GithubRepositoryType(
107113
config('self-update.repository_types.github'),
108114
$this->app->make(UpdateExecutor::class)
109115
);
110116
});
111117

112-
$this->app->bind(GithubBranchType::class, function (): GithubRepositoryTypeContract {
118+
$this->app->bind(GithubBranchType::class, function (): SourceRepositoryTypeContract {
113119
return new GithubBranchType(
114120
config('self-update.repository_types.github'),
115-
new Client(['base_uri' => GithubRepositoryTypeContract::GITHUB_API_URL]),
121+
$this->app->make(ClientInterface::class),
116122
$this->app->make(UpdateExecutor::class)
117123
);
118124
});
119125

120-
$this->app->bind(GithubTagType::class, function (): GithubRepositoryTypeContract {
126+
$this->app->bind(GithubTagType::class, function (): SourceRepositoryTypeContract {
121127
return new GithubTagType(
122128
config('self-update.repository_types.github'),
123-
new Client(['base_uri' => GithubRepositoryTypeContract::GITHUB_API_URL]),
129+
$this->app->make(ClientInterface::class),
124130
$this->app->make(UpdateExecutor::class)
125131
);
126132
});
127133

128134
$this->app->bind(HttpRepositoryType::class, function () {
129135
return new HttpRepositoryType(
130136
config('self-update.repository_types.http'),
131-
new Client(),
137+
$this->app->make(ClientInterface::class),
132138
$this->app->make(UpdateExecutor::class)
133139
);
134140
});

tests/TestCase.php

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

33
namespace Codedge\Updater\Tests;
44

5-
use Codedge\Updater\Contracts\GithubRepositoryTypeContract;
5+
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
66
use Codedge\Updater\Models\UpdateExecutor;
7+
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryType;
78
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes\GithubBranchType;
89
use Codedge\Updater\SourceRepositoryTypes\GithubRepositoryTypes\GithubTagType;
910
use Codedge\Updater\SourceRepositoryTypes\HttpRepositoryType;
1011
use Codedge\Updater\UpdaterFacade;
1112
use Codedge\Updater\UpdaterServiceProvider;
1213
use GuzzleHttp\Client;
14+
use GuzzleHttp\ClientInterface;
1315
use GuzzleHttp\Handler\MockHandler;
1416
use GuzzleHttp\HandlerStack;
1517
use GuzzleHttp\Psr7\Response;
@@ -57,30 +59,6 @@ protected function getEnvironmentSetUp($app)
5759
'private_access_token' => '',
5860
],
5961
]);
60-
61-
$app->bind(GithubBranchType::class, function (Application $app): GithubRepositoryTypeContract {
62-
return new GithubBranchType(
63-
config('self-update.repository_types.github'),
64-
$app->make(Client::class),
65-
$app->make(UpdateExecutor::class)
66-
);
67-
});
68-
69-
$app->bind(GithubTagType::class, function (Application $app): GithubRepositoryTypeContract {
70-
return new GithubTagType(
71-
config('self-update.repository_types.github'),
72-
$app->make(Client::class),
73-
$app->make(UpdateExecutor::class)
74-
);
75-
});
76-
77-
$app->bind(HttpRepositoryType::class, function(Application $app) {
78-
return new HttpRepositoryType(
79-
config('self-update.repository_types.http'),
80-
$app->make(Client::class),
81-
$app->make(UpdateExecutor::class)
82-
);
83-
});
8462
}
8563

8664
protected function getMockedClient($responses): Client

0 commit comments

Comments
 (0)