Skip to content

Commit

Permalink
Adds Collision
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Oct 12, 2017
1 parent 7e90855 commit 1ae6e9f
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [3.7.0] - 2017-10-12
### Added
- Added Collision listener to `phpunit.xml`.
- Core: Adds Collision.

## [3.6.11] - 2017-10-01
### Added
- Core: Adds `config_path` helper.
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
"mtdowling/cron-expression": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "~6.3",
"squizlabs/php_codesniffer": "^2.3"
"phpunit/phpunit": "~6.4",
"squizlabs/php_codesniffer": "^2.3",
"nunomaduro/collision": "^1.1"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<directory suffix="Test.php">./tests/Integration</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="NunoMaduro\Collision\Adapters\Phpunit\Listener"/>
</listeners>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
Expand Down
3 changes: 3 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Contracts\Container\Container as ContainerContract;
use LaravelZero\Framework\Contracts\Application as ApplicationContract;
use LaravelZero\Framework\Contracts\Providers\ErrorHandler as ErrorHandlerContract;

/**
* This is the Zero Framework application class.
Expand Down Expand Up @@ -81,6 +82,8 @@ protected function getCommandName(InputInterface $input)
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
$this->container->make(ErrorHandlerContract::class)->setOutput($output);

return parent::doRunCommand($this->runningCommand = $command, $input, $output);
}

Expand Down
17 changes: 11 additions & 6 deletions src/Bootstrappers/ServiceProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ServiceProviders extends Bootstrapper
* @var string[]
*/
protected $providers = [
Providers\ErrorHandler\ServiceProvider::class,
EventServiceProvider::class,
CacheServiceProvider::class,
Providers\Composer\ServiceProvider::class,
Expand Down Expand Up @@ -64,13 +65,17 @@ public function bootstrap(): void
)
->each(
function ($serviceProvider) {
$instance = new $serviceProvider($this->container);
if (method_exists($instance, 'register')) {
$instance->register();
$provider = new $serviceProvider($this->container);
if (method_exists($provider, 'register')) {
$provider->register();
}

if (method_exists($instance, 'boot')) {
$instance->boot();
}
)
->each(
function ($serviceProvider) {
$provider = new $serviceProvider($this->container);
if (method_exists($provider, 'boot')) {
$this->container->call([$provider, 'boot']);
}
}
);
Expand Down
25 changes: 25 additions & 0 deletions src/Contracts/Providers/ErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LaravelZero\Framework\Contracts\Providers;

use Symfony\Component\Console\Output\OutputInterface;

/**
* This is the Zero Framework ErrorHandler Contract.
*
* @author Nuno Maduro <[email protected]>
*/
interface ErrorHandler
{
/**
* Registers the error handler.
*/
public function register(): void;

/**
* Sets the output of the error handler.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
*/
public function setOutput(OutputInterface $output): void;
}
48 changes: 48 additions & 0 deletions src/Providers/ErrorHandler/ErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace LaravelZero\Framework\Providers\ErrorHandler;

use NunoMaduro\Collision\Provider;
use Symfony\Component\Console\Output\OutputInterface;
use NunoMaduro\Collision\Contracts\Provider as ProviderContract;
use LaravelZero\Framework\Contracts\Providers\ErrorHandler as ErrorHandlerContract;

/**
* This is the Zero Framework Error Handler class.
*
* @author Nuno Maduro <[email protected]>
*/
class ErrorHandler implements ErrorHandlerContract
{
/**
* @var \NunoMaduro\Collision\Contracts\Provider
*/
protected $provider;

/**
* Creates a new instance of the class.
*
* @param \NunoMaduro\Collision\Contracts\Provider|null $provider
*/
public function __construct(ProviderContract $provider = null)
{
$this->provider = $provider ?: new Provider;
}

/**
* @inheritdoc
*/
public function register(): void
{
$this->provider->register();
}

/**
* @inheritdoc
*/
public function setOutput(OutputInterface $output): void
{
$this->provider->getHandler()
->setOutput($output);
}
}
32 changes: 32 additions & 0 deletions src/Providers/ErrorHandler/ServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace LaravelZero\Framework\Providers\ErrorHandler;

use Illuminate\Support\ServiceProvider as BaseServiceProvider;
use LaravelZero\Framework\Contracts\Providers\ErrorHandler as ErrorHandlerContract;

/**
* This is the Zero Framework composer service provider class.
*
* @author Nuno Maduro <[email protected]>
*/
class ServiceProvider extends BaseServiceProvider
{
/**
* @inheritdoc
*/
public function boot(ErrorHandlerContract $errorHandler): void
{
$errorHandler->register();
}

/**
* @inheritdoc
*/
public function register(): void
{
$this->app->singleton(ErrorHandlerContract::class, function() {
return new ErrorHandler;
});
}
}
2 changes: 1 addition & 1 deletion tests/Integration/ApplicationTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\Unit;
namespace Tests\Integration;

use Tests\TestCase;
use Tests\FakeExtraCommand;
Expand Down
4 changes: 1 addition & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ abstract class TestCase extends BaseTestCase
protected $app;

/**
* Setup the test environment.
*
* @return void
* @inheritdoc
*/
protected function setUp(): void
{
Expand Down

0 comments on commit 1ae6e9f

Please sign in to comment.