Skip to content

Commit

Permalink
Migrate Timber instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
joelambert committed Nov 12, 2024
1 parent d7a559e commit b976cf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
5 changes: 1 addition & 4 deletions src/Providers/TimberServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ class TimberServiceProvider extends ServiceProvider
{
public function register()
{
$timber = new Timber();

$this->app->bind('timber', $timber);
$this->app->bind(Timber::class, $timber);
Timber::init();
}

public function boot(Config $config)
Expand Down
26 changes: 16 additions & 10 deletions tests/Unit/Providers/TimberServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,25 @@

namespace Rareloop\Lumberjack\Test\Providers;

use Mockery;
use Brain\Monkey;
use Timber\Timber;
use Brain\Monkey\Functions;
use PHPUnit\Framework\TestCase;
use Rareloop\Lumberjack\Config;
use Rareloop\Lumberjack\Application;
use Rareloop\Lumberjack\Http\Lumberjack;
use Rareloop\Lumberjack\Bootstrappers\BootProviders;
use Rareloop\Lumberjack\Bootstrappers\RegisterProviders;
use Rareloop\Lumberjack\Config;
use Rareloop\Lumberjack\Http\Lumberjack;
use Rareloop\Lumberjack\Providers\TimberServiceProvider;
use Rareloop\Lumberjack\Test\Unit\BrainMonkeyPHPUnitIntegration;
use Timber\Timber;

/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
* The above is required as we're using alias mocks which persist between tests
* https://laracasts.com/discuss/channels/testing/mocking-a-class-persists-over-tests/replies/103075
*/
class TimberServiceProviderTest extends TestCase
{
use BrainMonkeyPHPUnitIntegration;
Expand All @@ -23,20 +30,20 @@ public function timber_plugin_is_initialiased()
{
Functions\expect('is_admin')->once()->andReturn(false);

$app = new Application(__DIR__.'/../');
$timber = Mockery::mock('alias:' . Timber::class);
$timber->shouldReceive('init')->once();

$app = new Application(__DIR__ . '/../');
$lumberjack = new Lumberjack($app);

$app->register(new TimberServiceProvider($app));
$lumberjack->bootstrap();

$this->assertTrue($app->has('timber'));
$this->assertSame($app->get('timber'), $app->get(Timber::class));
}

/** @test */
public function dirname_variable_is_set_from_config()
{
$app = new Application(__DIR__.'/../');
$app = new Application(__DIR__ . '/../');

$config = new Config;
$config->set('timber.paths', [
Expand All @@ -55,11 +62,10 @@ public function dirname_variable_is_set_from_config()

$app->register(new TimberServiceProvider($app));

$this->assertTrue($app->has('timber'));
$this->assertSame([
'path/one',
'path/two',
'path/three',
], $app->get('timber')::$dirname);
], Timber::$dirname);
}
}

0 comments on commit b976cf8

Please sign in to comment.