Skip to content

Commit

Permalink
[Jobs] moves RestClientFactory.php and JobsPublisherFactory.php into …
Browse files Browse the repository at this point in the history
…Factoty directory. Adds unittest.
  • Loading branch information
cbleek committed Mar 3, 2015
1 parent e64f1da commit 5a96fd3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 21 deletions.
2 changes: 0 additions & 2 deletions .scrutinizer.yml
@@ -1,4 +1,2 @@
tools:
external_code_coverage:
timeout: 600
runs: 4
Expand Up @@ -8,21 +8,29 @@
* @author weitz@cross-solution.de
*/

namespace Core\Service;
namespace Core\Factory\Service;

use Core\Service\RestClient;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

abstract class RestClientFactory implements FactoryInterface
{
/**
* @var array
*/
protected $config;

/**
* @var ServiceLocatorInterface
*/
protected $serviceLocator;

/**
* Create the settings service
*
* @param ServiceLocatorInterface $serviceLocator
* @return ControllerManager
* @return RestClient
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
Expand Down
2 changes: 1 addition & 1 deletion module/Jobs/config/module.config.php
Expand Up @@ -146,7 +146,7 @@
'factories' => array(
'Jobs\Form\Hydrator\OrganizationNameHydrator' => '\Jobs\Form\Hydrator\SLFactory\OrganizationNameHydratorSLFactory',
'Jobs/JsonJobsEntityHydrator' => 'Jobs\Entity\Hydrator\JsonJobsEntityHydratorFactory',
'Jobs/RestClient' => 'Jobs\Services\JobsPublisherFactory',
'Jobs/RestClient' => 'Jobs\Factory\Service\JobsPublisherFactory',
)
),

Expand Down
Expand Up @@ -8,14 +8,14 @@
* @author weitz@cross-solution.de
*/

namespace Jobs\Services;
namespace Jobs\Factory\Service;

use Core\Service\RestClientFactory;
use Core\Factory\Service\RestClientFactory;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Class RestClientFactory
* @package Jobs\Services
* Class JobsPublisherFactory
* @package Jobs\Factory\Service
*/
class JobsPublisherFactory extends RestClientFactory
{
Expand All @@ -25,10 +25,12 @@ class JobsPublisherFactory extends RestClientFactory
*/
protected $serviceLocator;



protected function getUri() {
$config = $this->getConfig();
if (!array_key_exists('uri', $config)) {
throw new \RuntimeException('uri for Rest-Server CamMediaintown is missing', 500);
throw new \RuntimeException('uri for Rest-Server YAWIK is missing', 500);
}
return $config['uri'];
}
Expand All @@ -49,7 +51,4 @@ protected function getConfig() {
}
return $this->config;
}



}
}
32 changes: 25 additions & 7 deletions module/Jobs/src/Jobs/Listener/Publisher.php
Expand Up @@ -21,47 +21,66 @@
use Zend\Stdlib\Hydrator\Filter\MethodMatchFilter;

/**
* Job listener for triggering actions like sending mail notification
* Job listener for publishing job opening via REST
*
* @package CamMediaintown\Listener
* @package Jobs\Listener
*/

class Publisher implements ListenerAggregateInterface, SharedListenerAggregateInterface, ServiceManagerAwareInterface
{
protected $serviceManager;

/**
* @param ServiceManager $serviceManager
* @return $this
*/
public function setServiceManager(ServiceManager $serviceManager) {
$this->serviceManager = $serviceManager;
return $this;
}

/**
* @return mixed
*/
public function getServiceManager() {
return $this->serviceManager;
}

/**
* @param EventManagerInterface $events
* @return $this
*/
public function attach(EventManagerInterface $events)
{
//$events->attach(JobEvent::EVENT_NEW, array($this, 'jobNewMail'), 1);
return $this;
}

/**
* @param SharedEventManagerInterface $events
*/
public function attachShared(SharedEventManagerInterface $events)
{
$events->attach('Jobs', JobEvent::EVENT_JOB_ACCEPTED, array($this, 'restPost'), 10);
return;
}


/**
* @param EventManagerInterface $events
* @return $this
*/
public function detach(EventManagerInterface $events)
{
return $this;
}

/**
* @param SharedEventManagerInterface $events
* @return $this
*/
public function detachShared(SharedEventManagerInterface $events) {
return $this;
}


/**
* allows an event attachment just by class
* @param JobEvent $e
Expand All @@ -87,7 +106,6 @@ public function restPost(JobEvent $e)
}
}
return;

}

}

@@ -0,0 +1,41 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013-2015 Cross Solution (http://cross-solution.de)
* @license MIT
*/

namespace Jobs\Factory\Service;

use Test\Bootstrap;

class JobsPublisherFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var JobsPublisherFactory
*/
private $testedObj;

public function setUp()
{
$this->testedObj = new JobsPublisherFactory();
}

public function testCreateService()
{
$sm = clone Bootstrap::getServiceManager();
$sm->setAllowOverride(true);


$config=$sm->get('Config');
$config['multiposting']=array("target"=> array("restServer"=> array("uri"=>"http://test.de",
'PHP_AUTH_USER'=>'user',
'PHP_AUTH_PW' => 'secret')));
$sm->setService('Config',$config);

$result = $this->testedObj->createService($sm);
$this->assertInstanceOf('Core\Service\RestClient', $result);
}
}

0 comments on commit 5a96fd3

Please sign in to comment.