Test the module, use class paths as container ids
This commit is contained in:
parent
c36bca1adb
commit
cab1f667f4
@ -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 );
|
||||
|
@ -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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
{
|
||||
|
38
test/Config/ActivityPubModuleTest.php
Normal file
38
test/Config/ActivityPubModuleTest.php
Normal 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 );
|
||||
}
|
||||
}
|
||||
?>
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\Config;
|
||||
namespace ActivityPub\Test\TestConfig;
|
||||
|
||||
use PHPUnit\DbUnit\DataSet\AbstractDataSet;
|
||||
use PHPUnit\DbUnit\DataSet\DefaultTableMetadata;
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
namespace ActivityPub\Test\Config;
|
||||
namespace ActivityPub\Test\TestConfig;
|
||||
|
||||
use ActivityPub\ActivityPub;
|
||||
use PHPUnit\Framework\TestCase;
|
Loading…
Reference in New Issue
Block a user