From cab1f667f4e354b19ee48e3812e22563406a6ccf Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Sat, 19 Jan 2019 22:37:07 -0500 Subject: [PATCH] Test the module, use class paths as container ids --- src/ActivityPub.php | 12 +++-- src/Config/ActivityPubModule.php | 51 ++++++++++--------- test/ActivityPubTest.php | 4 +- test/Config/ActivityPubModuleTest.php | 38 ++++++++++++++ test/Entities/EntityTest.php | 4 +- test/Objects/ObjectsServiceTest.php | 4 +- test/{Config => TestConfig}/ArrayDataSet.php | 2 +- .../{Config => TestConfig}/SQLiteTestCase.php | 2 +- 8 files changed, 81 insertions(+), 36 deletions(-) create mode 100644 test/Config/ActivityPubModuleTest.php rename test/{Config => TestConfig}/ArrayDataSet.php (96%) rename test/{Config => TestConfig}/SQLiteTestCase.php (97%) diff --git a/src/ActivityPub.php b/src/ActivityPub.php index 5ba05ba..70b072d 100644 --- a/src/ActivityPub.php +++ b/src/ActivityPub.php @@ -3,7 +3,11 @@ namespace ActivityPub; require_once __DIR__ . '/../vendor/autoload.php'; +use ActivityPub\Auth\AuthListener; +use ActivityPub\Auth\SignatureListener; use ActivityPub\Config\ActivityPubModule; +use ActivityPub\Http\ControllerResolver; +use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\SchemaTool; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernel; @@ -45,11 +49,11 @@ class ActivityPub } $dispatcher = new EventDispatcher(); - $dispatcher->addSubscriber( $this->module->get( 'authListener' ) ); - $dispatcher->addSubscriber( $this->module->get( 'signatureListener' ) ); + $dispatcher->addSubscriber( $this->module->get( AuthListener::class ) ); + $dispatcher->addSubscriber( $this->module->get( SignatureListener::class ) ); $dispatcher->addSubscriber( new ExceptionListener() ); - $controllerResolver = $this->module->get( 'controllerResolver' ); + $controllerResolver = $this->module->get( ControllerResolver::class ); $argumentResolver = new ArgumentResolver(); $kernel = new HttpKernel( @@ -60,7 +64,7 @@ class ActivityPub public function updateSchema() { - $entityManager = $this->module->get( 'entityManager' ); + $entityManager = $this->module->get( EntityManager::class ); $schemaTool = new SchemaTool( $entityManager ); $classes = $entityManager->getMetadataFactory()->getAllMetadata(); $schemaTool->updateSchema( $classes ); diff --git a/src/Config/ActivityPubModule.php b/src/Config/ActivityPubModule.php index c49cd18..0051141 100644 --- a/src/Config/ActivityPubModule.php +++ b/src/Config/ActivityPubModule.php @@ -47,44 +47,47 @@ class ActivityPubModule $namingStrategy = new PrefixNamingStrategy( $options['dbPrefix'] ); $dbConfig->setNamingStrategy( $namingStrategy ); $dbParams = $options['dbOptions']; - $this->injector->register( 'entityManager', EntityManager::class ) + $this->injector->register( EntityManager::class, EntityManager::class ) ->setArguments( array( $dbParams, $dbConfig ) ) ->setFactory( array( EntityManager::class, 'create' ) ); - $this->injector->register( 'httpClient', Client::class ) + $this->injector->register( Client::class, Client::class ) ->addArgument( array( 'http_errors' => false ) ); - $this->injector->register( 'dateTimeProvider', SimpleDateTimeProvider::class ); + $this->injector->register( + SimpleDateTimeProvider::class, SimpleDateTimeProvider::class + ); - $this->injector->register( 'objectsService', ObjectsService::class ) - ->addArgument( new Reference( 'entityManager' ) ) - ->addArgument( new Reference( 'dateTimeProvider' ) ) - ->addArgument( new Reference( 'httpClient' ) ); + $this->injector->register( ObjectsService::class, ObjectsService::class ) + ->addArgument( new Reference( EntityManager::class ) ) + ->addArgument( new Reference( SimpleDateTimeProvider::class ) ) + ->addArgument( new Reference( Client::class ) ); - $this->injector->register( 'httpSignatureService', HttpSignatureService::class ) - ->addArgument( new Reference( 'dateTimeProvider' ) ); + $this->injector->register( + HttpSignatureService::class, HttpSignatureService::class + )->addArgument( new Reference( SimpleDateTimeProvider::class ) ); - $this->injector->register( 'signatureListener', SignatureListener::class ) - ->addArgument( new Reference( 'httpSignatureService' ) ) - ->addArgument( new Reference( 'objectsService' ) ); + $this->injector->register( SignatureListener::class, SignatureListener::class ) + ->addArgument( new Reference( HttpSignatureService::class ) ) + ->addArgument( new Reference( ObjectsService::class ) ); - $this->injector->register( 'authListener', AuthListener::class ) + $this->injector->register( AuthListener::class, AuthListener::class ) ->addArgument( $options['authFunction'] ); - $this->injector->register( 'getObjectController', GetObjectController::class ) - ->addArgument( new Reference( 'objectsService' ) ); + $this->injector->register( GetObjectController::class, GetObjectController::class ) + ->addArgument( new Reference( ObjectsService::class ) ); - $this->injector->register( 'inboxController', InboxController::class ) - ->addArgument( new Reference( 'objectsService' ) ); + $this->injector->register( InboxController::class, InboxController::class ) + ->addArgument( new Reference( ObjectsService::class ) ); - $this->injector->register( 'outboxController', OutboxController::class ) - ->addArgument( new Reference( 'objectsService' ) ); + $this->injector->register( OutboxController::class, OutboxController::class ) + ->addArgument( new Reference( ObjectsService::class ) ); - $this->injector->register( 'controllerResolver', ControllerResolver::class ) - ->addArgument( new Reference( 'objectsService' ) ) - ->addArgument( new Reference( 'getObjectController' ) ) - ->addArgument( new Reference( 'inboxController' ) ) - ->addArgument( new Reference( 'outboxController' ) ); + $this->injector->register( ControllerResolver::class, ControllerResolver::class ) + ->addArgument( new Reference( ObjectsService::class ) ) + ->addArgument( new Reference( GetObjectController::class ) ) + ->addArgument( new Reference( InboxController::class ) ) + ->addArgument( new Reference( OutboxController::class ) ); } /** diff --git a/test/ActivityPubTest.php b/test/ActivityPubTest.php index 4987db8..4f4503c 100644 --- a/test/ActivityPubTest.php +++ b/test/ActivityPubTest.php @@ -2,8 +2,8 @@ namespace ActivityPub\Test; use ActivityPub\ActivityPub; -use ActivityPub\Test\Config\SQLiteTestCase; -use ActivityPub\Test\Config\ArrayDataSet; +use ActivityPub\Test\TestConfig\SQLiteTestCase; +use ActivityPub\Test\TestConfig\ArrayDataSet; class ActivityPubTest extends SQLiteTestCase { diff --git a/test/Config/ActivityPubModuleTest.php b/test/Config/ActivityPubModuleTest.php new file mode 100644 index 0000000..06ba5aa --- /dev/null +++ b/test/Config/ActivityPubModuleTest.php @@ -0,0 +1,38 @@ + array( + 'driver' => 'pdo_sqlite', + 'path' => ':memory:', + ), + ); + $this->module = new ActivityPubModule( $opts ); + } + + public function testItInjects() + { + $entityManager = $this->module->get( EntityManager::class ); + $this->assertNotNull( $entityManager ); + $this->assertInstanceOf( EntityManager::class, $entityManager ); + } + + public function testItAutowires() + { + $controllerResolver = $this->module->get( ControllerResolver::class ); + $this->assertNotNull( $controllerResolver ); + $this->assertInstanceOf( ControllerResolver::class, $controllerResolver ); + } +} +?> diff --git a/test/Entities/EntityTest.php b/test/Entities/EntityTest.php index e47e508..c56cf17 100644 --- a/test/Entities/EntityTest.php +++ b/test/Entities/EntityTest.php @@ -5,8 +5,8 @@ use DateTime; use ActivityPub\Crypto\RsaKeypair; use ActivityPub\Entities\ActivityPubObject; use ActivityPub\Database\PrefixNamingStrategy; -use ActivityPub\Test\Config\ArrayDataSet; -use ActivityPub\Test\Config\SQLiteTestCase; +use ActivityPub\Test\TestConfig\ArrayDataSet; +use ActivityPub\Test\TestConfig\SQLiteTestCase; use ActivityPub\Test\TestUtils\TestDateTimeProvider; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Setup; diff --git a/test/Objects/ObjectsServiceTest.php b/test/Objects/ObjectsServiceTest.php index 25ed9e5..fd8440a 100644 --- a/test/Objects/ObjectsServiceTest.php +++ b/test/Objects/ObjectsServiceTest.php @@ -3,8 +3,8 @@ namespace ActivityPub\Test\Objects; use DateTime; use BadMethodCallException; -use ActivityPub\Test\Config\SQLiteTestCase; -use ActivityPub\Test\Config\ArrayDataSet; +use ActivityPub\Test\TestConfig\SQLiteTestCase; +use ActivityPub\Test\TestConfig\ArrayDataSet; use ActivityPub\Entities\ActivityPubObject; use ActivityPub\Entities\Field; use Doctrine\ORM\EntityManager; diff --git a/test/Config/ArrayDataSet.php b/test/TestConfig/ArrayDataSet.php similarity index 96% rename from test/Config/ArrayDataSet.php rename to test/TestConfig/ArrayDataSet.php index e79d3be..4599cad 100644 --- a/test/Config/ArrayDataSet.php +++ b/test/TestConfig/ArrayDataSet.php @@ -1,5 +1,5 @@