object = $this->getMockBuilder(GisGeometry::class) ->onlyMethods([ 'prepareRowAsSvg', 'prepareRowAsPng', 'prepareRowAsPdf', 'prepareRowAsOl', 'getExtent', 'generateWkt', 'getCoordinateParams', 'getType', ]) ->getMock(); } /** * tests getCoordinatesExtent method * * @param string $pointSet Point set * @param Extent $expected Expected output extent */ #[DataProvider('providerForTestGetCoordinatesExtent')] public function testGetCoordinatesExtent(string $pointSet, Extent $expected): void { $extent = (new ReflectionMethod(GisGeometry::class, 'getCoordinatesExtent')) ->invokeArgs($this->object, [$pointSet]); self::assertEquals($expected, $extent); } /** * data provider for testGetCoordinatesExtent * * @return array */ public static function providerForTestGetCoordinatesExtent(): array { return [ [ '12 35,48 75,69 23,25 45,14 53,35 78', new Extent(minX: 12, minY: 23, maxX: 69, maxY: 78), ], [ '12 35,48 75,69 23,25 45,14 53,35 78', new Extent(minX:12, minY: 23, maxX: 69, maxY: 78), ], ]; } /** * tests parseWktAndSrid method * * @param string $value Geometry data * @param array $output Expected output */ #[DataProvider('providerForTestParseWktAndSrid')] public function testParseWktAndSrid(string $value, array $output): void { self::assertSame( $output, (new ReflectionMethod(GisGeometry::class, 'parseWktAndSrid')) ->invokeArgs($this->object, [$value]), ); } /** * data provider for testParseWktAndSrid * * @return array}> */ public static function providerForTestParseWktAndSrid(): array { return [ [ "'MULTIPOINT(125 50,156 25,178 43,175 80)',125", ['srid' => 125, 'wkt' => 'MULTIPOINT(125 50,156 25,178 43,175 80)'], ], [ 'MULTIPOINT(125 50,156 25,178 43,175 80)', ['srid' => 0, 'wkt' => 'MULTIPOINT(125 50,156 25,178 43,175 80)'], ], ['foo', ['srid' => 0, 'wkt' => '']], ]; } /** * tests extractPointsInternal method * * @param string $pointSet String of comma separated points * @param ScaleData|null $scaleData Data related to scaling * @param bool $linear If true, as a 1D array, else as a 2D array * @param int[][]|int[] $output Expected output */ #[DataProvider('providerForTestExtractPointsInternal')] public function testExtractPointsInternal( string $pointSet, ScaleData|null $scaleData, bool $linear, array $output, ): void { $points = (new ReflectionMethod(GisGeometry::class, 'extractPointsInternal')) ->invokeArgs($this->object, [$pointSet, $scaleData, $linear]); self::assertEquals($output, $points); } /** * data provider for testExtractPointsInternal * * @return array */ public static function providerForTestExtractPointsInternal(): array { return [ // with no scale data ['12 35,48 75,69 23', null, false, [[12, 35], [48, 75], [69, 23]]], // with scale data [ '12 35,48 75,69 23', new ScaleData(scale: 2.0, offsetX: -10.0, offsetY: -210.0), false, [[14, 140], [86, 60], [128, 164]], ], // linear output ['12 35,48 75,69 23', null, true, [12, 35, 48, 75, 69, 23]], // if a single part of a coordinate is empty ['12 35,48 75,69 ', null, false, [[12, 35], [48, 75], [0, 0]]], ]; } }