| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the PierstovalCharacterManagerBundle package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Alexandre Rock Ancelet <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 Pierstoval\Bundle\CharacterManagerBundle\Tests\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use PHPUnit_Framework_MockObject_MockObject as MockObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Pierstoval\Bundle\CharacterManagerBundle\Controller\GeneratorController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Pierstoval\Bundle\CharacterManagerBundle\Registry\ActionsRegistryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Pierstoval\Bundle\CharacterManagerBundle\Resolver\StepResolverInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use \Pierstoval\Bundle\CharacterManagerBundle\Tests\Fixtures\Stubs\Action\ConcreteAbstractActionStub; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Pierstoval\Bundle\CharacterManagerBundle\Tests\Fixtures\Stubs\Entity\CharacterStub; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Pierstoval\Bundle\CharacterManagerBundle\Tests\RequestTestTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Symfony\Component\Routing\RouterInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Symfony\Component\Translation\TranslatorInterface; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 25 |  |  | abstract class AbstractGeneratorControllerTest extends TestCase | 
            
                                                        
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                        
            
                                    
            
            
                | 27 |  |  |     use RequestTestTrait; | 
            
                                                        
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 29 |  |  |     /** | 
            
                                                        
            
                                    
            
            
                | 30 |  |  |      * @param MockObject|StepResolverInterface    $resolver | 
            
                                                        
            
                                    
            
            
                | 31 |  |  |      * @param MockObject|TranslatorInterface      $translator | 
            
                                                        
            
                                    
            
            
                | 32 |  |  |      * @param MockObject|RouterInterface          $router | 
            
                                                        
            
                                    
            
            
                | 33 |  |  |      * @param MockObject|ActionsRegistryInterface $actionsRegistry | 
            
                                                        
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                        
            
                                    
            
            
                | 35 |  |  |      * @return GeneratorController | 
            
                                                        
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 37 |  |  |     protected function createController( | 
            
                                                        
            
                                    
            
            
                | 38 |  |  |         StepResolverInterface $resolver = null, | 
            
                                                        
            
                                    
            
            
                | 39 |  |  |         RouterInterface $router = null, | 
            
                                                        
            
                                    
            
            
                | 40 |  |  |         TranslatorInterface $translator = null, | 
            
                                                        
            
                                    
            
            
                | 41 |  |  |         ActionsRegistryInterface $actionsRegistry = null | 
            
                                                        
            
                                    
            
            
                | 42 |  |  |     ): GeneratorController { | 
            
                                                        
            
                                    
            
            
                | 43 |  |  |         if (null === $resolver) { | 
            
                                                        
            
                                    
            
            
                | 44 |  |  |             $resolver = $this->createMock(StepResolverInterface::class); | 
            
                                                        
            
                                    
            
            
                | 45 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 46 |  |  |         if (null === $router) { | 
            
                                                        
            
                                    
            
            
                | 47 |  |  |             $router = $this->createMock(RouterInterface::class); | 
            
                                                        
            
                                    
            
            
                | 48 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 49 |  |  |         if (null === $translator) { | 
            
                                                        
            
                                    
            
            
                | 50 |  |  |             $translator = $this->createMock(TranslatorInterface::class); | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |         if (null === $actionsRegistry) { | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |             $actionsRegistry = $this->createMock(ActionsRegistryInterface::class); | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         return new GeneratorController($resolver, $actionsRegistry, $router, $translator); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 59 |  |  |     protected function createManagerConfiguration(string $managerName, array $steps = []): array | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |         $manager = [ | 
            
                                                        
            
                                    
            
            
                | 62 |  |  |             'character_class' => CharacterStub::class, | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |             'steps' => [], | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |         // Will be used to populate missing data | 
            
                                                        
            
                                    
            
            
                | 67 |  |  |         $baseStep = [ | 
            
                                                        
            
                                    
            
            
                | 68 |  |  |             'action'         => ConcreteAbstractActionStub::class, | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |             'label'          => '', | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |             'number'         => 1, | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |             'name'           => '01', | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |             'manager_name'   => $managerName, | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |             'dependencies'   => [], | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |             'onchange_clear' => [], | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |         $manager['steps'] = $steps ?: [ | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |             '01' => $baseStep, | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |         ]; | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |         $i = 1; | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |         foreach ($manager['steps'] as $name => &$step) { | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |             $step = ['name' => $name, 'number' => $i++] + $step + $baseStep; | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |         return $manager; | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  |