Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reliq committed May 22, 2024
1 parent 76e9d4d commit defe803
Show file tree
Hide file tree
Showing 10 changed files with 83 additions and 249 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
max-parallel: 10
matrix:
laravel-version: ['^11.0', '^11.1']
laravel-version: ['^11.1']
preference: ['stable']
php-version: ['8.2', '8.3']
name: Laravel ${{ matrix.laravel-version }} (${{ matrix.preference }}) on PHP ${{ matrix.php-version }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"require": {
"php": "^8.2",
"illuminate/support": "^11.1",
"intervention/image": "^3.5",
"intervention/image": "^3.6",
"reliqarts/laravel-common": "^8.0",
"ext-json": "*",
"ext-fileinfo": "*",
Expand Down
3 changes: 0 additions & 3 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
</report>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory suffix=".php">tests</directory>
</testsuite>
<testsuite name="Integration">
<directory suffix="Test.php">tests/Feature</directory>
</testsuite>
Expand Down
4 changes: 2 additions & 2 deletions src/Demand/Resize.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function __construct(
mixed $height,
private readonly mixed $maintainAspectRatio = true,
private readonly mixed $allowUpSizing = null,
private readonly bool $returnObject = false
private readonly mixed $returnObject = false
) {
parent::__construct($request, $guidedImage, $width, $height);
}
Expand All @@ -35,6 +35,6 @@ public function allowUpSizing(): bool

public function returnObject(): bool
{
return $this->returnObject;
return ! $this->isValueConsideredNull($this->returnObject);
}
}
52 changes: 5 additions & 47 deletions tests/Unit/Demand/DummyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,21 @@
namespace ReliqArts\GuidedImage\Tests\Unit\Demand;

use Exception;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use ReliqArts\GuidedImage\Demand\Dummy;

/**
* Class DummyTest.
*
* @coversDefaultClass \ReliqArts\GuidedImage\Demand\Dummy
*
* @internal
*/
#[CoversClass(Dummy::class)]
final class DummyTest extends TestCase
{
/**
* @dataProvider colorDataProvider
*
* @covers ::__construct
* @covers ::getColor
* @covers ::isValueConsideredNull
*
* @param mixed $color
*
* @throws Exception
*/
public function testGetColor($color, string $expectedResult): void
#[DataProvider('colorDataProvider')]
public function testGetColor(mixed $color, string $expectedResult): void
{
$demand = new Dummy(
self::DIMENSION,
Expand All @@ -38,27 +30,6 @@ public function testGetColor($color, string $expectedResult): void
self::assertSame($expectedResult, $demand->getColor());
}

/**
* @dataProvider fillDataProvider
*
* @covers ::__construct
* @covers ::fill
* @covers ::isValueConsideredNull
*
* @param mixed $fill
*/
public function testFill($fill, ?string $expectedResult): void
{
$demand = new Dummy(
self::DIMENSION,
self::DIMENSION,
null,
$fill
);

self::assertSame($expectedResult, $demand->fill());
}

public static function colorDataProvider(): array
{
return [
Expand All @@ -71,17 +42,4 @@ public static function colorDataProvider(): array
[null, Dummy::DEFAULT_COLOR],
];
}

public static function fillDataProvider(): array
{
return [
['0f0', '0f0'],
['n', null],
['_', null],
['false', null],
['null', null],
[false, null],
[null, null],
];
}
}
53 changes: 25 additions & 28 deletions tests/Unit/Demand/ExistingImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,51 @@

namespace ReliqArts\GuidedImage\Tests\Unit\Demand;

use PHPUnit\Framework\MockObject\MockObject;
use Exception;
use PHPUnit\Framework\Attributes\CoversClass;
use ReliqArts\GuidedImage\Demand\ExistingImage;
use ReliqArts\GuidedImage\Demand\Thumbnail;

/**
* Class ExistingImageTest.
*
* @coversDefaultClass \ReliqArts\GuidedImage\Demand\ExistingImage
*
* @internal
*/
#[CoversClass(ExistingImage::class)]
final class ExistingImageTest extends TestCase
{
/**
* @covers ::__construct
* @covers ::getRequest
* @throws Exception
*/
public function testGetRequest(): void
{
$demand = $this->getExistingImageDemand(self::DIMENSION, self::DIMENSION, null);

self::assertSame($this->request->reveal(), $demand->getRequest());
self::assertSame(
$this->request->reveal(),
$this->getExistingImageDemand()->getRequest()
);
}

/**
* @covers ::__construct
* @covers ::getGuidedImage
* @throws Exception
*/
public function testGetGuidedImage(): void
{
$demand = $this->getExistingImageDemand(self::DIMENSION, self::DIMENSION, null);

self::assertSame($this->guidedImage->reveal(), $demand->getGuidedImage());
self::assertSame(
$this->guidedImage->reveal(),
$this->getExistingImageDemand()
->getGuidedImage()
);
}

/**
* @param $width
* @param $height
* @param null $returnObject
*
* @return ExistingImage|MockObject
* @throws Exception
*/
private function getExistingImageDemand(
$width,
$height,
$returnObject = null
): MockObject {
return $this->getMockBuilder(ExistingImage::class)
->setConstructorArgs([$this->request->reveal(), $this->guidedImage->reveal(), $width, $height, $returnObject])
->getMockForAbstractClass();
private function getExistingImageDemand(): ExistingImage
{
return new Thumbnail(
$this->request->reveal(),
$this->guidedImage->reveal(),
'crop',
self::DIMENSION,
self::DIMENSION
);
}
}
73 changes: 14 additions & 59 deletions tests/Unit/Demand/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,41 @@

namespace ReliqArts\GuidedImage\Tests\Unit\Demand;

use PHPUnit\Framework\MockObject\MockObject;
use Exception;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use ReliqArts\GuidedImage\Demand\Dummy;
use ReliqArts\GuidedImage\Demand\Image;

/**
* Class ImageTest.
*
* @coversDefaultClass \ReliqArts\GuidedImage\Demand\Image
*
* @internal
*/
#[CoversClass(Image::class)]
final class ImageTest extends TestCase
{
/**
* @dataProvider widthAndHeightDataProvider
* @covers ::__construct
* @covers ::getWidth
* @covers ::isValueConsideredNull
*
* @param mixed $width
* @throws Exception
*/
#[DataProvider('widthAndHeightDataProvider')]
public function testGetWidth($width, ?int $expectedResult): void
{
$demand = $this->getImageDemand($width, self::DIMENSION, null);
$demand = $this->getImageDemand($width, self::DIMENSION);

self::assertSame($expectedResult, $demand->getWidth());
}

/**
* @dataProvider widthAndHeightDataProvider
* @covers ::__construct
* @covers ::getHeight
* @covers ::isValueConsideredNull
*
* @param mixed $height
* @throws Exception
*/
#[DataProvider('widthAndHeightDataProvider')]
public function testGetHeight($height, ?int $expectedResult): void
{
$demand = $this->getImageDemand(self::DIMENSION, $height, null);
$demand = $this->getImageDemand(self::DIMENSION, $height);

self::assertSame($expectedResult, $demand->getHeight());
}

/**
* @dataProvider imageFlagDataProvider
* @covers ::__construct
* @covers ::isValueConsideredNull
* @covers ::returnObject
*
* @param mixed $returnObject
*/
public function testReturnObject($returnObject, bool $expectedResult): void
{
$demand = $this->getImageDemand(self::DIMENSION, self::DIMENSION, $returnObject);

self::assertSame($expectedResult, $demand->returnObject());
}

public function widthAndHeightDataProvider(): array
public static function widthAndHeightDataProvider(): array
{
return [
[200, 200],
Expand All @@ -75,30 +52,8 @@ public function widthAndHeightDataProvider(): array
];
}

public function imageFlagDataProvider(): array
{
return [
[true, true],
['n', false],
['_', false],
['false', false],
['null', false],
[false, false],
[null, false],
];
}

/**
* @param $width
* @param $height
* @param null $returnObject
*
* @return Image|MockObject
*/
private function getImageDemand($width, $height, $returnObject = null): MockObject
private function getImageDemand($width, $height): Image
{
return $this->getMockBuilder(Image::class)
->setConstructorArgs([$width, $height, $returnObject])
->getMockForAbstractClass();
return new Dummy($width, $height);
}
}
Loading

0 comments on commit defe803

Please sign in to comment.