|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Class ImagetilerTest |
| 4 | + * |
| 5 | + * @filesource ImagetilerTest.php |
| 6 | + * @created 20.06.2018 |
| 7 | + * @package chillerlan\ImagetilerTest |
| 8 | + * @author smiley <[email protected]> |
| 9 | + * @copyright 2018 smiley |
| 10 | + * @license MIT |
| 11 | + */ |
| 12 | + |
| 13 | +namespace chillerlan\ImagetilerTest; |
| 14 | + |
| 15 | +use chillerlan\Imagetiler\Imagetiler; |
| 16 | +use chillerlan\Imagetiler\ImagetilerOptions; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | +use ReflectionClass, ReflectionMethod; |
| 19 | + |
| 20 | +/** |
| 21 | + */ |
| 22 | +class ImagetilerTest extends TestCase{ |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \ReflectionClass |
| 26 | + */ |
| 27 | + protected $reflection; |
| 28 | + |
| 29 | + protected function setUp(){ |
| 30 | + $this->reflection = new ReflectionClass(Imagetiler::class); |
| 31 | + } |
| 32 | + |
| 33 | + public function testGetSize(){ |
| 34 | + |
| 35 | + $max = 22; |
| 36 | + |
| 37 | + $options = new ImagetilerOptions([ |
| 38 | + 'zoom_min' => 0, |
| 39 | + 'zoom_max' => $max, |
| 40 | + 'zoom_normalize' => 4, |
| 41 | + ]); |
| 42 | + |
| 43 | + $tiler = new Imagetiler($options); |
| 44 | + |
| 45 | + for($z = 0; $z <= $max; $z++){ |
| 46 | + $v = $this->getMethod('getSize')->invokeArgs($tiler, [4096, 2048, $z]); |
| 47 | + |
| 48 | + $expected = 2 ** $z * 256; |
| 49 | + |
| 50 | + $this->assertSame($expected, $v[0]); |
| 51 | + $this->assertSame($expected/2, $v[1]); |
| 52 | + } |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @param string $method |
| 58 | + * |
| 59 | + * @return \ReflectionMethod |
| 60 | + */ |
| 61 | + protected function getMethod(string $method):ReflectionMethod { |
| 62 | + $method = $this->reflection->getMethod($method); |
| 63 | + $method->setAccessible(true); |
| 64 | + |
| 65 | + return $method; |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | +} |
0 commit comments