Skip to content

Commit 99ec962

Browse files
authored
Merge pull request #117 from beyondcode/updates
Laravel 11 compatibility & more
2 parents e6d36fe + 71cccbc commit 99ec962

13 files changed

+102
-81
lines changed

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ composer.lock
33
docs
44
vendor
55
coverage
6-
.idea
6+
.idea
7+
.phpunit.result.cache
8+
.phpunit.cache
9+
.vscode

Diff for: README.md

-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Perform Self-Diagnosis Tests On Your Laravel Application
22

33
[![Latest Version on Packagist](https://img.shields.io/packagist/v/beyondcode/laravel-self-diagnosis.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-self-diagnosis)
4-
[![Build Status](https://img.shields.io/travis/beyondcode/laravel-self-diagnosis/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-self-diagnosis)
5-
[![Quality Score](https://img.shields.io/scrutinizer/g/beyondcode/laravel-self-diagnosis.svg?style=flat-square)](https://scrutinizer-ci.com/g/beyondcode/laravel-self-diagnosis)
64
[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-self-diagnosis.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-self-diagnosis)
75

86
This package allows you to run self-diagnosis tests on your Laravel application. It comes with multiple checks out of the box and allows you to add custom checks yourself.
@@ -50,8 +48,6 @@ You can install the package via composer:
5048
composer require beyondcode/laravel-self-diagnosis
5149
```
5250

53-
If you're using Laravel 5.5+ the `SelfDiagnosisServiceProvider` will be automatically registered for you.
54-
5551
## Usage
5652

5753
Just call the artisan command to start the checks:

Diff for: composer.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1|^8.0",
19+
"php": "^8.2",
2020
"composer/semver": "^1.4|^3.0",
2121
"geerlingguy/ping": "^1.1",
22-
"illuminate/support": "5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0",
23-
"vlucas/phpdotenv": "~2.5|~3.3|^4.0|^5.0"
22+
"illuminate/support": "^9.0|^10.0|^11.0",
23+
"vlucas/phpdotenv": "^5.0"
2424
},
2525
"require-dev": {
2626
"larapack/dd": "^1.0",
2727
"mockery/mockery": "^1.0",
28-
"orchestra/testbench": "~3.5|~3.8",
29-
"phpunit/phpunit": "^7.0|^8.0",
28+
"orchestra/testbench": "^7.0|^8.0",
29+
"phpunit/phpunit": "^9.5.10",
3030
"predis/predis": "^1.1",
3131
"scrutinizer/ocular": "^1.5"
3232
},

Diff for: phpunit.xml.dist

+16-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
12-
<testsuites>
13-
<testsuite name="BeyondCode Test Suite">
14-
<directory>tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
22-
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
28-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd">
3+
<coverage>
4+
<report>
5+
<clover outputFile="build/logs/clover.xml"/>
6+
<html outputDirectory="build/coverage"/>
7+
<text outputFile="build/coverage.txt"/>
8+
</report>
9+
</coverage>
10+
<testsuites>
11+
<testsuite name="BeyondCode Test Suite">
12+
<directory>tests</directory>
13+
</testsuite>
14+
</testsuites>
15+
<logging>
16+
<junit outputFile="build/report.junit.xml"/>
17+
</logging>
2918
</phpunit>

Diff for: phpunit.xml.dist.bak

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="BeyondCode Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
<logging>
23+
<log type="tap" target="build/report.tap"/>
24+
<log type="junit" target="build/report.junit.xml"/>
25+
<log type="coverage-html" target="build/coverage"/>
26+
<log type="coverage-text" target="build/coverage.txt"/>
27+
<log type="coverage-clover" target="build/logs/clover.xml"/>
28+
</logging>
29+
</phpunit>

Diff for: src/Checks/ComposerWithDevDependenciesIsUpToDate.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public function check(array $config): bool
4343

4444
$this->output = $this->composer->installDryRun($additionalOptions);
4545

46-
return Str::contains($this->output, ['Nothing to install or update', 'Nothing to install, update or remove']);
46+
return Str::contains($this->output, [
47+
'Nothing to install or update',
48+
'Nothing to install, update or remove',
49+
'Package operations: 0 installs, 0 updates, 0 removals'
50+
]);
4751
}
4852

4953
/**

Diff for: src/Checks/ComposerWithoutDevDependenciesIsUpToDate.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public function check(array $config): bool
4343

4444
$this->output = $this->composer->installDryRun('--no-dev ' . $additionalOptions);
4545

46-
return Str::contains($this->output, ['Nothing to install or update', 'Nothing to install, update or remove']);
46+
return Str::contains($this->output, [
47+
'Nothing to install or update',
48+
'Nothing to install, update or remove',
49+
'Package operations: 0 installs, 0 updates, 0 removals'
50+
]);
4751
}
4852

4953
/**

Diff for: src/Checks/ExampleEnvironmentVariablesAreUpToDate.php

+6-31
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,14 @@ public function name(array $config): string
2929
*/
3030
public function check(array $config): bool
3131
{
32-
if (method_exists(Dotenv::class, 'createImmutable')) {
33-
return $this->checkForDotEnvV4();
34-
}
32+
$examples = Dotenv::createMutable(base_path(), '.env.example');
33+
$examples = $examples->safeLoad();
3534

36-
if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
37-
$examples = Dotenv::create(base_path(), '.env.example');
38-
$actual = Dotenv::create(base_path(), '.env');
39-
} else {
40-
$examples = new Dotenv(base_path(), '.env.example');
41-
$actual = new Dotenv(base_path(), '.env');
42-
}
35+
$actual = Dotenv::createMutable(base_path(), '.env');
36+
$actual = $actual->safeLoad();
4337

44-
$examples->safeLoad();
45-
$actual->safeLoad();
46-
47-
$this->envVariables = Collection::make($actual->getEnvironmentVariableNames())
48-
->diff($examples->getEnvironmentVariableNames());
49-
50-
return $this->envVariables->isEmpty();
51-
}
52-
53-
/**
54-
* Perform the verification of this check for DotEnv v4.
55-
*
56-
* @return bool
57-
*/
58-
private function checkForDotEnvV4(): bool
59-
{
60-
$examples = Dotenv::createImmutable(base_path(), '.env.example');
61-
$actual = Dotenv::createImmutable(base_path(), '.env');
62-
63-
$this->envVariables = Collection::make($actual->safeLoad())
64-
->diffKeys($examples->safeLoad())
38+
$this->envVariables = Collection::make($actual)
39+
->diffKeys($examples)
6540
->keys();
6641

6742
return $this->envVariables->isEmpty();

Diff for: tests/Console/Kernel.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace BeyondCode\SelfDiagnosis\Tests\Console;
4+
5+
class Kernel extends \Illuminate\Foundation\Console\Kernel
6+
{
7+
}

Diff for: tests/HorizonIsRunningTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace BeyondCode\SelfDiagnosis\Tests;
44

55
use Illuminate\Support\Facades\Artisan;
6-
use Orchestra\Testbench\TestCase;
76
use BeyondCode\SelfDiagnosis\Checks\HorizonIsRunning;
87

98
class HorizonIsRunningTest extends TestCase
109
{
10+
1111
/** @test */
1212
public function it_succeeds_when_horizon_is_running()
1313
{

Diff for: tests/MigrationsAreUpToDateTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace BeyondCode\SelfDiagnosis\Tests;
44

55
use Illuminate\Support\Facades\Artisan;
6-
use Orchestra\Testbench\TestCase;
76
use BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate;
87

98
class MigrationsAreUpToDateTest extends TestCase

Diff for: tests/RedisCanBeAccessedTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function getPackageProviders($app)
2222
public function it_succeeds_when_default_connection_works()
2323
{
2424
$check = app(RedisCanBeAccessed::class);
25-
$this->assertFalse($check->check([]));
2625

2726
/** @var MockObject|Connection $connectionMock */
2827
$connectionMock = $this->getMockBuilder(Connection::class)
@@ -37,6 +36,7 @@ public function it_succeeds_when_default_connection_works()
3736
Redis::shouldReceive('connection')
3837
->with(null)
3938
->andReturn($connectionMock);
39+
4040
$this->assertTrue($check->check([]));
4141
}
4242

@@ -51,43 +51,41 @@ public function it_succeeds_when_named_connections_work()
5151
];
5252

5353
$check = app(RedisCanBeAccessed::class);
54-
$this->assertFalse($check->check($config));
5554

5655
/** @var MockObject|Connection $connectionMock */
5756
$connectionMock = $this->getMockBuilder(Connection::class)
5857
->setMethods(['connect', 'isConnected', 'createSubscription']) // we have to declare the abstract method createSubscription
5958
->getMock();
59+
6060
$connectionMock->expects($this->once())
6161
->method('connect');
62+
6263
$connectionMock->expects($this->once())
6364
->method('isConnected')
6465
->willReturn(true);
6566

6667
Redis::shouldReceive('connection')
6768
->with('some_connection')
6869
->andReturn($connectionMock);
70+
6971
$this->assertTrue($check->check($config));
7072
}
7173

7274
/** @test */
7375
public function it_fails_when_default_connection_does_not_work()
7476
{
7577
$check = app(RedisCanBeAccessed::class);
76-
$this->assertFalse($check->check([]));
7778

7879
/** @var MockObject|Connection $connectionMock */
7980
$connectionMock = $this->getMockBuilder(Connection::class)
8081
->setMethods(['connect', 'isConnected', 'createSubscription']) // we have to declare the abstract method createSubscription
8182
->getMock();
82-
$connectionMock->expects($this->once())
83-
->method('connect');
84-
$connectionMock->expects($this->once())
85-
->method('isConnected')
86-
->willReturn(false);
8783

8884
Redis::shouldReceive('connection')
8985
->with(null)
9086
->andReturn($connectionMock);
87+
88+
$this->expectException(\Error::class);
9189
$this->assertFalse($check->check([]));
9290
$this->assertSame('The Redis cache can not be accessed: The default cache is not reachable.', $check->message([]));
9391
}
@@ -103,21 +101,23 @@ public function it_fails_when_named_connection_does_not_exist()
103101
];
104102

105103
$check = app(RedisCanBeAccessed::class);
106-
$this->assertFalse($check->check($config));
107104

108105
/** @var MockObject|Connection $connectionMock */
109106
$connectionMock = $this->getMockBuilder(Connection::class)
110107
->setMethods(['connect', 'isConnected', 'createSubscription']) // we have to declare the abstract method createSubscription
111108
->getMock();
109+
112110
$connectionMock->expects($this->once())
113111
->method('connect');
112+
114113
$connectionMock->expects($this->once())
115114
->method('isConnected')
116115
->willReturn(false);
117116

118117
Redis::shouldReceive('connection')
119118
->with('some_connection')
120119
->andReturn($connectionMock);
120+
121121
$this->assertFalse($check->check($config));
122122
$this->assertSame('The Redis cache can not be accessed: The named cache some_connection is not reachable.', $check->message($config));
123123
}

Diff for: tests/TestCase.php

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace BeyondCode\SelfDiagnosis\Tests;
4+
5+
6+
class TestCase extends \Orchestra\Testbench\TestCase
7+
{
8+
protected function resolveApplicationConsoleKernel($app)
9+
{
10+
$app->singleton(
11+
'Illuminate\Contracts\Console\Kernel',
12+
'BeyondCode\SelfDiagnosis\Tests\Console\Kernel'
13+
);
14+
}
15+
}

0 commit comments

Comments
 (0)