Skip to content

Commit

Permalink
Make sure the Bento class is always a singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
xel1045 committed Oct 9, 2019
1 parent 5b0d7f5 commit f095b29
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/BentoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function boot(): void
*/
public function register(): void
{
$this->app->singleton('bento', Bento::class);
$this->app->singleton(Bento::class);

$this->app->alias(Bento::class, 'bento');
}
}
31 changes: 31 additions & 0 deletions tests/Integration/BentoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Exolnet\Bento\Tests\Integration;

use Exolnet\Bento\Bento;
use Exolnet\Bento\Tests\IntegrationTest;

class BentoTest extends IntegrationTest
{
/**
* @return void
*/
public function testIsSingleton(): void
{
$instance1 = $this->app->make(Bento::class);
$instance2 = $this->app->make(Bento::class);

$this->assertSame($instance1, $instance2);
}

/**
* @return void
*/
public function testAlias(): void
{
$instance = $this->app->make(Bento::class);
$alias = $this->app->make('bento');

$this->assertSame($instance, $alias);
}
}

0 comments on commit f095b29

Please sign in to comment.