Skip to content

Commit

Permalink
removed invokable from controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed Mar 15, 2016
1 parent 28b3f10 commit e859317
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 136 deletions.
33 changes: 27 additions & 6 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use ZfcTicketSystem\Controller;
use ZfcTicketSystem\Service;

return [
Expand Down Expand Up @@ -42,7 +43,7 @@
'zfcticketsystem_category_service' => Service\Category::class,
],
'factories' => [
Service\TicketSystem::class => function($sm) {
Service\TicketSystem::class => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
/** @noinspection PhpParamsInspection */
return new Service\TicketSystem(
Expand All @@ -52,21 +53,41 @@
$sm->get('zfcticketsystem_entry_options')
);
},
Service\Category::class => function($sm) {
Service\Category::class => function ($sm) {
/** @var $sm \Zend\ServiceManager\ServiceLocatorInterface */
/** @noinspection PhpParamsInspection */
return new Service\Category(
$sm->get('zfcticketsystem_admin_category_form'),
$sm->get('Doctrine\ORM\EntityManager'),
$sm->get('zfcticketsystem_entry_options')
);
}
},
],
],
'controllers' => [
'invokables' => [
'ZfcTicketSystem\Controller\TicketSystem' => 'ZfcTicketSystem\Controller\TicketSystemController',
'ZfcTicketSystem\Controller\Admin' => 'ZfcTicketSystem\Controller\AdminController',
'aliases' => [
'ZfcTicketSystem\Controller\TicketSystem' => Controller\TicketSystemController::class,
'ZfcTicketSystem\Controller\Admin' => Controller\AdminController::class,
],
'factories' => [
Controller\TicketSystemController::class => function ($sm) {
/** @var $sm \Zend\ServiceManager\AbstractPluginManager */
$config = $sm->getServiceLocator()->get('Config');
/** @noinspection PhpParamsInspection */
return new Controller\TicketSystemController(
$sm->getServiceLocator()->get('zfcticketsystem_ticketsystem_service'),
$sm->getServiceLocator()->get($config['zfc-ticket-system']['auth_service'])
);
},
Controller\AdminController::class => function ($sm) {
/** @var $sm \Zend\ServiceManager\AbstractPluginManager */
$config = $sm->getServiceLocator()->get('Config');
/** @noinspection PhpParamsInspection */
return new Controller\AdminController(
$sm->getServiceLocator()->get('zfcticketsystem_ticketsystem_service'),
$sm->getServiceLocator()->get($config['zfc-ticket-system']['auth_service'])
);
},
],
],
'doctrine' => [
Expand Down
42 changes: 42 additions & 0 deletions src/ZfcTicketSystem/Controller/AbstractController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace ZfcTicketSystem\Controller;

use Zend\Authentication\AuthenticationService;
use Zend\Mvc\Controller\AbstractActionController;
use ZfcTicketSystem\Service\TicketSystem;

class AbstractController extends AbstractActionController
{
/** @var TicketSystem */
protected $ticketService;
/** @var AuthenticationService */
protected $authService;

/**
* AbstractController constructor.
* @param TicketSystem $ticketService
* @param AuthenticationService $authService
*/
public function __construct(TicketSystem $ticketService, AuthenticationService $authService)
{
$this->ticketService = $ticketService;
$this->authService = $authService;
}

/**
* @return TicketSystem
*/
protected function getTicketService()
{
return $this->ticketService;
}

/**
* @return AuthenticationService
*/
protected function getAuthService()
{
return $this->authService;
}
}
2 changes: 1 addition & 1 deletion src/ZfcTicketSystem/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use ZfcTicketSystem\Entity\TicketSubject;

class AdminController extends BaseController
class AdminController extends AbstractController
{
/**
* @return array
Expand Down
38 changes: 0 additions & 38 deletions src/ZfcTicketSystem/Controller/BaseController.php

This file was deleted.

3 changes: 1 addition & 2 deletions src/ZfcTicketSystem/Controller/TicketSystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
use Zend\View\Model\ViewModel;
use ZfcTicketSystem\Entity\TicketSubject;

class TicketSystemController extends BaseController
class TicketSystemController extends AbstractController
{

/**
* @return ViewModel
*/
Expand Down
16 changes: 1 addition & 15 deletions tests/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
<?php

include __DIR__ . '/../vendor/autoload.php';

use ZfcTicketSystemTest\Util\ServiceManagerFactory;

ini_set('error_reporting', E_ALL);

if (file_exists(__DIR__ . '/TestConfig.php')) {
$config = require __DIR__ . '/TestConfig.php';
} else {
throw new \Exception('text config missing');
}

ServiceManagerFactory::setConfig($config);
unset($config);

include __DIR__ . '/../vendor/autoload.php';
13 changes: 0 additions & 13 deletions tests/TestConfig.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ZfcTicketSystemTest/Entity/TicketSubjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use SmallUser\Entity\User;
use ZfcTicketSystem\Entity\TicketCategory;
use ZfcTicketSystem\Entity\TicketSubject;
use ZfcTicketSystem\Entity\TicketEntry;
use ZfcTicketSystem\Entity\TicketSubject;

class TicketSubjectTest extends \PHPUnit_Framework_TestCase
{
Expand Down
45 changes: 0 additions & 45 deletions tests/ZfcTicketSystemTest/Util/ServiceManagerFactory.php

This file was deleted.

5 changes: 0 additions & 5 deletions tests/ZfcTicketSystemTest/Util/TestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@

class TestBase extends TestCase
{
/** @var \Zend\ServiceManager\ServiceManager */
protected $serviceManager;
/** @var string */
protected $className;

public function setUp()
{
parent::setUp();
$this->serviceManager = ServiceManagerFactory::getServiceManager();
}

/**
Expand All @@ -38,9 +35,7 @@ protected function getMethod($methodName)
protected function getClass($className = null)
{
$class = $className ? $className : $this->className;
/** @var \Zend\ServiceManager\ServiceManagerAwareInterface $class */
$class = new $class;
$class->setServiceManager($this->serviceManager);

return $class;
}
Expand Down
5 changes: 2 additions & 3 deletions tests/ZfcTicketSystemTest/View/Helper/TicketStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TicketStatusTest extends TestBase
public function testInvoke()
{
$this->assertContains('unknown', $this->getClass()->__invoke(-1));
$this->assertContains('unknown', $this->getClass()->__invoke(array('sdgdsg')));
$this->assertContains('unknown', $this->getClass()->__invoke(['sdgdsg']));
$this->assertNotContains('unknown', $this->getClass()->__invoke(1));
}

Expand All @@ -23,8 +23,7 @@ public function testInvoke()
*/
protected function getClass($className = null)
{
/** @var \Zend\ServiceManager\ServiceManagerAwareInterface $class */
$class = new $this->className($this->serviceManager);
$class = new $this->className();

return $class;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
processIsolation="false"
backupGlobals="false"
syntaxCheck="true"
>
>
<php>
<server name='HTTP_HOST' value='' />
<server name='HTTP_HOST' value=''/>
<server name="SERVER_NAME" value="http://foo.bar"/>
<server name="SERVER_PORT" value="80"/>
<server name="REMOTE_ADDR" value="127.1.2.3"/>
Expand Down
5 changes: 0 additions & 5 deletions tests/testing.config.php

This file was deleted.

0 comments on commit e859317

Please sign in to comment.