| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | namespace FlexyProject\GitHub\Tests\Receiver; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use FlexyProject\GitHub\{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |     AbstractApi, Client, Receiver\Miscellaneous, Tests\AbstractTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * Class MiscellaneousTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package FlexyProject\GitHub\Tests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class MiscellaneousTest extends AbstractTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** @var Miscellaneous */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected $miscellaneous; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     /** @var Miscellaneous\Emojis */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     protected $emojis; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** @var  Miscellaneous\Gitignore */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     protected $gitIgnore; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** @var  Miscellaneous\Licenses */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     protected $licenses; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /** @var  Miscellaneous\Markdown */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     protected $markdown; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** @var  Miscellaneous\Meta */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     protected $meta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** @var  Miscellaneous\RateLimit */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     protected $rateLimit; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * MiscellaneousTest constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param null   $name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param array  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @param string $dataName | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     public function __construct($name = null, array $data = [], $dataName = '') | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |         parent::__construct($name, $data, $dataName); | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |         // Miscellaneous | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $this->miscellaneous = $this->client->getReceiver(Client::MISCELLANEOUS); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         // Emojis | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         $this->emojis = $this->miscellaneous->getReceiver(Miscellaneous::EMOJIS); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         // GitIgnore | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $this->gitIgnore = $this->miscellaneous->getReceiver(Miscellaneous::GITIGNORE); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         // Licenses | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->licenses = $this->miscellaneous->getReceiver(Miscellaneous::LICENSES); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         // Markdown | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         $this->markdown = $this->miscellaneous->getReceiver(Miscellaneous::MARKDOWN); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         // Meta | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         $this->meta = $this->miscellaneous->getReceiver(Miscellaneous::META); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         // RateLimit | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         $this->rateLimit = $this->miscellaneous->getReceiver(Miscellaneous::RATE_LIMIT); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * Test list available Emojis | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     public function testGetListEmojis() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->assertCount(1508, $this->emojis->get()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * Test listing available templates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function testListingAvailableTemplates() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $templates = $this->gitIgnore->listingAvailableTemplates(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->assertContains('Android', $templates); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * Test getting a single template | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function testGetSingleTemplate() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $template = $this->gitIgnore->getSingleTemplate('Android'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $this->assertArrayHasKey('name', $template); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $this->assertArrayHasKey('source', $template); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * Test listing all licenses | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function testListAllLicenses() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $licenses = $this->licenses->listAllLicenses(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $license  = array_pop($licenses); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $this->assertArrayHasKey('key', $license); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $this->assertArrayHasKey('name', $license); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         $this->assertArrayHasKey('spdx_id', $license); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         $this->assertArrayHasKey('url', $license); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $this->assertArrayHasKey('featured', $license); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * Test getting individual license | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     public function testGettingIndividualLicense() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $license = $this->licenses->getIndividualLicense('mit'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $this->assertArrayHasKey('body', $license); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * Test render markdown text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 127 |  | View Code Duplication |     public function testRender() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $output = $this->markdown->render('Hello world FlexyProject/GitHubAPI#43 **cool**, and #43!'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         $this->assertEquals('<p>Hello world FlexyProject/GitHubAPI#43 <strong>cool</strong>, and #43!</p>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             str_replace(["\r\n", "\r", "\n"], "", $output[0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * Test render markdown raw text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 138 |  | View Code Duplication |     public function testRenderRaw() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         $output = $this->markdown->renderRaw('**cool**'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |         $this->assertEquals('<p>{"file":"<strong>cool</strong>"}</p>', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |             str_replace(["\r\n", "\r", "\n"], "", $output[0])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * Test getting meta about GitHub.com | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     public function testGetMeta() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         $meta = $this->meta->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $this->assertTrue($meta['verifiable_password_authentication']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |      * Test rate limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     public function testRateLimit() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $rateLimit = $this->rateLimit->get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $this->assertArrayHasKey('rate', $rateLimit); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 164 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 165 |  |  | } | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.