| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the ICanBoogie package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Olivier Laviale <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace ICanBoogie; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @group render | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | class RenderedErrorCollectionTest extends \PHPUnit_Framework_TestCase | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 18 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  | 	public function test_renderer() | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | 		$format = "error: {arg}"; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  | 		$arg1 = uniqid(); | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  | 		$arg2 = uniqid(); | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  | 		$arg3 = uniqid(); | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | 		$arg4 = uniqid(); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | 		$attribute = uniqid(); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  | 		$errors = (new ErrorCollection) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | 			->add($attribute, $format, [ 'arg' => $arg3 ]) | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | 			->add_generic($format, [ 'arg' => $arg1 ]) | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | 			->add($attribute, $format, [ 'arg' => $arg4 ]) | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | 			->add_generic($format, [ 'arg' => $arg2 ]) | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  | 		; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  | 		$renderer = new RenderedErrorCollection($errors); | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  | 		$rendered = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  | 		foreach ($renderer as $a => $r) | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  | 		{ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  | 			$rendered[] = [ $a, $r ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  | 		$this->assertSame([ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  | 			[ ErrorCollection::GENERIC, "error: {$arg1}" ], | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  | 			[ ErrorCollection::GENERIC, "error: {$arg2}" ], | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  | 			[ $attribute, "error: {$arg3}" ], | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  | 			[ $attribute, "error: {$arg4}" ], | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  | 		], $rendered); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | 	public function test_render_with_customer_error_renderer() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | 		$format = "error: {arg}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | 		$arg1 = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | 		$arg2 = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | 		$arg3 = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | 		$arg4 = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | 		$attribute = uniqid(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 		$errors = (new ErrorCollection) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 			->add($attribute, $format, [ 'arg' => $arg3 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 			->add_generic($format, [ 'arg' => $arg1 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 			->add($attribute, $format, [ 'arg' => $arg4 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 			->add_generic($format, [ 'arg' => $arg2 ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 		; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 		$renderer = new RenderedErrorCollection($errors, function (Error $error) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | 			return strrev($error); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  | 		$rendered = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 		foreach ($renderer as $a => $r) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 		{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 			$rendered[] = [ $a, $r ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 		$this->assertSame([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 			[ ErrorCollection::GENERIC, strrev("error: {$arg1}") ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 			[ ErrorCollection::GENERIC, strrev("error: {$arg2}") ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 			[ $attribute, strrev("error: {$arg3}") ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 			[ $attribute, strrev("error: {$arg4}") ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		], $rendered); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |  |