-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from mgcostaParedes/mgcosta_feat_facade
feat: facade class
- Loading branch information
Showing
6 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MgCosta\Spanner\Facade; | ||
|
||
use Google\Cloud\Spanner\Database; | ||
use MgCosta\Spanner\Builder\Builder; | ||
use MgCosta\Spanner\Manager\Manager; | ||
|
||
class SpannerDB | ||
{ | ||
/** | ||
* The spanner connection instance. | ||
* | ||
* @var Database; | ||
*/ | ||
protected $connection; | ||
|
||
public function __construct(Database $connection = null) | ||
{ | ||
$this->connection = $connection ?? Manager::getConnection(); | ||
} | ||
|
||
public function table(string $name): Builder | ||
{ | ||
return (new Builder($this->connection))->from($name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ | |
interface Manageable | ||
{ | ||
public function boot(); | ||
public static function getConnection(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Tests\unit; | ||
|
||
use Google\Cloud\Spanner\Database; | ||
use MgCosta\Spanner\Builder\Builder; | ||
use MgCosta\Spanner\Facade\SpannerDB; | ||
use Codeception\Test\Unit; | ||
use MgCosta\Spanner\Manager\Manager; | ||
use Mockery as m; | ||
|
||
class FacadeSpannerDBTest extends Unit | ||
{ | ||
private $facade; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
new Manager(m::mock(Database::class)); | ||
$this->facade = new SpannerDB(); | ||
} | ||
|
||
public function testShouldReturnAQueryBuilderInstanceWhenCallingWithinMethodTable() | ||
{ | ||
$this->assertInstanceOf(Builder::class, $this->facade->table('test')); | ||
} | ||
} |