diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 98d9d31..67297f4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,8 +15,8 @@ jobs: fail-fast: false matrix: include: - - { php: "8.1", laravel: "^8.12.0", os: "ubuntu-latest" } - - { php: "8.1", laravel: "^8.12.0", os: "windows-latest" } + - { php: "8.1", laravel: "8.*", os: "ubuntu-latest" } + - { php: "8.1", laravel: "8.*", os: "windows-latest" } - { php: "8.1", laravel: "9.*", os: "ubuntu-latest" } - { php: "8.1", laravel: "9.*", os: "windows-latest" } - { php: "8.2", laravel: "9.*", os: "ubuntu-latest" } diff --git a/composer.json b/composer.json index 51f8c63..6b30bda 100644 --- a/composer.json +++ b/composer.json @@ -28,8 +28,9 @@ "illuminate/support": "^8.0|^9.0|^10.0|^11.0" }, "require-dev": { - "phpunit/phpunit": "^10.5", - "phpstan/phpstan": "^1.11" + "phpunit/phpunit": "^9.3.10|^10.0", + "phpstan/phpstan": "^1.11", + "orchestra/testbench": "^6.0|^7.0|^8.0|^9.0" }, "autoload": { "psr-4": { diff --git a/src/Middleware/IgnoreDevEnv.php b/src/Middleware/IgnoreDevEnv.php index bd635aa..6bc20a3 100644 --- a/src/Middleware/IgnoreDevEnv.php +++ b/src/Middleware/IgnoreDevEnv.php @@ -17,6 +17,11 @@ public function __construct(string $environment) public function __invoke($report): void { - $report->ignored = !($this->environment === 'local' || $this->environment === 'testing'); + $report->ignored = ($this->environment === 'local' || $this->environment === 'testing'); + } + + public function getWeight(): int + { + return -1000; } } diff --git a/src/TelebugsServiceProvider.php b/src/TelebugsServiceProvider.php index 9a1ac67..d24d1d1 100644 --- a/src/TelebugsServiceProvider.php +++ b/src/TelebugsServiceProvider.php @@ -16,7 +16,6 @@ class TelebugsServiceProvider extends ServiceProvider public function boot(): void { $this->publishes([ - // @phpstan-ignore-next-line __DIR__ . '/../config/telebugs.php' => base_path('config/telebugs.php'), ], 'config'); } @@ -33,7 +32,7 @@ public function register() $config->middleware()->use(new IgnoreDevEnv($app->environment())); }); - return new Reporter(); + return Reporter::getInstance(); }); $path = realpath(__DIR__ . '/../config/telebugs.php'); diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php new file mode 100644 index 0000000..1ca77ab --- /dev/null +++ b/tests/AbstractTestCase.php @@ -0,0 +1,25 @@ + + */ + protected function getPackageProviders($app): array + { + return [ + TelebugsServiceProvider::class, + ]; + } +} diff --git a/tests/Middleware/IgnoreDevEnvTest.php b/tests/Middleware/IgnoreDevEnvTest.php new file mode 100644 index 0000000..3cd4da4 --- /dev/null +++ b/tests/Middleware/IgnoreDevEnvTest.php @@ -0,0 +1,59 @@ +createMock(Report::class); + + $middleware = new IgnoreDevEnv("local"); + $middleware($report); + + $this->assertTrue($report->ignored); + } + + public function testIgnoreDevEnvIgnoresTestingEnvironment(): void + { + $report = $this->createMock(Report::class); + + $middleware = new IgnoreDevEnv("testing"); + $middleware($report); + + $this->assertTrue($report->ignored); + } + + public function testIgnoreDevEnvDoesNotIgnoreProductionEnvironment(): void + { + $report = $this->createMock(Report::class); + + $middleware = new IgnoreDevEnv("production"); + $middleware($report); + + $this->assertFalse($report->ignored); + } + + public function testIgnoreDevEnvDoesNotIgnoreStagingEnvironment(): void + { + $report = $this->createMock(Report::class); + + $middleware = new IgnoreDevEnv("staging"); + $middleware($report); + + $this->assertFalse($report->ignored); + } + + public function testWeight(): void + { + $middleware = new IgnoreDevEnv("local"); + + $this->assertSame(-1000, $middleware->getWeight()); + } +} diff --git a/tests/Middleware/ReporterInfoTest.php b/tests/Middleware/ReporterInfoTest.php new file mode 100644 index 0000000..10bdd36 --- /dev/null +++ b/tests/Middleware/ReporterInfoTest.php @@ -0,0 +1,31 @@ +createMock(Report::class); + + $middleware = new ReporterInfo($laravelVersion); + $middleware($report); + + $laravelReporter = $report->data["reporters"][0]; + + $this->assertSame("telebugs-laravel", $laravelReporter["library"]["name"]); + $this->assertSame( + \Telebugs\TelebugsLaravel\TelebugsLaravel::VERSION, + $laravelReporter["library"]["version"] + ); + $this->assertSame("Laravel", $laravelReporter["platform"]["name"]); + $this->assertSame($laravelVersion, $laravelReporter["platform"]["version"]); + } +} diff --git a/tests/TelebugsServiceProviderTest.php b/tests/TelebugsServiceProviderTest.php new file mode 100644 index 0000000..7204108 --- /dev/null +++ b/tests/TelebugsServiceProviderTest.php @@ -0,0 +1,31 @@ +app->getProvider(TelebugsServiceProvider::class); + $this->assertInstanceOf(ServiceProvider::class, $serviceProvider); + } + + public function testServiceProviderBoots() + { + $this->assertTrue($this->app->bound('telebugs')); + } + + public function testReporterInfoMiddlewareIsAttached() + { + $this->assertInstanceOf(Reporter::class, $this->app['telebugs']); + $this->assertEquals(4, count(Config::getInstance()->middleware()->getMiddlewares())); + } +}