Chris@0: expectException(\InvalidArgumentException::class); Chris@14: } Chris@14: else { Chris@14: $this->setExpectedException(\InvalidArgumentException::class); Chris@14: } Chris@0: $rect = new Rectangle(-40, 20); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests wrong rectangle height. Chris@0: * Chris@0: * @covers ::rotate Chris@0: */ Chris@0: public function testWrongHeight() { Chris@14: if (method_exists($this, 'expectException')) { Chris@14: $this->expectException(\InvalidArgumentException::class); Chris@14: } Chris@14: else { Chris@14: $this->setExpectedException(\InvalidArgumentException::class); Chris@14: } Chris@0: $rect = new Rectangle(40, 0); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests getting rectangle dimensions after a rotation operation. Chris@0: * Chris@0: * @param int $width Chris@0: * The width of the rectangle. Chris@0: * @param int $height Chris@0: * The height of the rectangle. Chris@0: * @param float $angle Chris@0: * The angle for rotation. Chris@0: * @param int $exp_width Chris@0: * The expected width of the rotated rectangle. Chris@0: * @param int $exp_height Chris@0: * The expected height of the rotated rectangle. Chris@0: * Chris@0: * @covers ::rotate Chris@0: * @covers ::getBoundingWidth Chris@0: * @covers ::getBoundingHeight Chris@0: * Chris@0: * @dataProvider providerPhp55RotateDimensions Chris@0: */ Chris@0: public function testRotateDimensions($width, $height, $angle, $exp_width, $exp_height) { Chris@0: $rect = new Rectangle($width, $height); Chris@0: $rect->rotate($angle); Chris@0: $this->assertEquals($exp_width, $rect->getBoundingWidth()); Chris@0: $this->assertEquals($exp_height, $rect->getBoundingHeight()); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Provides data for image dimension rotation tests. Chris@0: * Chris@0: * This dataset sample was generated by running on PHP 5.5 the function below Chris@0: * - first, for all integer rotation angles (-360 to 360) on a rectangle Chris@0: * 40x20; Chris@0: * - second, for 500 random float rotation angle in the range -360 to 360 on Chris@0: * a rectangle 40x20; Chris@0: * - third, on 1000 rectangles of random WxH rotated to a random float angle Chris@0: * in the range -360 to 360 Chris@0: * - fourth, on 2000 rectangles of random WxH rotated to a random integer Chris@0: * angle multiple of 30 degrees in the range -360 to 360 (which is the most Chris@0: * tricky case). Chris@0: * Using the GD toolkit operations gives us true data coming from the GD Chris@0: * library that can be used to match against the Rectangle class under test. Chris@0: * @code Chris@0: * protected function rotateResults($width, $height, $angle, &$new_width, &$new_height) { Chris@0: * $image = \Drupal::service('image.factory')->get(NULL, 'gd'); Chris@0: * $image->createNew($width, $height); Chris@0: * $old_res = $image->getToolkit()->getResource(); Chris@0: * $image->rotate($angle); Chris@0: * $new_width = $image->getWidth(); Chris@0: * $new_height = $image->getHeight(); Chris@0: * if (is_resource($old_res)) { Chris@0: * imagedestroy($old_res); Chris@0: * } Chris@0: * } Chris@0: * @endcode Chris@0: * Chris@0: * @return array[] Chris@0: * A simple array of simple arrays, each having the following elements: Chris@0: * - original image width Chris@0: * - original image height Chris@0: * - rotation angle in degrees Chris@0: * - expected image width after rotation Chris@0: * - expected image height after rotation Chris@0: * Chris@0: * @see testRotateDimensions() Chris@0: */ Chris@0: public function providerPhp55RotateDimensions() { Chris@0: // The dataset is stored in a .json file because it is very large and causes Chris@0: // problems for PHPCS. Chris@0: return json_decode(file_get_contents(__DIR__ . '/fixtures/RectangleTest.json')); Chris@0: } Chris@0: Chris@0: }