Skip to content

Commit

Permalink
Merge pull request #364 from bearsunday/app-interface
Browse files Browse the repository at this point in the history
#363 Enable AppInterface binding
  • Loading branch information
koriym authored Mar 17, 2021
2 parents 5eaa30d + b0302e3 commit 1f088e7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"aura/cli": "^2.2",
"bear/app-meta": "^1.6.2",
"bear/query-repository": "^1.6.10",
"bear/resource": "^1.15.3",
"bear/resource": "^1.15.4",
"bear/streamer": "^1.2.2",
"bear/sunday": "^1.5.3",
"bear/sunday": "^1.5.4",
"monolog/monolog": "^1.25 || ^2.0",
"ray/aop": "^2.10",
"ray/di": "^2.11.1",
"ray/di": "^2.12",
"ray/object-visual-grapher": "^1.0",
"psr/log": "^1.1",
"doctrine/cache": "^1.10",
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __invoke(AbstractAppMeta $appMeta, string $context, string $cach
$module = $this->installContextModule($appMeta, $contextItem, $module);
}

$module->override(new AppMetaModule($appMeta));
$module->install(new AppMetaModule($appMeta));
$module->override(new CacheNamespaceModule($cacheNamespace));

return $module;
Expand Down
8 changes: 4 additions & 4 deletions tests/InjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public function testCachedGetInstance(string $context, int $countOfNew): void
App::$counfOfNew = 0;
$injector = Injector::getInstance('FakeVendor\HelloWorld', $context, $appDir);
$app = $injector->getInstance(AppInterface::class);
assert($app instanceof App);
$this->assertInstanceOf(App::class, $app);
assert($app instanceof AppInterface);
$this->assertInstanceOf(AppInterface::class, $app);
$this->assertSame($countOfNew, App::$counfOfNew);
// 2nd injector; AppInterface object should be stored as a singleton.
$injector = Injector::getInstance('FakeVendor\HelloWorld', $context, $appDir);
$app = $injector->getInstance(AppInterface::class);
assert($app instanceof App);
$this->assertInstanceOf(App::class, $app);
assert($app instanceof AppInterface);
$this->assertInstanceOf(AppInterface::class, $app);
$this->assertSame($countOfNew, App::$counfOfNew);
}

Expand Down
14 changes: 7 additions & 7 deletions tests/NewAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace BEAR\Package;

use BEAR\AppMeta\AppMeta;
use BEAR\AppMeta\Meta;
use BEAR\Package\Context\CliModule;
use BEAR\Package\Module\AppMetaModule;
use BEAR\Sunday\Extension\Application\AppInterface;
use FakeVendor\HelloWorld\Module\App;
use FakeVendor\HelloWorld\Module\AppModule;
use FakeVendor\HelloWorld\Module\ProdModule;
use PHPUnit\Framework\TestCase;
Expand All @@ -18,19 +18,19 @@

class NewAppTest extends TestCase
{
public function testGetInstanceByHand(): App
public function testGetInstanceByHand(): AppInterface
{
$app = (new Injector(new AppMetaModule(new AppMeta('FakeVendor\HelloWorld'), new ProdModule(new CliModule(new AppModule()))), __DIR__ . '/tmp'))->getInstance(AppInterface::class);
$this->assertInstanceOf(App::class, $app);
$app = (new Injector(new AppMetaModule(new Meta('FakeVendor\HelloWorld'), new ProdModule(new CliModule(new AppModule()))), __DIR__ . '/tmp'))->getInstance(AppInterface::class);
$this->assertInstanceOf(AppInterface::class, $app);

return $app;
}

/**
* @depends testGetInstanceByHand
*/
public function testSerializable(App $app): void
public function testSerializable(AppInterface $app): void
{
$this->assertInstanceOf(App::class, unserialize(serialize($app)));
$this->assertInstanceOf(AppInterface::class, unserialize(serialize($app)));
}
}
3 changes: 1 addition & 2 deletions tests/script/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use BEAR\Package\Injector;
use BEAR\Resource\ResourceObject;
use BEAR\Sunday\Extension\Application\AppInterface;
use FakeVendor\HelloWorld\Module\App;

require dirname(__DIR__, 2) . '/vendor/autoload.php';
//require __DIR__ . '/benchmark.php';
Expand All @@ -15,7 +14,7 @@
$appDir = dirname(__DIR__) . '/Fake/fake-app';
$injector = Injector::getInstance('FakeVendor\HelloWorld', $context, $appDir);
$app = $injector->getInstance(AppInterface::class);
assert($app instanceof App);
assert($app instanceof AppInterface);
$ro = $app->resource->get('/');

exit((int) ! ($ro instanceof ResourceObject));

0 comments on commit 1f088e7

Please sign in to comment.