作者:TheMadelein
项目:Syliu
function it_creates_a_default_united_states_channel_with_country_zone_and_usd_as_default_currency(RepositoryInterface $channelRepository, RepositoryInterface $countryRepository, RepositoryInterface $currencyRepository, RepositoryInterface $localeRepository, RepositoryInterface $zoneMemberRepository, RepositoryInterface $zoneRepository, ChannelFactoryInterface $channelFactory, FactoryInterface $countryFactory, FactoryInterface $currencyFactory, FactoryInterface $localeFactory, FactoryInterface $zoneFactory, FactoryInterface $zoneMemberFactory, ZoneMemberInterface $zoneMember, ZoneInterface $zone, ChannelInterface $channel, CountryInterface $unitedStates, CurrencyInterface $currency, LocaleInterface $locale)
{
$channel->getName()->willReturn('United States');
$channelFactory->createNamed('United States')->willReturn($channel);
$localeFactory->createNew()->willReturn($locale);
$locale->setCode('en_US')->shouldBeCalled();
$zoneMemberFactory->createNew()->willReturn($zoneMember);
$zoneFactory->createNew()->willReturn($zone);
$channel->setCode('WEB-US')->shouldBeCalled();
$channel->setTaxCalculationStrategy('order_items_based')->shouldBeCalled();
$zoneMember->setCode('US')->shouldBeCalled();
$zone->setCode('US')->shouldBeCalled();
$zone->setName('United States')->shouldBeCalled();
$zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled();
$zone->addMember($zoneMember)->shouldBeCalled();
$countryFactory->createNew()->willReturn($unitedStates);
$unitedStates->setCode('US')->shouldBeCalled();
$currencyFactory->createNew()->willReturn($currency);
$currency->setCode('USD')->shouldBeCalled();
$currency->setExchangeRate(1.0)->shouldBeCalled();
$channel->setDefaultCurrency($currency)->shouldBeCalled();
$channel->addCurrency($currency)->shouldBeCalled();
$channel->setDefaultLocale($locale)->shouldBeCalled();
$channel->addLocale($locale)->shouldBeCalled();
$currencyRepository->findOneBy(['code' => 'USD'])->willReturn(null);
$localeRepository->findOneBy(['code' => 'en_US'])->willReturn(null);
$currencyRepository->add($currency)->shouldBeCalled();
$localeRepository->add($locale)->shouldBeCalled();
$countryRepository->add($unitedStates)->shouldBeCalled();
$channelRepository->add($channel)->shouldBeCalled();
$zoneRepository->add($zone)->shouldBeCalled();
$zoneMemberRepository->add($zoneMember)->shouldBeCalled();
$this->create();
}
作者:Strontium-9
项目:Syliu
function it_calls_proper_method_with_arguments_based_on_configuration(RepositoryInterface $repository, $configuration)
{
$configuration->getRepositoryMethod('findBy')->willReturn('findAll');
$configuration->getRepositoryArguments(array())->willReturn(array(5));
$repository->findAll(5)->shouldBeCalled()->willReturn(array('foo', 'bar'));
$this->getResource($repository, 'findBy')->shouldReturn(array('foo', 'bar'));
}
作者:Spomk
项目:Syliu
function it_uses_a_custom_method_if_configured(RequestConfiguration $requestConfiguration, RepositoryInterface $repository, ResourceInterface $resource)
{
$requestConfiguration->getRepositoryMethod()->willReturn('findAll');
$requestConfiguration->getRepositoryArguments()->willReturn(array('foo'));
$repository->findAll('foo')->willReturn($resource);
$this->get($requestConfiguration, $repository)->shouldReturn($resource);
}
作者:Strontium-9
项目:Syliu
function it_checks_if_the_locale_is_available(RepositoryInterface $repository, LocaleInterface $locale)
{
$repository->findBy(Argument::any())->willReturn(array($locale));
$locale->getCode()->willReturn('en');
$this->isLocaleAvailable('en')->shouldReturn(true);
$this->isLocaleAvailable('fr')->shouldReturn(false);
}
作者:ReissClothin
项目:Syliu
function it_does_not_add_customer_if_they_not_exist(FormEvent $event, RepositoryInterface $customerRepository, FormInterface $form)
{
$event->getData()->willReturn(['email' => 'imno@example.com']);
$customerRepository->findOneBy(['email' => 'imno@example.com'])->willReturn(null);
$form->setData(null)->shouldNotBeCalled();
$this->preSubmit($event);
}
作者:vikey8
项目:Syliu
function it_creates_a_taxon_and_assigns_a_taxonomy_to_id(FactoryInterface $factory, RepositoryInterface $taxonomyRepository, TaxonomyInterface $taxonomy, TaxonInterface $taxon)
{
$factory->createNew()->willReturn($taxon);
$taxonomyRepository->find(13)->willReturn($taxonomy);
$taxon->setTaxonomy($taxonomy)->shouldBeCalled();
$this->createForTaxonomy(13)->shouldReturn($taxon);
}
作者:enhav
项目:enhav
/**
* Moves resource directly behind the position of existing object with id $target
*
* @param RequestConfiguration $requestConfiguration
* @param MetadataInterface $metadataInterface
* @param $resource
* @param RepositoryInterface $repository
* @param int $target
*/
public function moveAfter(RequestConfiguration $requestConfiguration, MetadataInterface $metadataInterface, $resource, RepositoryInterface $repository, $target)
{
$property = $requestConfiguration->getSortablePosition();
$targetResource = $repository->find($target);
$accessor = PropertyAccess::createPropertyAccessor();
$strategy = $requestConfiguration->getSortingStrategy();
$resourceValue = $accessor->getValue($resource, $property);
$targetValue = $accessor->getValue($targetResource, $property);
if ($resourceValue === null || $targetValue === null || $resourceValue == $targetValue) {
// Errors in value consistency: recalculate all position values for this entity
$this->recalculateSortingProperty($property, $repository);
$resourceValue = $accessor->getValue($resource, $property);
$targetValue = $accessor->getValue($targetResource, $property);
}
// Adjust target position based on the resources position relative to the targets position
if (($strategy == self::STRATEGY_ASC_LAST || $strategy == self::STRATEGY_ASC_FIRST) && $resourceValue > $targetValue) {
// Resource is below target
// To get to position one below target, we don't need to move target, only get to position one below, which means to position + 1 in asc strategies.
$targetPosition = $targetValue + 1;
} elseif (($strategy == self::STRATEGY_DESC_LAST || $strategy == self::STRATEGY_DESC_FIRST) && $resourceValue < $targetValue) {
// Resource is below target
// To get to position one below target, we don't need to move target, only get to position one below, which means to position - 1 in desc strategies.
$targetPosition = $targetValue - 1;
} else {
// Resource is above target, we need to move target as well to get to the position one below
$targetPosition = $targetValue;
}
// Execute movement
$this->moveToPosition($resource, $targetPosition, $property, $strategy, $repository);
}
作者:ReissClothin
项目:Syliu
function it_gets_province_code_if_its_abbreviation_is_not_set(RepositoryInterface $provinceRepository, ProvinceInterface $province)
{
$province->getCode()->willReturn('IE-UL');
$province->getAbbreviation()->willReturn(null);
$provinceRepository->findOneBy(['code' => 'IE-UL'])->willReturn($province);
$this->getAbbreviation('IE-UL')->shouldReturn('IE-UL');
}
作者:Mangets
项目:Syliu
function it_creates_a_variant_and_assigns_a_product_to_id(FactoryInterface $factory, RepositoryInterface $productRepository, ProductInterface $product, VariantInterface $variant)
{
$factory->createNew()->willReturn($variant);
$productRepository->find(13)->willReturn($product);
$variant->setProduct($product)->shouldBeCalled();
$this->createForProduct(13)->shouldReturn($variant);
}
作者:ahmadrabi
项目:Syliu
/**
* {@inheritdoc}
*/
public function create()
{
$channel = $this->channelFactory->createNamed(self::DEFAULT_CHANNEL_NAME);
$channel->setCode(self::DEFAULT_CHANNEL_CODE);
$this->channelRepository->add($channel);
return ['channel' => $channel];
}
作者:bcreme
项目:Syliu
private function getCurrency($code)
{
if (isset($this->cache[$code])) {
return $this->cache[$code];
}
return $this->cache[$code] = $this->currencyRepository->findOneBy(array('code' => $code));
}
作者:liverboo
项目:dos-sms-bundl
/**
* @return null|ProviderInterface
*/
public function getActivedProvider()
{
if ($provider = $this->repository->findOneBy(array('actived' => true))) {
return $provider;
}
return $this->findByName($this->defaultProvider);
}
作者:ReissClothin
项目:Syliu
/**
* {@inheritdoc}
*/
public function getAvailableCurrenciesCodes()
{
$currencies = $this->currencyRepository->findBy(['enabled' => true]);
return array_map(function (CurrencyInterface $currency) {
return $currency->getCode();
}, $currencies);
}
作者:origamm
项目:Syliu
/**
* {@inheritdoc}
*/
public function update(OrderInterface $order)
{
/** @var CurrencyInterface $currency */
$currency = $this->currencyRepository->findOneBy(['code' => $this->currencyContext->getCurrencyCode()]);
$order->setCurrencyCode($currency->getCode());
$order->setExchangeRate($currency->getExchangeRate());
}
作者:ahmadrabi
项目:Syliu
/**
* @Given /^the store has disabled country "([^"]*)"$/
*/
public function theStoreHasDisabledCountry($countryName)
{
$country = $this->createCountryNamed(trim($countryName));
$country->disable();
$this->sharedStorage->set('country', $country);
$this->countryRepository->add($country);
}
作者:polisy
项目:Syliu
/**
* @param string $code
*
* @return CurrencyInterface
*/
protected function getCurrency($code)
{
if (isset($this->cache[$code])) {
return $this->cache[$code];
}
return $this->cache[$code] = $this->currencyRepository->findOneBy(['code' => $code]);
}
作者:ReissClothin
项目:Syliu
/**
* @param array $options
*
* @return array
*/
private function getZones(array $options)
{
if (isset($options['scope'])) {
return $this->zoneRepository->findBy(['scope' => $options['scope']]);
}
return $this->zoneRepository->findAll();
}
作者:nany
项目:Syliu
/**
* {@inheritDoc}
*
* @param $request Notify
*/
public function execute($request)
{
if (!$this->supports($request)) {
throw RequestNotSupportedException::createActionNotSupported($this, $request);
}
$this->payment->execute($httpRequest = new GetHttpRequest());
$details = $httpRequest->query;
if (!$this->api->verifyHash($details)) {
throw new BadRequestHttpException('Hash cannot be verified.');
}
if (empty($details['ORDERID'])) {
throw new BadRequestHttpException('Order id cannot be guessed');
}
$payment = $this->paymentRepository->findOneBy(array($this->identifier => $details['ORDERID']));
if (null === $payment) {
throw new BadRequestHttpException('Payment cannot be retrieved.');
}
if ((int) $details['AMOUNT'] !== $payment->getAmount()) {
throw new BadRequestHttpException('Request amount cannot be verified against payment amount.');
}
// Actually update payment details
$details = array_merge($payment->getDetails(), $details);
$payment->setDetails($details);
$status = new GetStatus($payment);
$this->payment->execute($status);
$nextState = $status->getValue();
$this->updatePaymentState($payment, $nextState);
$this->objectManager->flush();
throw new HttpResponse(new Response('OK', 200));
}
作者:lingod
项目:Syliu
/**
* {@inheritdoc}
*/
public function getPermission($code)
{
if (null === ($permission = $this->repository->findOneBy(array('code' => $code)))) {
throw new PermissionNotFoundException($code);
}
return $permission;
}
作者:loic42
项目:Syliu
/**
* @Transform /^country "([^"]+)"$/
* @Transform /^"([^"]+)" country$/
* @Transform /^"([^"]+)" as shipping country$/
*/
public function getCountryByName($countryName)
{
$countryCode = $this->countryNameConverter->convertToCode($countryName);
$country = $this->countryRepository->findOneBy(['code' => $countryCode]);
Assert::notNull($country, sprintf('Country with name "%s" does not exist', $countryName));
return $country;
}