Skip to content

Commit

Permalink
Merge pull request #117 from beyondcode/updates
Browse files Browse the repository at this point in the history
Laravel 11 compatibility & more
  • Loading branch information
mechelon authored Mar 14, 2024
2 parents e6d36fe + 71cccbc commit 99ec962
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 81 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ composer.lock
docs
vendor
coverage
.idea
.idea
.phpunit.result.cache
.phpunit.cache
.vscode
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Perform Self-Diagnosis Tests On Your Laravel Application

[![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)
[![Build Status](https://img.shields.io/travis/beyondcode/laravel-self-diagnosis/master.svg?style=flat-square)](https://travis-ci.org/beyondcode/laravel-self-diagnosis)
[![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)
[![Total Downloads](https://img.shields.io/packagist/dt/beyondcode/laravel-self-diagnosis.svg?style=flat-square)](https://packagist.org/packages/beyondcode/laravel-self-diagnosis)

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.
Expand Down Expand Up @@ -50,8 +48,6 @@ You can install the package via composer:
composer require beyondcode/laravel-self-diagnosis
```

If you're using Laravel 5.5+ the `SelfDiagnosisServiceProvider` will be automatically registered for you.

## Usage

Just call the artisan command to start the checks:
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
}
],
"require": {
"php": "^7.1|^8.0",
"php": "^8.2",
"composer/semver": "^1.4|^3.0",
"geerlingguy/ping": "^1.1",
"illuminate/support": "5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0|^8.0",
"vlucas/phpdotenv": "~2.5|~3.3|^4.0|^5.0"
"illuminate/support": "^9.0|^10.0|^11.0",
"vlucas/phpdotenv": "^5.0"
},
"require-dev": {
"larapack/dd": "^1.0",
"mockery/mockery": "^1.0",
"orchestra/testbench": "~3.5|~3.8",
"phpunit/phpunit": "^7.0|^8.0",
"orchestra/testbench": "^7.0|^8.0",
"phpunit/phpunit": "^9.5.10",
"predis/predis": "^1.1",
"scrutinizer/ocular": "^1.5"
},
Expand Down
43 changes: 16 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
<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">
<coverage>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/report.junit.xml"/>
</logging>
</phpunit>
29 changes: 29 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="BeyondCode Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
6 changes: 5 additions & 1 deletion src/Checks/ComposerWithDevDependenciesIsUpToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function check(array $config): bool

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

return Str::contains($this->output, ['Nothing to install or update', 'Nothing to install, update or remove']);
return Str::contains($this->output, [
'Nothing to install or update',
'Nothing to install, update or remove',
'Package operations: 0 installs, 0 updates, 0 removals'
]);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/Checks/ComposerWithoutDevDependenciesIsUpToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public function check(array $config): bool

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

return Str::contains($this->output, ['Nothing to install or update', 'Nothing to install, update or remove']);
return Str::contains($this->output, [
'Nothing to install or update',
'Nothing to install, update or remove',
'Package operations: 0 installs, 0 updates, 0 removals'
]);
}

/**
Expand Down
37 changes: 6 additions & 31 deletions src/Checks/ExampleEnvironmentVariablesAreUpToDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,14 @@ public function name(array $config): string
*/
public function check(array $config): bool
{
if (method_exists(Dotenv::class, 'createImmutable')) {
return $this->checkForDotEnvV4();
}
$examples = Dotenv::createMutable(base_path(), '.env.example');
$examples = $examples->safeLoad();

if (interface_exists(\Dotenv\Environment\FactoryInterface::class)) {
$examples = Dotenv::create(base_path(), '.env.example');
$actual = Dotenv::create(base_path(), '.env');
} else {
$examples = new Dotenv(base_path(), '.env.example');
$actual = new Dotenv(base_path(), '.env');
}
$actual = Dotenv::createMutable(base_path(), '.env');
$actual = $actual->safeLoad();

$examples->safeLoad();
$actual->safeLoad();

$this->envVariables = Collection::make($actual->getEnvironmentVariableNames())
->diff($examples->getEnvironmentVariableNames());

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

/**
* Perform the verification of this check for DotEnv v4.
*
* @return bool
*/
private function checkForDotEnvV4(): bool
{
$examples = Dotenv::createImmutable(base_path(), '.env.example');
$actual = Dotenv::createImmutable(base_path(), '.env');

$this->envVariables = Collection::make($actual->safeLoad())
->diffKeys($examples->safeLoad())
$this->envVariables = Collection::make($actual)
->diffKeys($examples)
->keys();

return $this->envVariables->isEmpty();
Expand Down
7 changes: 7 additions & 0 deletions tests/Console/Kernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace BeyondCode\SelfDiagnosis\Tests\Console;

class Kernel extends \Illuminate\Foundation\Console\Kernel
{
}
2 changes: 1 addition & 1 deletion tests/HorizonIsRunningTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
namespace BeyondCode\SelfDiagnosis\Tests;

use Illuminate\Support\Facades\Artisan;
use Orchestra\Testbench\TestCase;
use BeyondCode\SelfDiagnosis\Checks\HorizonIsRunning;

class HorizonIsRunningTest extends TestCase
{

/** @test */
public function it_succeeds_when_horizon_is_running()
{
Expand Down
1 change: 0 additions & 1 deletion tests/MigrationsAreUpToDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace BeyondCode\SelfDiagnosis\Tests;

use Illuminate\Support\Facades\Artisan;
use Orchestra\Testbench\TestCase;
use BeyondCode\SelfDiagnosis\Checks\MigrationsAreUpToDate;

class MigrationsAreUpToDateTest extends TestCase
Expand Down
18 changes: 9 additions & 9 deletions tests/RedisCanBeAccessedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function getPackageProviders($app)
public function it_succeeds_when_default_connection_works()
{
$check = app(RedisCanBeAccessed::class);
$this->assertFalse($check->check([]));

/** @var MockObject|Connection $connectionMock */
$connectionMock = $this->getMockBuilder(Connection::class)
Expand All @@ -37,6 +36,7 @@ public function it_succeeds_when_default_connection_works()
Redis::shouldReceive('connection')
->with(null)
->andReturn($connectionMock);

$this->assertTrue($check->check([]));
}

Expand All @@ -51,43 +51,41 @@ public function it_succeeds_when_named_connections_work()
];

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

/** @var MockObject|Connection $connectionMock */
$connectionMock = $this->getMockBuilder(Connection::class)
->setMethods(['connect', 'isConnected', 'createSubscription']) // we have to declare the abstract method createSubscription
->getMock();

$connectionMock->expects($this->once())
->method('connect');

$connectionMock->expects($this->once())
->method('isConnected')
->willReturn(true);

Redis::shouldReceive('connection')
->with('some_connection')
->andReturn($connectionMock);

$this->assertTrue($check->check($config));
}

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

/** @var MockObject|Connection $connectionMock */
$connectionMock = $this->getMockBuilder(Connection::class)
->setMethods(['connect', 'isConnected', 'createSubscription']) // we have to declare the abstract method createSubscription
->getMock();
$connectionMock->expects($this->once())
->method('connect');
$connectionMock->expects($this->once())
->method('isConnected')
->willReturn(false);

Redis::shouldReceive('connection')
->with(null)
->andReturn($connectionMock);

$this->expectException(\Error::class);
$this->assertFalse($check->check([]));
$this->assertSame('The Redis cache can not be accessed: The default cache is not reachable.', $check->message([]));
}
Expand All @@ -103,21 +101,23 @@ public function it_fails_when_named_connection_does_not_exist()
];

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

/** @var MockObject|Connection $connectionMock */
$connectionMock = $this->getMockBuilder(Connection::class)
->setMethods(['connect', 'isConnected', 'createSubscription']) // we have to declare the abstract method createSubscription
->getMock();

$connectionMock->expects($this->once())
->method('connect');

$connectionMock->expects($this->once())
->method('isConnected')
->willReturn(false);

Redis::shouldReceive('connection')
->with('some_connection')
->andReturn($connectionMock);

$this->assertFalse($check->check($config));
$this->assertSame('The Redis cache can not be accessed: The named cache some_connection is not reachable.', $check->message($config));
}
Expand Down
15 changes: 15 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace BeyondCode\SelfDiagnosis\Tests;


class TestCase extends \Orchestra\Testbench\TestCase
{
protected function resolveApplicationConsoleKernel($app)
{
$app->singleton(
'Illuminate\Contracts\Console\Kernel',
'BeyondCode\SelfDiagnosis\Tests\Console\Kernel'
);
}
}

0 comments on commit 99ec962

Please sign in to comment.