1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-17 20:28:21 +01:00
intervention_image/tests/Unit/ResolutionTest.php
Oliver Vogel dcc95b8299
PHPUnit 10 Migration (#1302)
* Bump PHPUnit dependencies

* Set return type of base TestCase methods

From the [PHPUnit 8 release notes][1], the `TestCase` methods below now declare a `void` return type:

- `setUpBeforeClass()`
- `setUp()`
- `assertPreConditions()`
- `assertPostConditions()`
- `tearDown()`
- `tearDownAfterClass()`
- `onNotSuccessfulTest()`

[1]: https://phpunit.de/announcements/phpunit-8.html

* Ignore PHPUnit cache folder

* Adopt PHP attributes in test classes

* Declare data providers as `static`

* Add return types to test methods

* Define test classes as `final`

* Migrate phpunit.xml to phpunit 10

* Correct phpunit attribute class name

* Rename base test class

* Restructure test folders

* Fix test image paths

* Only set rules for php files in .editorconfig

* Remove php unit flag in local test env

---------

Co-authored-by: Shift <shift@laravelshift.com>
2024-02-28 16:16:23 +01:00

59 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Intervention\Image\Tests\Unit;
use PHPUnit\Framework\Attributes\CoversClass;
use Intervention\Image\Resolution;
use Intervention\Image\Tests\BaseTestCase;
#[CoversClass(\Intervention\Image\Resolution::class)]
final class ResolutionTest extends BaseTestCase
{
public function testConstructor(): void
{
$resolution = new Resolution(1, 2);
$this->assertInstanceOf(Resolution::class, $resolution);
}
public function testXY(): void
{
$resolution = new Resolution(1.2, 3.4);
$this->assertEquals(1.2, $resolution->x());
$this->assertEquals(3.4, $resolution->y());
}
public function testPerInch(): void
{
$resolution = new Resolution(300, 150); // per inch
$this->assertEquals(300, $resolution->perInch()->x());
$this->assertEquals(150, $resolution->perInch()->y());
$resolution = new Resolution(300, 150, Resolution::PER_CM);
$this->assertEquals(118.11024, round($resolution->perInch()->x(), 5));
$this->assertEquals(59.05512, round($resolution->perInch()->y(), 5));
}
public function testPerCm(): void
{
$resolution = new Resolution(118.11024, 59.05512); // per inch
$this->assertEquals(300, round($resolution->perCm()->x()));
$this->assertEquals(150, round($resolution->perCm()->y()));
$resolution = new Resolution(300, 150, Resolution::PER_CM);
$this->assertEquals(300, $resolution->perCm()->x());
$this->assertEquals(150, $resolution->perCm()->y());
}
public function testToString(): void
{
$resolution = new Resolution(300, 150, Resolution::PER_CM);
$this->assertEquals('300.00 x 150.00 dpcm', $resolution->toString());
$resolution = new Resolution(300, 150, Resolution::PER_INCH);
$this->assertEquals('300.00 x 150.00 dpi', $resolution->toString());
$this->assertEquals('300.00 x 150.00 dpi', (string) $resolution);
}
}