/** * @Transform /^"([^"]+)" tax category$/ * @Transform /^tax category "([^"]+)"$/ * @Transform :taxCategory */ public function getTaxCategoryByName($taxCategoryName) { $taxCategory = $this->taxCategoryRepository->findOneByName($taxCategoryName); if (null === $taxCategory) { throw new \InvalidArgumentException('Tax category with name "' . $taxCategoryName . '" does not exist'); } return $taxCategory; }
function it_creates_a_tax_category_with_name_and_code(SharedStorageInterface $sharedStorage, TaxCategoryInterface $taxCategory, TaxCategoryRepositoryInterface $taxCategoryRepository, FactoryInterface $taxCategoryFactory) { $taxCategoryFactory->createNew()->willReturn($taxCategory); $taxCategory->setName('Alcohol')->shouldBeCalled(); $taxCategory->setCode('alcohol')->shouldBeCalled(); $taxCategoryRepository->add($taxCategory)->shouldBeCalled(); $sharedStorage->set('tax_category', $taxCategory)->shouldBeCalled(); $this->theStoreHasTaxCategoryWithCode('Alcohol', 'alcohol'); }
/** * @param string $taxCategoryName * * @return TaxCategoryInterface */ private function createTaxCategory($taxCategoryName) { $taxCategory = $this->taxCategoryFactory->createNew(); $taxCategory->setName($taxCategoryName); $taxCategory->setCode($this->getCodeFromName($taxCategoryName)); $this->taxCategoryRepository->add($taxCategory); return $taxCategory; }
/** * @param string $taxCategoryName * @param string|null $taxCategoryCode * * @return TaxCategoryInterface */ private function createTaxCategory($taxCategoryName, $taxCategoryCode = null) { /** @var TaxCategoryInterface $taxCategory */ $taxCategory = $this->taxCategoryFactory->createNew(); if (null === $taxCategoryCode) { $taxCategoryCode = $this->getCodeFromName($taxCategoryName); } $taxCategory->setName($taxCategoryName); $taxCategory->setCode($taxCategoryCode); $this->taxCategoryRepository->add($taxCategory); return $taxCategory; }
/** * @Transform /^"([^"]+)" tax category$/ * @Transform /^tax category "([^"]+)"$/ * @Transform :taxCategory */ public function getTaxCategoryByName($taxCategoryName) { $taxCategory = $this->taxCategoryRepository->findOneByName($taxCategoryName); Assert::notNull($taxCategory, sprintf('Tax category with name "%s" does not exist', $taxCategoryName)); return $taxCategory; }
/** * @Transform /^"([^"]+)" tax category$/ * @Transform /^tax category "([^"]+)"$/ * @Transform :taxCategory */ public function getTaxCategoryByName($taxCategoryName) { $taxCategories = $this->taxCategoryRepository->findByName($taxCategoryName); Assert::eq(1, count($taxCategories), sprintf('%d tax categories has been found with name "%s".', count($taxCategories), $taxCategoryName)); return $taxCategories[0]; }