From 46e6b1e5d35a47571720dfa5c963dd96d5a254bb Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 28 Feb 2017 17:01:25 +0900 Subject: [PATCH] Cleanup (#226) * add phpdoc * add app object test * fix cs * update composer.json --- composer.json | 30 +++++++++++++------ src/AppMetaModule.php | 3 +- src/Bootstrap.php | 18 +++++++++-- src/Provide/Transfer/CliResponder.php | 2 +- tests/Fake/FakeRouter.php | 2 ++ tests/Fake/fake-app/src/Resource/App/Task.php | 1 + tests/Fake/fake-app/src/Resource/App/User.php | 1 + tests/NewAppTest.php | 30 +++++++++++++++++++ 8 files changed, 74 insertions(+), 13 deletions(-) create mode 100644 tests/NewAppTest.php diff --git a/composer.json b/composer.json index 80b497b9..b9b93451 100644 --- a/composer.json +++ b/composer.json @@ -6,11 +6,8 @@ "DI", "AOP", "REST", - "framework", - "hypermedia", - "API" + "framework" ], - "homepage": "https://github.com/koriym/BEAR.Package", "license": "MIT", "authors": [ { @@ -24,14 +21,29 @@ "bear/app-meta": "^1.0", "bear/query-repository": "^1.2", "bear/sunday": "^1.1", - "ray/web-param-module": "~1.0" + "ray/web-param-module": "^1.0" }, "autoload": { "psr-4": { "BEAR\\Package\\": "src/" } }, - "bin": [ - "bin/bear.env" - ] -} + "scripts" :{ + "test": [ + "phpmd src text ./phpmd.xml", + "phpcs src tests", + "phpunit" + ], + "cs-fix": [ + "php-cs-fixer fix --config-file=./.php_cs", + "phpcbf src" + ], + "build": [ + "rm -rf ./build; mkdir -p ./build/logs ./build/pdepend ./build/api", + "pdepend --jdepend-xml=./build/logs/jdepend.xml --jdepend-chart=./build/pdepend/dependencies.svg --overview-pyramid=./build/pdepend/overview-pyramid.svg src", + "phploc --log-csv ./build/logs/phploc.csv src", + "phpcs --report=checkstyle --report-file=./build/logs/checkstyle.xml --standard=phpcs.xml src", + "apigen generate -s src -d build/api", + "@test" + ] + }} diff --git a/src/AppMetaModule.php b/src/AppMetaModule.php index 5f9c0ea3..1adba202 100644 --- a/src/AppMetaModule.php +++ b/src/AppMetaModule.php @@ -18,9 +18,10 @@ class AppMetaModule extends AbstractModule */ private $appMeta; - public function __construct(AbstractAppMeta $appMeta) + public function __construct(AbstractAppMeta $appMeta, AbstractModule $module = null) { $this->appMeta = $appMeta; + parent::__construct($module); } /** diff --git a/src/Bootstrap.php b/src/Bootstrap.php index ee1bf096..7207e4f7 100644 --- a/src/Bootstrap.php +++ b/src/Bootstrap.php @@ -20,13 +20,25 @@ use Ray\Compiler\ScriptInjector; use Ray\Di\AbstractModule; +/** + * Bootstrap + * + * Create an app object that contains all the objects used in the bootstrap script The bootstrap script uses the public + * property of $ app to run the application. + * + * AppModule knows the binding of all interfaces. Other context modules override bindings on the interface. For example, + * `app` binds JsonRenderer and outputs JSON. In` html-prod`, HtmlModule overwrites the binding on TwigRenderer and + * outputs html. + */ final class Bootstrap { /** * Return application instance by name and contexts * - * @param string $name application name (Vendor.Package) - * @param string $contexts application context (prd-html-app) + * Use newApp() instead for your own AppMeta and Cache. + * + * @param string $name application name 'koriym\blog' (vendor\package) + * @param string $contexts application context 'prd-html-app' * * @return AbstractApp */ @@ -36,6 +48,8 @@ public function getApp($name, $contexts) } /** + * Return application instance by AppMeta and Cache + * * @param AbstractAppMeta $appMeta * @param string $contexts * @param Cache $cache diff --git a/src/Provide/Transfer/CliResponder.php b/src/Provide/Transfer/CliResponder.php index d4844b08..14e5208a 100644 --- a/src/Provide/Transfer/CliResponder.php +++ b/src/Provide/Transfer/CliResponder.php @@ -27,7 +27,7 @@ public function __invoke(ResourceObject $resourceObject, array $server) $ob .= "{$label}: {$value}" . PHP_EOL; } // empty line - $ob .= PHP_EOL; + $ob .= PHP_EOL; // body $ob .= $body; diff --git a/tests/Fake/FakeRouter.php b/tests/Fake/FakeRouter.php index 73c01622..2a66b67e 100644 --- a/tests/Fake/FakeRouter.php +++ b/tests/Fake/FakeRouter.php @@ -18,6 +18,8 @@ public function match(array $globals, array $server) */ public function generate($name, $data) { + unset($name); + return '/task/' . $data['id']; } } diff --git a/tests/Fake/fake-app/src/Resource/App/Task.php b/tests/Fake/fake-app/src/Resource/App/Task.php index 11c5d64e..13af2f3e 100644 --- a/tests/Fake/fake-app/src/Resource/App/Task.php +++ b/tests/Fake/fake-app/src/Resource/App/Task.php @@ -8,6 +8,7 @@ class Task extends ResourceObject { public function onGet($id = null) { + unset($id); $this->headers['Location'] = '/self?id=10'; return $this; diff --git a/tests/Fake/fake-app/src/Resource/App/User.php b/tests/Fake/fake-app/src/Resource/App/User.php index 26b51539..b6e4eb0c 100644 --- a/tests/Fake/fake-app/src/Resource/App/User.php +++ b/tests/Fake/fake-app/src/Resource/App/User.php @@ -13,6 +13,7 @@ class User extends ResourceObject */ public function onGet($id, $type = 'defaultType') { + unset($type); $this['id'] = $id; $this['friend_id'] = 'f' . $id; $this['org_id'] = 'o' . $id; diff --git a/tests/NewAppTest.php b/tests/NewAppTest.php new file mode 100644 index 00000000..fd46c2e2 --- /dev/null +++ b/tests/NewAppTest.php @@ -0,0 +1,30 @@ +getInstance(AppInterface::class); + $this->assertInstanceOf(App::class, $app); + + return $app; + } + + /** + * @depends testGetInstanceByHand + */ + public function testSerializable(App $app) + { + $this->assertInstanceOf(App::class, unserialize(serialize($app))); + } +}