Test the module, use class paths as container ids

This commit is contained in:
Jeremy Dormitzer 2019-01-19 22:37:07 -05:00
parent c36bca1adb
commit cab1f667f4
8 changed files with 81 additions and 36 deletions

View File

@ -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 );

View File

@ -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 ) );
}
/**

View File

@ -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
{

View File

@ -0,0 +1,38 @@
<?php
namespace ActivityPub\Test\Config;
use ActivityPub\Config\ActivityPubModule;
use ActivityPub\Http\ControllerResolver;
use Doctrine\ORM\EntityManager;
use PHPUnit\Framework\TestCase;
class ActivityPubModuleTest extends TestCase
{
private $module;
public function setUp()
{
$opts = array(
'dbOptions' => 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 );
}
}
?>

View File

@ -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;

View File

@ -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;

View File

@ -1,5 +1,5 @@
<?php
namespace ActivityPub\Test\Config;
namespace ActivityPub\Test\TestConfig;
use PHPUnit\DbUnit\DataSet\AbstractDataSet;
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;

View File

@ -1,5 +1,5 @@
<?php
namespace ActivityPub\Test\Config;
namespace ActivityPub\Test\TestConfig;
use ActivityPub\ActivityPub;
use PHPUnit\Framework\TestCase;