Skip to content

Commit 08fd69a

Browse files
authored
Merge pull request #56 from codedge/improve-test-coverage
Improve tests
2 parents 2740323 + d381f77 commit 08fd69a

File tree

7 files changed

+84
-28
lines changed

7 files changed

+84
-28
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"guzzlehttp/guzzle": "6.*"
5555
},
5656
"require-dev": {
57-
"phpunit/phpunit": "^7",
58-
"orchestra/testbench": "3.7.*",
59-
"mockery/mockery": "^0.9.5"
57+
"phpunit/phpunit": "^7.0",
58+
"mockery/mockery": "^0.9.5",
59+
"orchestra/testbench": "~3.4.2|~3.5.0|~3.6.0|~3.7.0"
6060
}
6161
}

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false">
11+
stopOnFailure="true">
1212

1313
<testsuites>
1414
<testsuite name="Laravel Application Self-Updater Test Suite">
@@ -22,4 +22,4 @@
2222
</whitelist>
2323
</filter>
2424

25-
</phpunit>
25+
</phpunit>

src/UpdaterManager.php

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

55
use Closure;
66
use GuzzleHttp\Client;
7+
use InvalidArgumentException;
78
use Illuminate\Foundation\Application;
89
use Codedge\Updater\Contracts\UpdaterContract;
910
use Codedge\Updater\Contracts\SourceRepositoryTypeContract;
@@ -114,9 +115,13 @@ public function __call($method, $parameters)
114115
*
115116
* @return array
116117
*/
117-
protected function getConfig($name)
118+
protected function getConfig(string $name): array
118119
{
119-
return $this->app['config']['self-update']['repository_types'][$name];
120+
if (isset($this->app['config']['self-update']['repository_types'][$name])) {
121+
return $this->app['config']['self-update']['repository_types'][$name];
122+
}
123+
124+
return [];
120125
}
121126

122127
/**
@@ -144,7 +149,7 @@ protected function resolve($name)
144149
{
145150
$config = $this->getConfig($name);
146151

147-
if (is_null($config)) {
152+
if (empty($config)) {
148153
throw new InvalidArgumentException("Source repository [{$name}] is not defined.");
149154
}
150155

tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
use GuzzleHttp\Handler\MockHandler;
1010
use GuzzleHttp\HandlerStack;
1111
use GuzzleHttp\Psr7\Response;
12-
use GuzzleHttp\Psr7\Request;
13-
use GuzzleHttp\Exception\RequestException;
14-
use Mockery;
15-
use Psr\Http\Message\StreamInterface;
12+
use Illuminate\Support\Facades\Storage;
13+
use InvalidArgumentException;
14+
use Exception;
1615

1716
class GithubRepositoryTypeTest extends TestCase
1817
{
@@ -63,16 +62,10 @@ public function setUp()
6362
);
6463
}
6564

66-
public function tearDown()
67-
{
68-
parent::tearDown();
69-
Mockery::close();
70-
}
71-
7265
public function testIsNewVersionAvailableFailsWithInvalidArgumentException()
7366
{
7467
$class = new GithubRepositoryType($this->client, $this->config);
75-
$this->expectException(\InvalidArgumentException::class);
68+
$this->expectException(InvalidArgumentException::class);
7669
$class->isNewVersionAvailable();
7770
}
7871

@@ -81,6 +74,8 @@ public function testIsNewVersionAvailableTriggerUpdateAvailableEvent()
8174
$class = new GithubRepositoryType($this->client, $this->config);
8275
$currentVersion = 'v1.1.0';
8376

77+
Storage::delete(GithubRepositoryType::NEW_VERSION_FILE);
78+
8479
$this->expectsEvents(UpdateAvailable::class);
8580
$this->assertTrue($class->isNewVersionAvailable($currentVersion));
8681
}
@@ -108,7 +103,7 @@ public function testGetVersionAvailable()
108103
public function testFetchingFailsWithException()
109104
{
110105
$class = new GithubRepositoryType($this->client, $this->config);
111-
$this->expectException(\Exception::class);
106+
$this->expectException(Exception::class);
112107
$class->fetch();
113108
}
114-
}
109+
}

tests/TestCase.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Codedge\Updater\Tests;
44

55
use Codedge\Updater\UpdaterFacade;
66
use Codedge\Updater\UpdaterServiceProvider;
7-
use GuzzleHttp\Client;
87
use Illuminate\Foundation\Application;
9-
use Orchestra\Testbench\TestCase as BaseTestCase;
8+
use Orchestra\Testbench\TestCase as Orchestra;
109

11-
class TestCase extends BaseTestCase
10+
abstract class TestCase extends Orchestra
1211
{
1312
protected $client;
1413

1514
/**
16-
* @param \Illuminate\Foundation\Application $app
15+
* @param Application $app
16+
*
17+
* @return void
1718
*/
1819
protected function getEnvironmentSetUp($app)
1920
{
@@ -28,6 +29,12 @@ protected function getEnvironmentSetUp($app)
2829
'repository_url' => '',
2930
'download_path' => '/tmp',
3031
],
32+
'http' => [
33+
'type' => 'http',
34+
'repository_url' => env('SELF_UPDATER_REPO_URL', ''),
35+
'pkg_filename_format' => env('SELF_UPDATER_PKG_FILENAME_FORMAT', 'v_VERSION_'),
36+
'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),
37+
],
3138
],
3239
'log_events' => false,
3340
'mail_to' => [
@@ -58,4 +65,4 @@ protected function getPackageAliases($app)
5865
'Updater' => UpdaterFacade::class,
5966
];
6067
}
61-
}
68+
}

tests/UpdaterManagerTest.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Codedge\Updater\Tests;
4+
5+
use Codedge\Updater\SourceRepository;
6+
use Codedge\Updater\UpdaterManager;
7+
use InvalidArgumentException;
8+
9+
class UpdaterManagerTest extends Testcase
10+
{
11+
public function test_can_be_instantiated()
12+
{
13+
$manager = new UpdaterManager(app());
14+
15+
$this->assertInstanceOf(UpdaterManager::class, $manager);
16+
}
17+
18+
public function test_get_source_repository_with_name_github()
19+
{
20+
$manager = new UpdaterManager(app());
21+
$result = $manager->source('github');
22+
23+
$this->assertInstanceOf(SourceRepository::class, $result);
24+
}
25+
26+
public function test_get_source_repository_with_name_http()
27+
{
28+
$manager = new UpdaterManager(app());
29+
$result = $manager->source('http');
30+
31+
$this->assertInstanceOf(SourceRepository::class, $result);
32+
}
33+
34+
public function test_get_source_repository_with_default_name()
35+
{
36+
$manager = new UpdaterManager(app());
37+
$result = $manager->source();
38+
39+
$this->assertInstanceOf(SourceRepository::class, $result);
40+
}
41+
42+
public function test_get_source_repository_with_not_existing_name()
43+
{
44+
$manager = new UpdaterManager(app());
45+
46+
$this->expectException(InvalidArgumentException::class);
47+
$manager->source('test');
48+
}
49+
}

0 commit comments

Comments
 (0)