-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(svg): generate unique IDs for gradients based on their properties (…
- Loading branch information
Showing
5 changed files
with
81 additions
and
1 deletion.
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
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,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BaconQrCodeTest\Integration; | ||
|
||
use BaconQrCode\Renderer\Color\Rgb; | ||
use BaconQrCode\Renderer\Image\SvgImageBackEnd; | ||
use BaconQrCode\Renderer\ImageRenderer; | ||
use BaconQrCode\Renderer\RendererStyle\EyeFill; | ||
use BaconQrCode\Renderer\RendererStyle\Fill; | ||
use BaconQrCode\Renderer\RendererStyle\Gradient; | ||
use BaconQrCode\Renderer\RendererStyle\GradientType; | ||
use BaconQrCode\Renderer\RendererStyle\RendererStyle; | ||
use BaconQrCode\Writer; | ||
use PHPUnit\Framework\Attributes\Group; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
#[Group('integration')] | ||
final class SVGRenderingTest extends TestCase | ||
{ | ||
public function testGenericQrCode(): void | ||
{ | ||
$renderer = new ImageRenderer( | ||
new RendererStyle(400), | ||
new SvgImageBackEnd() | ||
); | ||
$writer = new Writer($renderer); | ||
|
||
$svgCode = $writer->writeString('Hello World!'); | ||
$expected = file_get_contents(__DIR__.'/__snapshots__/files/SVGRenderingTest__testGenericQrCode__1.svg'); | ||
|
||
$this->assertEquals($expected, $svgCode); | ||
} | ||
|
||
// SVGRenderingTest__testQrWithGradientGeneratesDifferentIdsForDifferentGradients_horizontal | ||
//SVGRenderingTest__testQrWithGradientGeneratesDifferentIdsForDifferentGradients_vertical | ||
public function testQrWithGradientGeneratesDifferentIdsForDifferentGradients() | ||
{ | ||
$types = ['HORIZONTAL', 'VERTICAL']; | ||
foreach ($types as $type) { | ||
$gradient = new Gradient( | ||
new Rgb(0, 0, 0), | ||
new Rgb(255, 0, 0), | ||
GradientType::$type() | ||
); | ||
$renderer = new ImageRenderer( | ||
new RendererStyle( | ||
size: 400, | ||
fill: Fill::withForegroundGradient( | ||
new Rgb(255, 255, 255), | ||
$gradient, | ||
EyeFill::inherit(), | ||
EyeFill::inherit(), | ||
EyeFill::inherit() | ||
) | ||
), | ||
new SvgImageBackEnd() | ||
); | ||
$writer = new Writer($renderer); | ||
$qr = $writer->writeString('Hello World!'); | ||
$expectedFile = __DIR__ . '/__snapshots__/files/'; | ||
$expectedFile .= 'SVGRenderingTest__testQrWithGradientGeneratesDifferentIdsForDifferentGradients__'; | ||
$expectedFile .= strtolower($type) . '.svg'; | ||
$expected = file_get_contents($expectedFile); | ||
|
||
$this->assertEquals($expected, $qr); | ||
} | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
test/Integration/__snapshots__/files/SVGRenderingTest__testGenericQrCode__1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions
2
...t__testQrWithGradientGeneratesDifferentIdsForDifferentGradients__horizontal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions
2
...est__testQrWithGradientGeneratesDifferentIdsForDifferentGradients__vertical.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.