diff --git a/.github/workflows/pest.yml b/.github/workflows/pest.yml new file mode 100644 index 0000000..4a0a706 --- /dev/null +++ b/.github/workflows/pest.yml @@ -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 diff --git a/composer.json b/composer.json index 1be6b0a..c829257 100644 --- a/composer.json +++ b/composer.json @@ -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, @@ -46,6 +47,11 @@ "Astrotomic\\DeepFace\\": "src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests" + } + }, "config": { "allow-plugins": { "pestphp/pest-plugin": true diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..398f715 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,17 @@ + + + + + ./tests/Feature + + + + + ./src + + + diff --git a/tests/Feature/DeepfaceTest.php b/tests/Feature/DeepfaceTest.php new file mode 100644 index 0000000..685cb40 --- /dev/null +++ b/tests/Feature/DeepfaceTest.php @@ -0,0 +1,28 @@ +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); + }); +}); diff --git a/tests/Fixtures/images/couple.jpg b/tests/Fixtures/images/couple.jpg new file mode 100644 index 0000000..1a07d76 Binary files /dev/null and b/tests/Fixtures/images/couple.jpg differ diff --git a/tests/Fixtures/images/img1.jpg b/tests/Fixtures/images/img1.jpg new file mode 100644 index 0000000..7ceab4f Binary files /dev/null and b/tests/Fixtures/images/img1.jpg differ diff --git a/tests/Fixtures/images/img2.jpg b/tests/Fixtures/images/img2.jpg new file mode 100644 index 0000000..05683ea Binary files /dev/null and b/tests/Fixtures/images/img2.jpg differ diff --git a/tests/Fixtures/images/img3.jpg b/tests/Fixtures/images/img3.jpg new file mode 100644 index 0000000..08e8dcc Binary files /dev/null and b/tests/Fixtures/images/img3.jpg differ diff --git a/tests/Fixtures/images/selfie-many-people.jpg b/tests/Fixtures/images/selfie-many-people.jpg new file mode 100644 index 0000000..a6fed51 Binary files /dev/null and b/tests/Fixtures/images/selfie-many-people.jpg differ diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..c131132 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,3 @@ +extend(Tests\TestCase::class)->in('Feature'); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..89c8d9c --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,19 @@ +