imageService = new ImageService(); } /** * @dataProvider imageDataProvider */ public function testGetPicture(string $filePath, int $width, int $height, string $expectedType): void { // Создаем тестовый файл изображения $testImagePath = __DIR__ . '/test_image.jpg'; $this->createTestImage($testImagePath); $response = $this->imageService->getPicture($testImagePath, $width, $height); $this->assertInstanceOf(Response::class, $response); $this->assertEquals($expectedType, $response->headers->get('Content-Type')); $this->assertNotEmpty($response->getContent()); // Удаляем тестовый файл unlink($testImagePath); } public function imageDataProvider(): array { return [ ['test_image.jpg', 200, 200, 'image/jpeg'], ['test_image.png', 100, 100, 'image/png'], ['test_image.gif', 150, 150, 'image/gif'], ]; } public function testInvalidFile(): void { $response = $this->imageService->getPicture('non_existent_file.jpg'); $this->assertInstanceOf(Response::class, $response); $this->assertEmpty($response->getContent()); } public function testDefaultSize(): void { $testImagePath = __DIR__ . '/test_image.jpg'; $this->createTestImage($testImagePath); $response = $this->imageService->getPicture($testImagePath); $this->assertInstanceOf(Response::class, $response); $this->assertEquals('image/jpeg', $response->headers->get('Content-Type')); $this->assertNotEmpty($response->getContent()); unlink($testImagePath); } private function createTestImage(string $path): void { $image = imagecreatetruecolor(800, 600); $color = imagecolorallocate($image, 255, 0, 0); imagefilledrectangle($image, 0, 0, 800, 600, $color); imagejpeg($image, $path); imagedestroy($image); } }