| 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 spec\Sylius\Bundle\AdminApiBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use FOS\OAuthServerBundle\Model\ClientManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use PhpSpec\ObjectBehavior; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Prophecy\Argument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Sylius\Bundle\AdminApiBundle\Model\Client; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Sylius\Bundle\AdminApiBundle\Command\CreateClientCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Symfony\Component\DependencyInjection\ContainerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | final class CreateClientCommandSpec extends ObjectBehavior | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     public function it_is_initializable() | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $this->shouldHaveType(CreateClientCommand::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function it_is_a_container_aware_command() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->shouldHaveType(ContainerAwareCommand::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function it_has_a_name() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->getName()->shouldReturn('sylius:oauth-server:create-client'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function it_creates_a_client( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         ContainerInterface $container, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         InputInterface $input, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         OutputInterface $output, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ClientManager $clientManager, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         Client $client | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $input->bind(Argument::any())->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $input->isInteractive()->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $input->validate()->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $input->hasArgument('command')->willReturn(false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $container->get('fos_oauth_server.client_manager.default')->willReturn($clientManager); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $clientManager->createClient()->willReturn($client); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $input->getOption('redirect-uri')->willReturn(['redirect-uri']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $input->getOption('grant-type')->willReturn(['grant-type']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $client->setRedirectUris(['redirect-uri'])->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $client->setAllowedGrantTypes(['grant-type'])->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $clientManager->updateClient($client)->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $client->getPublicId()->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $client->getSecret()->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $output->writeln(Argument::type('string'))->shouldBeCalled(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $this->setContainer($container); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->run($input, $output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 72 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |  |