| 
									
										
										
										
											2023-07-13 11:34:56 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace App\Tests; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | use PHPUnit\Framework\TestCase; | 
					
						
							|  |  |  | use PHPUnit\Framework\Attributes\CoversClass; | 
					
						
							| 
									
										
										
										
											2023-11-14 09:09:15 +00:00
										 |  |  | use PHPUnit\Framework\Attributes\DataProvider; | 
					
						
							| 
									
										
										
										
											2023-07-13 11:34:56 +00:00
										 |  |  | use Psr\Log\LoggerInterface; | 
					
						
							|  |  |  | use App\App; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[CoversClass(App::class)]
 | 
					
						
							|  |  |  | final class AppTest extends \PHPUnit\Framework\TestCase | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     public function testNonexistentConfigFile(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->expectException(\Exception::class); | 
					
						
							|  |  |  |         new App('no_file'); | 
					
						
							|  |  |  |         $this->fail('Exception was not thrown'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testGoodConfig(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $app = new App('config.example.yml'); | 
					
						
							|  |  |  |         $this->assertEquals('output.log', $app->getConfig('log')); | 
					
						
							|  |  |  |         $this->assertInstanceOf(LoggerInterface::class, $app->getLogger()); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-11-14 09:09:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     public function testBadConfigFileSyntaxError(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->expectException(\TypeError::class); | 
					
						
							| 
									
										
										
										
											2023-11-16 10:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-14 09:09:15 +00:00
										 |  |  |         $app = new App('tests/config/bad/syntaxerror.yml'); | 
					
						
							|  |  |  |         $app->getConfig('rclone'); | 
					
						
							|  |  |  |         $app->getConfig('rclone.path'); | 
					
						
							|  |  |  |         $app->getConfig('backup'); | 
					
						
							|  |  |  |         $app->getConfig('notification'); | 
					
						
							|  |  |  |         $app->getConfig('log'); | 
					
						
							|  |  |  |         $app->getConfig('templates'); | 
					
						
							|  |  |  |         $app->getConfig('templates.notify'); | 
					
						
							|  |  |  |         $app->getConfig('templates.error'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->fail('Exception was not thrown'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testBadConfigFileEmpty(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->expectException(\TypeError::class); | 
					
						
							| 
									
										
										
										
											2023-11-16 10:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-14 09:09:15 +00:00
										 |  |  |         $app = new App('tests/config/bad/empty.yml'); | 
					
						
							|  |  |  |         $app->getConfig('rclone'); | 
					
						
							|  |  |  |         $app->getConfig('rclone.path'); | 
					
						
							|  |  |  |         $app->getConfig('backup'); | 
					
						
							|  |  |  |         $app->getConfig('notification'); | 
					
						
							|  |  |  |         $app->getConfig('log'); | 
					
						
							|  |  |  |         $app->getConfig('templates'); | 
					
						
							|  |  |  |         $app->getConfig('templates.notify'); | 
					
						
							|  |  |  |         $app->getConfig('templates.error'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->fail('Exception was not thrown'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function testBadConfigFileTypos(): void | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $this->expectException(\League\Config\Exception\ValidationException::class); | 
					
						
							| 
									
										
										
										
											2023-11-16 10:30:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-14 09:09:15 +00:00
										 |  |  |         $app = new App('tests/config/bad/typos.yml'); | 
					
						
							|  |  |  |         $app->getConfig('rclone'); | 
					
						
							|  |  |  |         $app->getConfig('rclone.path'); | 
					
						
							|  |  |  |         $app->getConfig('backup'); | 
					
						
							|  |  |  |         $app->getConfig('notification'); | 
					
						
							|  |  |  |         $app->getConfig('log'); | 
					
						
							|  |  |  |         $app->getConfig('templates'); | 
					
						
							|  |  |  |         $app->getConfig('templates.notify'); | 
					
						
							|  |  |  |         $app->getConfig('templates.error'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $this->fail('Exception was not thrown'); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-07-13 11:34:56 +00:00
										 |  |  | } |