|
19 | 19 | class CircleParserTest extends TestCase {
|
20 | 20 |
|
21 | 21 | public function testGivenCoordinateAndRadius_parserReturnsCircle() {
|
22 |
| - $parser = new CircleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) ); |
23 |
| - |
24 |
| - $circle = $parser->parse( '57.421,23.90625:32684.605182' ); |
25 |
| - |
26 |
| - $this->assertInstanceOf( Circle::class, $circle ); |
| 22 | + $circle = $this->newCircleParser()->parse( '57.421,23.90625:32684.605182' ); |
27 | 23 |
|
28 | 24 | $expectedLatLong = new LatLongValue( 57.421, 23.90625 );
|
29 | 25 | $this->assertTrue( $expectedLatLong->equals( $circle->getCircleCentre() ) );
|
30 | 26 |
|
31 | 27 | $this->assertSame( 32684.605182, $circle->getCircleRadius() );
|
32 | 28 | }
|
33 | 29 |
|
34 |
| - public function testGivenTitleAndText_circleHasProvidedMetaData() { |
35 |
| - $parser = new CircleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) ); |
36 |
| - |
37 |
| - $circle = $parser->parse( '57.421,23.90625:32684.605182~title~text' ); |
| 30 | + private function newCircleParser(): CircleParser { |
| 31 | + return new CircleParser( new CoordinateFriendlyGeocoder( new NullGeocoder() ) ); |
| 32 | + } |
38 | 33 |
|
39 |
| - $this->assertInstanceOf( Circle::class, $circle ); |
| 34 | + public function testGivenTitleAndText_circleHasProvidedMetaData() { |
| 35 | + $circle = $this->newCircleParser()->parse( '57.421,23.90625:32684.605182~title~text' ); |
40 | 36 |
|
41 | 37 | $this->assertSame( 'title', $circle->getTitle() );
|
42 | 38 | $this->assertSame( 'text', $circle->getText() );
|
43 | 39 | }
|
44 | 40 |
|
| 41 | + public function testGivenNoRadius_radiusIsOne() { |
| 42 | + $circle = $this->newCircleParser()->parse( '42,42' ); |
| 43 | + |
| 44 | + $this->assertSame( 1.0, $circle->getCircleRadius() ); |
| 45 | + } |
| 46 | + |
| 47 | + public function testGivenNegative_radiusIsOne() { |
| 48 | + $circle = $this->newCircleParser()->parse( '42,42:-5' ); |
| 49 | + |
| 50 | + $this->assertSame( 1.0, $circle->getCircleRadius() ); |
| 51 | + } |
| 52 | + |
| 53 | + public function testGivenInvalid_radiusIsOne() { |
| 54 | + $circle = $this->newCircleParser()->parse( '42,42:foo' ); |
| 55 | + |
| 56 | + $this->assertSame( 1.0, $circle->getCircleRadius() ); |
| 57 | + } |
| 58 | + |
45 | 59 | }
|
0 commit comments