-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2221ff4
commit 409fef7
Showing
15 changed files
with
206 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ${{ matrics.os }} | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
php: [8.2, 8.3] | ||
stability: [prefer-lowest, prefer-stable] | ||
|
||
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: curl, mbstring, imagick | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction | ||
|
||
- name: Setup problem matchers | ||
run: | | ||
echo "::add-matcher::${{ runner.tool_cache }}/php.json" | ||
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
- name: Execute tests | ||
run: | | ||
npm install | ||
vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
/vendor | ||
/composer.lock | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,20 @@ | |
"SimonHamp\\TheOg\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\": "tests/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Simon Hamp", | ||
"email": "[email protected]" | ||
} | ||
] | ||
], | ||
"require-dev": { | ||
"spatie/phpunit-snapshot-assertions": "^5.1", | ||
"phpunit/phpunit": "^10.5", | ||
"spatie/pixelmatch-php": "^1.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devDependencies": { | ||
"pixelmatch": "^5.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="Integration"> | ||
<directory>tests/Integration</directory> | ||
</testsuite> | ||
<testsuite name="Unit"> | ||
<directory>tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
|
||
namespace Tests\Integration; | ||
|
||
use FilesystemIterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use RecursiveDirectoryIterator; | ||
use RecursiveIteratorIterator; | ||
use SimonHamp\TheOg\Background; | ||
use SimonHamp\TheOg\Image; | ||
use SimonHamp\TheOg\Themes\Themes; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
|
||
class ImageTest extends TestCase | ||
{ | ||
use MatchesSnapshots; | ||
|
||
private const TESTCASE_DIRECTORY = __DIR__.'/../resources/testcases'; | ||
|
||
#[DataProvider('snapshotImages')] | ||
public function test_basic_image(Image $image, string $name): void | ||
{ | ||
$path = self::TESTCASE_DIRECTORY.'/'.$name.'.png'; | ||
|
||
$image->save($path); | ||
|
||
$this->assertMatchesImageSnapshot($path); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
|
||
$files = new RecursiveIteratorIterator( | ||
new RecursiveDirectoryIterator(self::TESTCASE_DIRECTORY, FilesystemIterator::SKIP_DOTS), | ||
RecursiveIteratorIterator::CHILD_FIRST, | ||
); | ||
|
||
foreach ($files as $file) { | ||
unlink($file->getRealPath()); | ||
} | ||
} | ||
|
||
public static function snapshotImages() | ||
{ | ||
yield 'basic' => [ | ||
(new Image()) | ||
->url('https://example.com/blog/some-blog-post-url') | ||
->title('Some blog post title that is quite big and quite long') | ||
->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words'), | ||
'basic', | ||
]; | ||
|
||
yield 'different theme' => [ | ||
(new Image()) | ||
->theme(Themes::Dark) | ||
->url('https://example.com/blog/some-blog-post-url') | ||
->title('Some blog post title that is quite big and quite long') | ||
->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words'), | ||
'different-theme', | ||
]; | ||
|
||
yield 'override some elements' => [ | ||
(new Image()) | ||
->accentColor('#cc0000') | ||
->url('https://example.com/blog/some-blog-post-url') | ||
->title('Some blog post title that is quite big and quite long') | ||
->description(<<<'TEXT' | ||
Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words. | ||
Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words. | ||
TEXT | ||
) | ||
->background(Background::JustWaves, 0.2), | ||
'override-some-elements', | ||
]; | ||
|
||
yield 'basic with background url' => [ | ||
(new Image()) | ||
->url('https://example.com/blog/some-blog-post-url') | ||
->title('Some blog post title that is quite big and quite long') | ||
->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words') | ||
->backgroundUrl('https://www.goodfreephotos.com/albums/animals/mammals/african-bush-elephant-loxodonta-africana.jpg', 0.2), | ||
'basic-with-background-url', | ||
]; | ||
|
||
yield 'different theme with background url' => [ | ||
(new Image()) | ||
->theme(Themes::Dark) | ||
->url('https://example.com/blog/some-blog-post-url') | ||
->title('Some blog post title that is quite big and quite long') | ||
->description('Some slightly smaller but potentially much longer subtext. It could be really long so we might need to trim it completely after many words') | ||
->backgroundUrl('https://www.goodfreephotos.com/albums/animals/mammals/african-bush-elephant-loxodonta-africana.jpg', 0.2), | ||
'different-theme-with-background-url', | ||
]; | ||
} | ||
} |
Binary file added
BIN
+725 KB
...ts__/ImageTest__test_basic_image with data set basic with background url__1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added
BIN
+713 KB
...Test__test_basic_image with data set different theme with background url__1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.