| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Sylius package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Paweł Jędrzejewski | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Sylius\Behat\Context\Setup; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Behat\Behat\Context\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Doctrine\Common\Persistence\ObjectManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Sylius\Behat\Service\SharedStorageInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Sylius\Component\Core\Formatter\StringInflector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Sylius\Component\Resource\Factory\FactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Sylius\Component\Resource\Repository\RepositoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Sylius\Component\Shipping\Model\ShippingCategoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author Anna Walasek <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | final class ShippingCategoryContext implements Context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @var SharedStorageInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     private $sharedStorage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @var FactoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private $shippingCategoryFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var RepositoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private $shippingCategoryRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var ObjectManager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     private $shippingCategoryManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @param SharedStorageInterface $sharedStorage | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param FactoryInterface $shippingCategoryFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param RepositoryInterface $shippingCategoryRepository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param ObjectManager $shippingCategoryManager | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     public function __construct( | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         SharedStorageInterface $sharedStorage, | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         FactoryInterface $shippingCategoryFactory, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         RepositoryInterface $shippingCategoryRepository, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         ObjectManager $shippingCategoryManager | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         $this->sharedStorage = $sharedStorage; | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $this->shippingCategoryFactory = $shippingCategoryFactory; | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         $this->shippingCategoryRepository = $shippingCategoryRepository; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $this->shippingCategoryManager = $shippingCategoryManager; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @Given the store has :firstShippingCategoryName shipping category | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * @Given the store has :firstShippingCategoryName and :secondShippingCategoryName shipping category | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     public function theStoreHasAndShippingCategory($firstShippingCategoryName, $secondShippingCategoryName = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->createShippingCategory($firstShippingCategoryName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         (null === $secondShippingCategoryName)? : $this->createShippingCategory($secondShippingCategoryName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @param string $shippingCategoryName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     private function createShippingCategory($shippingCategoryName) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         /** @var ShippingCategoryInterface $shippingCategory */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $shippingCategory =  $this->shippingCategoryFactory->createNew(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $shippingCategory->setName($shippingCategoryName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $shippingCategory->setCode(StringInflector::nameToCode($shippingCategoryName)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->shippingCategoryRepository->add($shippingCategory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $this->sharedStorage->set('shipping_category', $shippingCategory); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  | 
            
                        
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.