Skip to content

Commit

Permalink
Merge branch 'release/0.10.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
endelwar committed Dec 29, 2021
2 parents 99886a6 + 30da83b commit 0941bec
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.10.1] - 2021-12-29
### Fixed
- Refactor tests to use `onlyMethods()`

## [0.10.0] - 2021-12-29
### Changed
- Unset `--format` option in `Pdf` class which is deprecated in WeasyPrint 53 and removed in WeasyPrint 54
Expand Down
2 changes: 1 addition & 1 deletion src/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected function executeCommand(string $command): array
* Prepares the specified output.
*
* @param string $filename The output filename
* @param bool $overwrite Whether to overwrite the file if it already exist
* @param bool $overwrite Whether to overwrite the file if it already exists
*
* @throws FileAlreadyExistsException
* @throws \RuntimeException
Expand Down
4 changes: 2 additions & 2 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Pontedilana\PhpWeasyPrint\Exception\UnsupportedWeasyPrintVersionException;

/**
* Use this class to create a snapshot / thumbnail from a HTML page.
* Use this class to create a snapshot / thumbnail from an HTML page.
*
* @author Manuel Dalla Lana <manuel@pontedilana.it>
*/
Expand All @@ -28,7 +28,7 @@ protected function configure(): void
{
$this->addOptions([
// Global options
'format' => 'png', // forced to 'png', should not be override
'format' => 'png', // forced to 'png', should not be overridden
'encoding' => null,
'stylesheet' => [], //repeatable
'media-type' => null,
Expand Down
2 changes: 1 addition & 1 deletion src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Pontedilana\PhpWeasyPrint;

/**
* Use this class to transform a html/a url to a pdf.
* Use this class to transform a html/an url to a pdf.
*
* @author Manuel Dalla Lana <manuel@pontedilana.it>
*/
Expand Down
89 changes: 55 additions & 34 deletions tests/Unit/AbstractGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use PHPUnit\Framework\TestCase;
use Pontedilana\PhpWeasyPrint\AbstractGenerator;
use Psr\Log\LoggerInterface;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
use RuntimeException;
Expand Down Expand Up @@ -41,15 +40,21 @@ public function testAddOption(): void
$media->getOptions(),
'->addOption() appends the option to the existing ones'
);
}

$message = '->addOption() raises an exception when the specified option already exists';
/**
* @covers \Pontedilana\PhpWeasyPrint\AbstractGenerator::addOption
*/
public function testAddOptionException(): void
{
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

try {
$r->invokeArgs($media, ['baz', 'bat']);
$this->fail($message);
} catch (ReflectionException $e) {
$this->anything();
}
$r = new ReflectionMethod($media, 'addOption');
$r->setAccessible(true);
$r->invokeArgs($media, ['foo', 'bar']);

$this->expectException(InvalidArgumentException::class);
$r->invokeArgs($media, ['foo', 'baz']);
}

/**
Expand Down Expand Up @@ -86,15 +91,21 @@ public function testAddOptions(): void
$media->getOptions(),
'->addOptions() adds the given options to the existing ones'
);
}

$message = '->addOptions() raises an exception when one of the given options already exists';
/**
* @covers \Pontedilana\PhpWeasyPrint\AbstractGenerator::addOptions
*/
public function testAddOptionsException(): void
{
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);

try {
$r->invokeArgs($media, [['bak' => 'bam', 'bah' => 'bap', 'baz' => 'bat']]);
$this->fail($message);
} catch (ReflectionException $e) {
$this->anything();
}
$r = new ReflectionMethod($media, 'addOptions');
$r->setAccessible(true);
$r->invokeArgs($media, [['foo' => 'bar', 'baz' => 'bat']]);

$this->expectException(InvalidArgumentException::class);
$r->invokeArgs($media, [['foo' => 'baz']]);
}

/**
Expand Down Expand Up @@ -188,7 +199,7 @@ public function testSetOptions(): void
public function testGenerate(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'prepareOutput',
'getCommand',
Expand Down Expand Up @@ -264,7 +275,7 @@ public function testGenerate(): void
public function testFailingGenerate(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'prepareOutput',
'getCommand',
Expand Down Expand Up @@ -336,7 +347,7 @@ public function testFailingGenerate(): void
public function testGenerateFromHtml(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'generate',
'createTemporaryFile',
Expand Down Expand Up @@ -374,7 +385,7 @@ public function testGenerateFromHtml(): void
public function testGetOutput(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'getDefaultExtension',
'createTemporaryFile',
Expand Down Expand Up @@ -430,7 +441,7 @@ public function testGetOutput(): void
public function testGetOutputFromHtml(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'getOutput',
'createTemporaryFile',
Expand Down Expand Up @@ -503,15 +514,25 @@ public function testMergeOptions(): void
$mergedOptions,
'->mergeOptions() merges many options to the instance ones and returns the result options array'
);
}

$message = '->mergeOptions() throws an InvalidArgumentException once there is an undefined option in the given array';
/**
* @covers \Pontedilana\PhpWeasyPrint\AbstractGenerator::mergeOptions
*/
public function testMergeOptionsException(): void
{
$media = $this->getMockForAbstractClass(AbstractGenerator::class, [], '', false);
$originalOptions = ['foo' => 'bar', 'baz' => 'bat'];

try {
$r->invokeArgs($media, [['foo' => 'ban', 'bad' => 'bah']]);
$this->fail($message);
} catch (ReflectionException $e) {
$this->anything();
}
$addOptions = new ReflectionMethod($media, 'addOptions');
$addOptions->setAccessible(true);
$addOptions->invokeArgs($media, [$originalOptions]);

$r = new ReflectionMethod($media, 'mergeOptions');
$r->setAccessible(true);

$this->expectException(InvalidArgumentException::class);
$mergedOptions = $r->invokeArgs($media, [['bad' => 'ban']]);
}

/**
Expand Down Expand Up @@ -588,7 +609,7 @@ public function dataForBuildCommand(): array
public function testCheckOutput(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'fileExists',
'filesize',
Expand Down Expand Up @@ -628,7 +649,7 @@ public function testCheckOutput(): void
public function testCheckOutputWhenTheFileDoesNotExist(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'fileExists',
'filesize',
Expand Down Expand Up @@ -662,7 +683,7 @@ public function testCheckOutputWhenTheFileDoesNotExist(): void
public function testCheckOutputWhenTheFileIsEmpty(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'fileExists',
'filesize',
Expand Down Expand Up @@ -703,7 +724,7 @@ public function testCheckOutputWhenTheFileIsEmpty(): void
public function testCheckProcessStatus(): void
{
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods(['configure'])
->onlyMethods(['configure'])
->disableOriginalConstructor()
->getMock()
;
Expand Down Expand Up @@ -737,7 +758,7 @@ public function testItThrowsTheProperExceptionWhenFileExistsAndNotOverwritting()
{
$this->expectException(\Pontedilana\PhpWeasyPrint\Exception\FileAlreadyExistsException::class);
$media = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'fileExists',
'isFile',
Expand Down Expand Up @@ -768,7 +789,7 @@ public function testItThrowsTheProperExceptionWhenFileExistsAndNotOverwritting()
public function testCleanupEmptyTemporaryFiles(): void
{
$generator = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'unlink',
])
Expand Down Expand Up @@ -800,7 +821,7 @@ public function testCleanupEmptyTemporaryFiles(): void
public function testCleanupTemporaryFiles(): void
{
$generator = $this->getMockBuilder(AbstractGenerator::class)
->setMethods([
->onlyMethods([
'configure',
'unlink',
])
Expand Down

0 comments on commit 0941bec

Please sign in to comment.