Skip to content

Commit

Permalink
add basic test and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Dec 19, 2024
1 parent 5021026 commit 032f69a
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/pest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: pest

on:
push:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- run: python -m pip install --upgrade pip
- run: pip install deepface
- run: composer install --no-interaction --no-scripts
- run: vendor/bin/pest
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"symfony/process": "^6.0|^7.0"
},
"require-dev": {
"laravel/pint": "^1.13"
"laravel/pint": "^1.13",
"pestphp/pest": "^3.7"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -46,6 +47,11 @@
"Astrotomic\\DeepFace\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests"
}
},
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
Expand Down
17 changes: 17 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Feature Test Suite">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
28 changes: 28 additions & 0 deletions tests/Feature/DeepfaceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Astrotomic\DeepFace\Data\AnalyzeResult;
use Astrotomic\DeepFace\Enums\Emotion;
use Astrotomic\DeepFace\Enums\Gender;
use Astrotomic\DeepFace\Enums\Race;
use PHPUnit\Framework\Assert;

describe('analyze', function ():void {
it('analyzes: img1', function ():void {
$img = $this->image('img1.jpg');
$results = $this->deepface()->analyze($img);

Assert::assertCount(1, $results);
Assert::assertContainsOnlyInstancesOf(AnalyzeResult::class, $results);

$result = $results[0];

Assert::assertSame($img, $result->img_path);
Assert::assertSame(339, $result->facial_area->x);
Assert::assertSame(218, $result->facial_area->y);
Assert::assertSame(768, $result->facial_area->w);
Assert::assertSame(768, $result->facial_area->h);
Assert::assertSame(Emotion::HAPPY, $result->dominant_emotion);
Assert::assertSame(Gender::WOMAN, $result->dominant_gender);
Assert::assertSame(Race::LATINO_HISPANIC, $result->dominant_race);
});
});
Binary file added tests/Fixtures/images/couple.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Fixtures/images/img1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Fixtures/images/img2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Fixtures/images/img3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/Fixtures/images/selfie-many-people.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

pest()->extend(Tests\TestCase::class)->in('Feature');
19 changes: 19 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tests;

use Astrotomic\DeepFace\DeepFace;
use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
protected function deepface(): DeepFace
{
return new DeepFace('/opt/homebrew/bin/python3.11');
}

protected function image(string $img): string
{
return realpath(__DIR__ . DIRECTORY_SEPARATOR . 'Fixtures'. DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $img);
}
}

0 comments on commit 032f69a

Please sign in to comment.