| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace JefersonC\Tests; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use JefersonC\Enum\PrettyEnum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use JefersonC\Enum\InvalidEnumKeyException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use JefersonC\Enum\InvalidEnumMethodException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use JefersonC\Example\ExampleEnum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use JefersonC\Example\ProfilesExampleEnum; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use PHPUnit\Framework\TestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class PrettyEnumTest extends TestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function test_getting_enum_value() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $this->assertEquals(ExampleEnum::get('TEST'), 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     public function test_getting_pretty_value() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->assertEquals(ExampleEnum::pretty('TEST'), "Teste"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function test_getting_list_of_enumerator() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $list = ExampleEnum::all(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->assertEquals($list[0]->value, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertEquals($list[0]->name, "Teste"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function test_throws_exception_when_key_does_not_exists() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $this->expectException(InvalidEnumKeyException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->assertEquals(ExampleEnum::pretty('ASDSAD'), "sdadas"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     public function test_getting_multiples_enuns_values() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertEquals(ExampleEnum::pretty('BLUE'), 'Azul'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->assertEquals(ExampleEnum::pretty('RED'), 'Vermelho'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertEquals(ExampleEnum::get('BLUE') + ExampleEnum::get('RED'), 55); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function test_throws_exception_when_method_does_not_exists() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |       $this->expectException(InvalidEnumMethodException::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |       $this->assertEquals(ExampleEnum::safdfsd('ASDSAD'), "sdadas"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 52 |  |  |     public function test_get_custom_propertie_from_enum() | 
            
                                                        
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |         $item = ProfilesExampleEnum::item('ADMIN'); | 
            
                                                        
            
                                    
            
            
                | 55 |  |  |         $this->assertEquals($item->value, 'ADMIN'); | 
            
                                                        
            
                                    
            
            
                | 56 |  |  |         $this->assertEquals($item->name, 'Administrador'); | 
            
                                                        
            
                                    
            
            
                | 57 |  |  |         $this->assertEquals($item->description, 'Perfil de permissões para administradores'); | 
            
                                                        
            
                                    
            
            
                | 58 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 59 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  |  |