https://github.com/trismegiste/phpunit-assert-picture
Make assertions on pictures
https://github.com/trismegiste/phpunit-assert-picture
Last synced: 5 months ago
JSON representation
Make assertions on pictures
- Host: GitHub
- URL: https://github.com/trismegiste/phpunit-assert-picture
- Owner: Trismegiste
- Created: 2022-10-11T09:22:35.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-11T09:35:14.000Z (almost 3 years ago)
- Last Synced: 2025-01-07T21:24:34.910Z (6 months ago)
- Language: PHP
- Size: 33.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# phpunit-assert-picture
New PhpUnit Assertions for testing Pictures (size, type, text content...)# What
It's a set of Traits for adding new assertions on pictures# How
Add the library :
```bash
$ composer require --dev trismegiste/phpunit-assert-picture
```Use the traits in your TestCase subclass :
```php
class MyPictureTest extends \PHPUnit\Framework\TestCase
{
use \Trismegiste\PhpunitAssertPicture\ImageSpecs;
use \Trismegiste\PhpunitAssertPicture\TextContent;// ... your tests
```# Examples
Here's a picture :
## Image attributes
We can call assertions with the full pathname of the picture or with a \GdImage instance :
```php
/** @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);
}
```## Text contents
Assertion on text content inside the picture thanks to OCR :
```php
$this->assertPictureContainsString('YOLO', $pic);
```# Dependencies
* Tesseract
* GD2# Contribute
Feel free to contribute with new fancy features