Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trismegiste/phpunit-assert-picture
Make assertions on pictures
https://github.com/trismegiste/phpunit-assert-picture
Last synced: about 1 month 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 (about 2 years ago)
- Default Branch: master
- Last Pushed: 2022-10-11T09:35:14.000Z (about 2 years ago)
- Last Synced: 2024-04-09T13:13:48.423Z (9 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 :![Sample](https://github.com/Trismegiste/phpunit-assert-picture/blob/master/tests/fixtures/sample.png)
## 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