-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test suite #5
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
409fef7
Add integration tests
svenluijten c050355
Clean up integrationt test
svenluijten 7188b28
Add phpunit files to .gitignore
svenluijten dad87eb
Update README with testing instructions
svenluijten 4ebed80
Add return typehint to data provider
svenluijten 9a733c9
Add unit test for layouts
svenluijten 1cf6ca2
Update .github/workflows/run-tests.yml
svenluijten c0e785c
Add missing word in testing instructions in README
svenluijten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: ${{ matrix.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,6 @@ | ||
.DS_Store | ||
/vendor | ||
/composer.lock | ||
/node_modules | ||
/phpunit.xml | ||
/.phpunit.cache |
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
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
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,78 @@ | ||
<?php | ||
|
||
namespace Tests\Integration; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use SimonHamp\TheOg\Background; | ||
use SimonHamp\TheOg\Image; | ||
use SimonHamp\TheOg\Themes\Themes; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
|
||
class ImageTest extends IntegrationTestCase | ||
{ | ||
use MatchesSnapshots; | ||
|
||
#[DataProvider('snapshotImages')] | ||
public function test_basic_image(Image $image, string $name): void | ||
{ | ||
$path = self::TESTCASE_DIRECTORY.'/'.$name.'.png'; | ||
|
||
$image->save($path); | ||
|
||
$this->assertMatchesImageSnapshot($path); | ||
} | ||
|
||
public static function snapshotImages(): iterable | ||
{ | ||
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', | ||
]; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Tests\Integration; | ||
|
||
use FilesystemIterator; | ||
use PHPUnit\Framework\TestCase; | ||
use RecursiveDirectoryIterator; | ||
use RecursiveIteratorIterator; | ||
|
||
class IntegrationTestCase extends TestCase | ||
{ | ||
protected const TESTCASE_DIRECTORY = __DIR__.'/../resources/testcases'; | ||
|
||
protected function tearDown(): void | ||
{ | ||
TestCase::tearDown(); | ||
|
||
$files = new RecursiveIteratorIterator( | ||
new RecursiveDirectoryIterator(self::TESTCASE_DIRECTORY, FilesystemIterator::SKIP_DOTS), | ||
RecursiveIteratorIterator::CHILD_FIRST, | ||
); | ||
|
||
foreach ($files as $file) { | ||
unlink($file->getRealPath()); | ||
} | ||
} | ||
} |
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 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,38 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Layout; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use SimonHamp\TheOg\BorderPosition; | ||
use SimonHamp\TheOg\Layout\Layouts\GitHubBasic; | ||
use SimonHamp\TheOg\Layout\Layouts\Standard; | ||
use Tests\Unit\UnitTestcase; | ||
|
||
class LayoutsTest extends UnitTestCase | ||
{ | ||
#[DataProvider('provideLayouts')] | ||
public function test_layouts( | ||
string $layoutClass, | ||
BorderPosition $borderPosition, | ||
int $borderWidth, | ||
int $boxWidth, | ||
int $boxHeight, | ||
int $mountX, | ||
int $mountY | ||
): void { | ||
$layout = new $layoutClass(); | ||
|
||
self::assertEquals($borderPosition, $layout->getBorderPosition()); | ||
self::assertEquals($borderWidth, $layout->getBorderWidth()); | ||
self::assertEquals($boxWidth, $layout->mountArea()->box->width()); | ||
self::assertEquals($boxHeight, $layout->mountArea()->box->height()); | ||
self::assertEquals($mountX, $layout->mountArea()->position->x()); | ||
self::assertEquals($mountY, $layout->mountArea()->position->y()); | ||
} | ||
|
||
public static function provideLayouts(): iterable | ||
{ | ||
yield 'standard' => [Standard::class, BorderPosition::All, 25, 1070, 500, 65, 65]; | ||
yield 'github basic' => [GitHubBasic::class, BorderPosition::Bottom, 25, 1190, 550, 45, 45]; | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class UnitTestcase extends TestCase | ||
{ | ||
// | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should note that I haven't been able to test this workflow. So it might require some tweaking after it's been merged into
main
.