for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
/**
* @author Łukasz Chruściel <[email protected]>
final class CustomerContext implements Context
{
* @var RepositoryInterface
private $customerRepository;
* @var FactoryInterface
private $customerFactory;
* @param RepositoryInterface $customerRepository
* @param FactoryInterface $customerFactory
public function __construct(RepositoryInterface $customerRepository, FactoryInterface $customerFactory)
$this->customerRepository = $customerRepository;
$this->customerFactory = $customerFactory;
}
* @Transform :customer
public function getOrCreateCustomerByEmail($email)
/** @var CustomerInterface $customer */
$customer = $this->customerRepository->findOneBy(['email' => $email]);
if (null === $customer) {
$customer = $this->customerFactory->createNew();
$customer->setEmail($email);
$this->customerRepository->add($customer);
return $customer;