Remove container in Customer listener. #198

This commit is contained in:
Manuel Raynaud
2014-01-31 11:03:53 +01:00
parent 485816cc4c
commit 3fb0dfe1db
3 changed files with 27 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ use Thelia\Core\Event\ActionEvent;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\Event\Customer\CustomerEvent; use Thelia\Core\Event\Customer\CustomerEvent;
use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Event\TheliaEvents;
use Thelia\Core\Security\SecurityContext;
use Thelia\Model\Customer as CustomerModel; use Thelia\Model\Customer as CustomerModel;
use Thelia\Core\Event\Customer\CustomerLoginEvent; use Thelia\Core\Event\Customer\CustomerLoginEvent;
@@ -39,8 +40,14 @@ use Thelia\Core\Event\Customer\CustomerLoginEvent;
* @package Thelia\Action * @package Thelia\Action
* @author Manuel Raynaud <mraynaud@openstudio.fr> * @author Manuel Raynaud <mraynaud@openstudio.fr>
*/ */
class Customer extends BaseAction implements EventSubscriberInterface class Customer implements EventSubscriberInterface
{ {
protected $securityContext;
public function __construct(SecurityContext $securityContext)
{
$this->securityContext = $securityContext;
}
public function create(CustomerCreateOrUpdateEvent $event) public function create(CustomerCreateOrUpdateEvent $event)
{ {
@@ -65,7 +72,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
$customer = $event->getCustomer(); $customer = $event->getCustomer();
$customer->setDispatcher($this->getDispatcher()); $customer->setDispatcher($event->getDispatcher());
$customer $customer
->setTitleId($event->getTitle()) ->setTitleId($event->getTitle())
@@ -91,7 +98,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event) private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event)
{ {
$customer->setDispatcher($this->getDispatcher()); $customer->setDispatcher($event->getDispatcher());
$customer->createOrUpdate( $customer->createOrUpdate(
$event->getTitle(), $event->getTitle(),
@@ -140,7 +147,7 @@ class Customer extends BaseAction implements EventSubscriberInterface
*/ */
protected function getSecurityContext() protected function getSecurityContext()
{ {
return $this->container->get('thelia.securityContext'); return $this->securityContext;
} }
/** /**

View File

@@ -16,8 +16,8 @@
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </service>
<service id="thelia.action.customer" class="Thelia\Action\Customer"> <service id="thelia.action.customer" class="Thelia\Action\Customer" scope="request">
<argument type="service" id="service_container"/> <argument type="service" id="thelia.securityContext"/>
<tag name="kernel.event_subscriber"/> <tag name="kernel.event_subscriber"/>
</service> </service>

View File

@@ -24,6 +24,9 @@
namespace Thelia\Tests\Action\ImageTest; namespace Thelia\Tests\Action\ImageTest;
use Thelia\Action\Customer; use Thelia\Action\Customer;
use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent; use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Security\SecurityContext;
use Thelia\Model\CustomerQuery;
/** /**
* Class CustomerTest * Class CustomerTest
@@ -32,15 +35,12 @@ use Thelia\Core\Event\Customer\CustomerCreateOrUpdateEvent;
*/ */
class CustomerTest extends \PHPUnit_Framework_TestCase class CustomerTest extends \PHPUnit_Framework_TestCase
{ {
public function getContainer()
public static function setUpBeforeClass()
{ {
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder(); CustomerQuery::create()
->filterByRef('testRef')
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"); ->delete();
$container->set("event_dispatcher", $dispatcher);
return $container;
} }
public function testCreatedCustomer() public function testCreatedCustomer()
@@ -67,7 +67,9 @@ class CustomerTest extends \PHPUnit_Framework_TestCase
null null
); );
$customerAction = new Customer($this->getContainer()); $customerCreateEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$customerAction = new Customer(new SecurityContext(new Request()));
$customerAction->create($customerCreateEvent); $customerAction->create($customerCreateEvent);
@@ -126,7 +128,9 @@ class CustomerTest extends \PHPUnit_Framework_TestCase
'testRef' 'testRef'
); );
$customerAction = new Customer($this->getContainer()); $customerCreateEvent->setDispatcher($this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface"));
$customerAction = new Customer(new SecurityContext(new Request()));
$customerAction->create($customerCreateEvent); $customerAction->create($customerCreateEvent);