[Behat] Refactoring in zone transform context

This commit is contained in:
Arminek 2016-04-06 16:53:41 +02:00
parent f1828533be
commit c4964e9507

View file

@ -12,6 +12,7 @@
namespace Sylius\Behat\Context\Transform;
use Behat\Behat\Context\Context;
use Sylius\Component\Addressing\Model\ZoneInterface;
use Sylius\Component\Addressing\Repository\ZoneRepositoryInterface;
/**
@ -37,14 +38,17 @@ final class ZoneContext implements Context
* @Transform /^zone "([^"]+)"$/
* @Transform :zone
*/
public function getZoneByCode($zone)
public function getZoneByCode($code)
{
$existingZone = $this->zoneRepository->findOneBy(['code' => $zone]);
if (null === $existingZone) {
throw new \InvalidArgumentException(sprintf('Zone with code "%s" does not exist.', $zone));
}
return $this->getZoneBy(['code' => $code]);
}
return $existingZone;
/**
* @Transform /^zone named "([^"]+)"$/
*/
public function getZoneByName($name)
{
return $this->getZoneBy(['name' => $name]);
}
/**
@ -60,4 +64,19 @@ final class ZoneContext implements Context
return $zone;
}
/**
* @param array $parameters
*
* @return ZoneInterface
*/
private function getZoneBy(array $parameters)
{
$existingZone = $this->zoneRepository->findOneBy($parameters);
if (null === $existingZone) {
throw new \InvalidArgumentException(sprintf('Zone does not exist.'));
}
return $existingZone;
}
}