trismegiste/phpunit-assert-picture

图片的有用断言

dev-master 2022-10-11 09:35 UTC

This package is not auto-updated.

Last update: 2024-09-25 17:43:56 UTC


README

新的 PhpUnit 断言用于测试图片(大小、类型、文本内容...)

是什么

这是一个特性集,用于在图片上添加新的断言

如何使用

添加库

$ composer require --dev trismegiste/phpunit-assert-picture

在您的 TestCase 子类中使用特性

class MyPictureTest extends \PHPUnit\Framework\TestCase
{
    use \Trismegiste\PhpunitAssertPicture\ImageSpecs;
    use \Trismegiste\PhpunitAssertPicture\TextContent;

    // ... your tests

示例

这是一张图片

Sample

图像属性

我们可以使用图片的完整路径或使用 \GdImage 实例来调用断言

   /** @dataProvider getFixture */
   public function testPicture(string $pic)
   {
       // assertions on width and height :
       $this->assertDimension(128, 256, $pic);
       // assetion on mime-type :
       $this->assertMimeType('image/png', $pic);
       // assertion on orientation mode :
       $this->assertPortrait($pic);
   }

文本内容

通过 OCR 在图片内部对文本内容进行断言

       $this->assertPictureContainsString('YOLO', $pic);

依赖

  • Tesseract
  • GD2

贡献

请随时贡献新的特性