Skip to content

Commit

Permalink
Add more Laravel specific package features
Browse files Browse the repository at this point in the history
  • Loading branch information
mpociot committed Feb 6, 2019
1 parent 9193237 commit 39476e3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
7 changes: 7 additions & 0 deletions config/chuck-norris.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [

'route' => '/chuck-norris'

];
5 changes: 5 additions & 0 deletions resources/views/joke.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h1>{{ $joke }}</h1>
</body>
</html>
16 changes: 16 additions & 0 deletions src/ChuckNorrisJokesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace Mpociot\ChuckNorrisJokes;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;
use Mpociot\ChuckNorrisJokes\Console\ChuckNorrisJoke;
use Mpociot\ChuckNorrisJokes\Http\Controllers\ChuckNorrisController;

class ChuckNorrisJokesServiceProvider extends ServiceProvider
{
Expand All @@ -14,12 +16,26 @@ public function boot()
ChuckNorrisJoke::class,
]);
}

$this->loadViewsFrom(__DIR__ . '/../resources/views', 'chuck-norris');

$this->publishes([
__DIR__.'/../resources/views' => resource_path('views/vendor/chuck-norris')
], 'views');

$this->publishes([
__DIR__.'/../config/chuck-norris.php' => base_path('config/chuck-norris.php')
], 'config');

Route::get(config('chuck-norris.route'), ChuckNorrisController::class);
}

public function register()
{
$this->app->bind('chuck-norris', function () {
return new JokeFactory();
});

$this->mergeConfigFrom(__DIR__.'/../config/chuck-norris.php', 'chuck-norris');
}
}
15 changes: 15 additions & 0 deletions src/Http/Controllers/ChuckNorrisController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Mpociot\ChuckNorrisJokes\Http\Controllers;

use Mpociot\ChuckNorrisJokes\Facades\ChuckNorris;

class ChuckNorrisController
{
public function __invoke()
{
return view('chuck-norris::joke', [
'joke' => ChuckNorris::getRandomJoke()
]);
}
}
13 changes: 13 additions & 0 deletions tests/LaravelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,17 @@ public function the_console_command_returns_a_joke()

$this->assertSame('some joke'.PHP_EOL, $output);
}

/** @test */
public function the_route_can_be_accessed()
{
ChuckNorris::shouldReceive('getRandomJoke')
->once()
->andReturn('some joke');

$this->get('/chuck-norris')
->assertViewIs('chuck-norris::joke')
->assertViewHas('joke', 'some joke')
->assertStatus(200);
}
}

0 comments on commit 39476e3

Please sign in to comment.