Skip to content

Commit

Permalink
Merge pull request #11 from mikemix/changes
Browse files Browse the repository at this point in the history
Update phpunit, use psr-11, improved test loading
  • Loading branch information
snapshotpl authored Aug 10, 2018
2 parents e1ba583 + a2b7039 commit 7361f00
Show file tree
Hide file tree
Showing 31 changed files with 199 additions and 243 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/vendor
/.idea
composer.phar
humbuglog.txt
phpunit.xml
composer.lock
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ build:
tests:
override:
-
command: 'phpunit --coverage-clover=clover.xml ./test/'
command: 'vendor/bin/phpunit --coverage-clover=clover.xml'
coverage:
file: 'clover.xml'
format: 'php-clover'
17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# Tactician ZF3 Module

Wrapper module for easy use of the [Tactician](http://tactician.thephpleague.com/) Command Bus in your ZF3 applications.
Wrapper module for easy use of the [Tactician](http://tactician.thephpleague.com/) Command Bus in your ZF3 or Expressive applications.

[![Build Status](https://travis-ci.org/mikemix/TacticianModule.svg?branch=master)](https://travis-ci.org/mikemix/TacticianModule) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mikemix/TacticianModule/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mikemix/TacticianModule/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/mikemix/TacticianModule/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/mikemix/TacticianModule/?branch=master) [![Dependency Status](https://www.versioneye.com/user/projects/556b5a106365320026fa4500/badge.svg?style=flat)](https://www.versioneye.com/user/projects/556b5a106365320026fa4500) [![Latest Stable Version](https://poser.pugx.org/mikemix/tactician-module/v/stable)](https://packagist.org/packages/mikemix/tactician-module) [![Total Downloads](https://poser.pugx.org/mikemix/tactician-module/downloads)](https://packagist.org/packages/mikemix/tactician-module) [![License](https://poser.pugx.org/mikemix/tactician-module/license)](https://packagist.org/packages/mikemix/tactician-module)

## Installation

Best install with Composer:

`composer require mikemix/tactician-module`
```
composer require mikemix/tactician-module
```

### Register as Zend Framework module inside your ```config/application.config.php``` file:
Register as Zend Framework module inside your ```config/application.config.php``` file using `TacticianModule` name.

```php
'modules' => [
'YourApplicationModule',
'TacticianModule',
],
```
You can also use this package as [Zend Expressive](https://docs.zendframework.com/zend-expressive/v3/features/modular-applications/) module by `TacticianModule\ConfigProvider`

## Using

Expand Down Expand Up @@ -109,8 +106,8 @@ To add custom middleware to the middleware stack, add it to the `middleware` arr
// ... your module config
'tactician' => [
'middleware' => [
YourCustomMiddleware::class => -100, // execute last
YourAnotherMiddleware::class => 100, // execute early
YourCustomMiddleware::class => 50, // execute last
],
],
```
Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"require": {
"php": "^5.6 || ^7.0",
"league/tactician": "^1.0",
"zendframework/zend-mvc": "^3.0",
"zendframework/zend-servicemanager": "^3.0"
"zendframework/zend-mvc": "^3.1.1",
"psr/container": "^1.0"
},
"require-dev": {
"league/tactician-doctrine": "^1.0",
"phpunit/phpunit": "^4.8.36",
"sebastian/comparator": "^1.2.4",
"phpunit/phpunit": "^5.7.27",
"doctrine/orm": "^2.5"
},
"keywords": [
Expand Down Expand Up @@ -39,8 +38,7 @@
},
"autoload-dev": {
"psr-4": {
"TacticianModuleTest\\": "test/",
"TestObjects\\": "test/"
"TacticianModuleTest\\": "test/"
}
},
"suggests": {
Expand Down
11 changes: 0 additions & 11 deletions humbug.json

This file was deleted.

4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<phpunit
bootstrap="./test/Bootstrap.php"
bootstrap="./vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
Expand All @@ -12,7 +12,7 @@
syntaxCheck="true"
>
<testsuite name="TacticianModule tests">
<directory>./test/TacticianModuleTest</directory>
<directory>./test</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
Expand Down
26 changes: 26 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
namespace TacticianModule;

class ConfigProvider
{
private $config;

public function __construct()
{
$this->config = (new Module())->getConfig();
}

public function __invoke()
{
$config = $this->config;

$config['dependencies'] = $config['service_manager'];

return $config;
}

public function getDependencies()
{
return $this->config['service_manager'];
}
}
8 changes: 6 additions & 2 deletions src/Controller/Plugin/TacticianCommandBusPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ public function __construct(CommandBus $commandBus)
$this->commandBus = $commandBus;
}

/**
* @param object|null $command
* @return CommandBus|mixed
*/
public function __invoke($command = null)
{
if (!$command) {
if ($command === null) {
return $this->commandBus;
}

return $this->commandBus->handle($command);
}
}
11 changes: 3 additions & 8 deletions src/Factory/CommandBusFactory.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<?php
namespace TacticianModule\Factory;

use Interop\Container\ContainerInterface;
use League\Tactician\CommandBus;
use League\Tactician\Middleware;
use Zend\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class CommandBusFactory implements FactoryInterface
class CommandBusFactory
{
/**
* Create service
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return CommandBus
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
$configMiddleware = $container->get('config')['tactician']['middleware'];

Expand Down
11 changes: 3 additions & 8 deletions src/Factory/CommandHandlerMiddlewareFactory.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
<?php
namespace TacticianModule\Factory;

use Interop\Container\ContainerInterface;
use League\Tactician\Handler\CommandHandlerMiddleware;
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor;
use League\Tactician\Handler\Locator\HandlerLocator;
use League\Tactician\Handler\MethodNameInflector\MethodNameInflector;
use Zend\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class CommandHandlerMiddlewareFactory implements FactoryInterface
class CommandHandlerMiddlewareFactory
{
/**
* Create service
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return CommandHandlerMiddleware
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config')['tactician'];

Expand Down
16 changes: 5 additions & 11 deletions src/Factory/Controller/Plugin/TacticianCommandBusPluginFactory.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
<?php
namespace TacticianModule\Factory\Controller\Plugin;

use Interop\Container\ContainerInterface;
use League\Tactician\CommandBus;
use Psr\Container\ContainerInterface;
use TacticianModule\Controller\Plugin\TacticianCommandBusPlugin;
use Zend\ServiceManager\Factory\FactoryInterface;
use Zend\ServiceManager\AbstractPluginManager;

class TacticianCommandBusPluginFactory implements FactoryInterface
class TacticianCommandBusPluginFactory
{
/**
* Create service
*
* @param ContainerInterface $pm
* @param string $requestedName
* @param array $options
* @param ContainerInterface $container
* @return TacticianCommandBusPlugin
*/
public function __invoke(ContainerInterface $pm, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
$commandBus = $pm->get(CommandBus::class);
$commandBus = $container->get(CommandBus::class);

return new TacticianCommandBusPlugin($commandBus);
}
Expand Down
11 changes: 3 additions & 8 deletions src/Factory/InMemoryLocatorFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?php
namespace TacticianModule\Factory;

use Interop\Container\ContainerInterface;
use League\Tactician\Handler\Locator\InMemoryLocator;
use Zend\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class InMemoryLocatorFactory implements FactoryInterface
class InMemoryLocatorFactory
{
/**
* Create service
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return InMemoryLocator
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
$handlerMap = $container->get('config')['tactician']['handler-map'];

Expand Down
11 changes: 3 additions & 8 deletions src/Factory/Plugin/DoctrineTransactionFactory.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<?php
namespace TacticianModule\Factory\Plugin;

use Interop\Container\ContainerInterface;
use League\Tactician\Doctrine\ORM\TransactionMiddleware;
use Zend\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class DoctrineTransactionFactory implements FactoryInterface
class DoctrineTransactionFactory
{
/**
* Create service
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return TransactionMiddleware
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
$config = $container->get('config')['tactician']['plugins'];
$ormKey = $config[TransactionMiddleware::class];
Expand Down
12 changes: 6 additions & 6 deletions src/Locator/ClassnameZendLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

use League\Tactician\Exception\MissingHandlerException;
use League\Tactician\Handler\Locator\HandlerLocator;
use Zend\ServiceManager\ServiceLocatorInterface;
use Psr\Container\ContainerInterface;

class ClassnameZendLocator implements HandlerLocator
{
private $serviceLocator;
private $container;

public function __construct(ServiceLocatorInterface $serviceLocator)
public function __construct(ContainerInterface $container)
{
$this->serviceLocator = $serviceLocator;
$this->container = $container;
}

/**
Expand All @@ -27,8 +27,8 @@ public function getHandlerForCommand($commandName)
{
$handlerFQCN = $commandName . 'Handler';

if ($this->serviceLocator->has($handlerFQCN)) {
return $this->serviceLocator->get($handlerFQCN);
if ($this->container->has($handlerFQCN)) {
return $this->container->get($handlerFQCN);
}

if (class_exists($handlerFQCN)) {
Expand Down
11 changes: 3 additions & 8 deletions src/Locator/ClassnameZendLocatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

namespace TacticianModule\Locator;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

class ClassnameZendLocatorFactory implements FactoryInterface
class ClassnameZendLocatorFactory
{
/**
* Create service
*
* @param ContainerInterface $container
* @param string $requestedName
* @param array $options
* @return ClassnameZendLocator
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
public function __invoke(ContainerInterface $container)
{
return new ClassnameZendLocator($container);
}
Expand Down
14 changes: 7 additions & 7 deletions src/Locator/ZendLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

use League\Tactician\Exception\MissingHandlerException;
use League\Tactician\Handler\Locator\HandlerLocator;
use Zend\ServiceManager\ServiceLocatorInterface;
use Psr\Container\ContainerInterface;

class ZendLocator implements HandlerLocator
{
/** @var array */
protected $handlerMap;

private $serviceLocator;
private $container;

public function __construct(ServiceLocatorInterface $serviceLocator)
public function __construct(ContainerInterface $container)
{
$this->serviceLocator = $serviceLocator;
$this->container = $container;
}

/**
Expand All @@ -34,8 +34,8 @@ public function getHandlerForCommand($commandName)

$serviceNameOrFQCN = $this->handlerMap[$commandName];

if ($this->serviceLocator->has($serviceNameOrFQCN)) {
return $this->serviceLocator->get($serviceNameOrFQCN);
if ($this->container->has($serviceNameOrFQCN)) {
return $this->container->get($serviceNameOrFQCN);
}

if (class_exists($serviceNameOrFQCN)) {
Expand All @@ -52,7 +52,7 @@ public function getHandlerForCommand($commandName)
protected function commandExists($commandName)
{
if (!$this->handlerMap) {
$this->handlerMap = $this->serviceLocator->get('config')['tactician']['handler-map'];
$this->handlerMap = $this->container->get('config')['tactician']['handler-map'];
}

return isset($this->handlerMap[$commandName]);
Expand Down
Loading

0 comments on commit 7361f00

Please sign in to comment.