mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Behat] Refactoring in zone transform context
This commit is contained in:
parent
f1828533be
commit
c4964e9507
1 changed files with 25 additions and 6 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue