| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace Nexendrie\Translation\Loaders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Tester\Assert, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |     Nexendrie\Translation\InvalidFolderException, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |     Nexendrie\Translation\FolderNotSetException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * General test suit for file loaders | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author Jakub Konečný | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | abstract class FileLoaderTestAbstract extends \Tester\TestCase { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |   /** @var FileLoader */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |   protected $loader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |   public function testGetLang() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     $lang = $this->loader->lang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     Assert::type("string", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     Assert::same("en", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |   public function testSetLang() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     $this->loader->lang = "cs"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     $lang = $this->loader->lang; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     Assert::type("string", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     Assert::same("cs", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |   public function testGetDefaultLang() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     $lang = $this->loader->defaultLang; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     Assert::type("string", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     Assert::same("en", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |   public function testSetDefaultLang() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     $this->loader->defaultLang = "cs"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     $lang = $this->loader->defaultLang; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     Assert::type("string", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     Assert::same("cs", $lang); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |   public function testGetFolders() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     $folders = $this->loader->folders; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     Assert::type("array", $folders); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     Assert::count(2, $folders); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     Assert::same(__DIR__ . "/../../../lang", $folders[0]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     Assert::same(__DIR__ . "/../../../lang2", $folders[1]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |   public function testSetFolders() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     Assert::exception(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |       $this->loader->folders = [""]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     }, InvalidFolderException::class, "Folder  does not exist."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |   } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 58 |  |  |    | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |   public function testGetResources() { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     // texts were not loaded yet so there are no resources | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |     $resources = $this->loader->resources; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |     Assert::type("array", $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |     Assert::count(0, $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |     // english texts are loaded, there is 1 resource for each domain | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     $this->loader->getTexts(); | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     $resources = $this->loader->resources; | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |     Assert::type("array", $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     Assert::count(3, $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     Assert::count(1, $resources["messages"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     Assert::count(1, $resources["book"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |     Assert::count(1, $resources["abc"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     // czech and english texts are loaded, there are 2 resources for each domain | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |     $this->loader->lang = "cs"; | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     $this->loader->getTexts(); | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |     $resources = $this->loader->resources; | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |     Assert::type("array", $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |     Assert::count(3, $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     Assert::count(2, $resources["messages"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     Assert::count(2, $resources["book"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     Assert::count(2, $resources["abc"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     // the language does not exist, 1 (default) resource for each domain | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     if($this->loader instanceof MessagesCatalogue) { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |       return; // the following tests for some reason fail with MessagesCatalogue | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     $this->loader->lang = "xyz"; | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     $this->loader->getTexts(); | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     $resources = $this->loader->resources; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |     Assert::type("array", $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |     Assert::count(3, $resources); | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |     Assert::count(1, $resources["messages"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     Assert::count(1, $resources["book"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     Assert::count(1, $resources["abc"]); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |   public function testGetTexts() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     $texts = $this->loader->getTexts(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     Assert::type("array", $texts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     Assert::count(3, $texts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     Assert::type("array", $texts["messages"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     Assert::count(3, $texts["messages"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     Assert::type("array", $texts["book"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     Assert::count(5, $texts["book"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     $this->loader->lang = "cs"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     $texts = $this->loader->getTexts(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     Assert::type("array", $texts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     Assert::count(3, $texts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     Assert::type("array", $texts["messages"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     Assert::count(3, $texts["messages"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     Assert::type("array", $texts["book"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     Assert::count(5, $texts["book"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     if($this->loader instanceof MessagesCatalogue) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |       return; // the following tests for some reason fail with MessagesCatalogue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     $this->loader->lang = "xyz"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |     $texts = $this->loader->getTexts(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     Assert::type("array", $texts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     Assert::count(3, $texts); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     Assert::type("array", $texts["messages"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     Assert::count(3, $texts["messages"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     Assert::type("array", $texts["book"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     Assert::count(5, $texts["book"]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |   public function testNoFolder() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     Assert::exception(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |       $class = get_class($this->loader); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |       $this->loader = new $class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |       $this->loader->getTexts(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     }, FolderNotSetException::class, "Folder for translations was not set."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |   public function testGetAvailableLanguages() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     $result = $this->loader->getAvailableLanguages(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     Assert::type("array", $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     Assert::count(2, $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     Assert::contains("en", $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     Assert::contains("cs", $result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |     Assert::exception(function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |       $class = get_class($this->loader); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |       $this->loader = new $class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |       $this->loader->getAvailableLanguages(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     }, FolderNotSetException::class, "Folder for translations was not set."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |    | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |   public function testGetResolverName() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     $name = $this->loader->getResolverName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     Assert::type("string", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     Assert::same("ManualLocaleResolver", $name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |   } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 150 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 151 |  |  | ?> | 
            
                        
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.