Skip to content

Commit 5c5d2c9

Browse files
committed
Fixed exception check for PhpUnit 4.8
(cherry picked from commit abb6d2a)
1 parent 4a3c524 commit 5c5d2c9

File tree

7 files changed

+28
-10
lines changed

7 files changed

+28
-10
lines changed

tests/Integration/SpatialTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ protected function assertDatabaseHas($table, array $data, $connection = null)
6565
}
6666
}
6767

68+
protected function assertException($exceptionName) {
69+
if(method_exists(parent::class, 'expectException')) {
70+
parent::expectException($exceptionName);
71+
}
72+
else {
73+
$this->setExpectedException($exceptionName);
74+
}
75+
}
76+
6877
private function onMigrations(\Closure $closure, $reverse_sort = false)
6978
{
7079
$fileSystem = new Filesystem();
@@ -87,7 +96,7 @@ public function testSpatialFieldsNotDefinedException()
8796
$geo->geometry = new Point(1, 2);
8897
$geo->save();
8998

90-
$this->expectException(\Grimzy\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException::class);
99+
$this->assertException(\Grimzy\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException::class);
91100
NoSpatialFieldsModel::all();
92101
}
93102

tests/Unit/BaseTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ public function tearDown()
66
{
77
Mockery::close();
88
}
9+
10+
protected function assertException($exceptionName) {
11+
if(method_exists(parent::class, 'expectException')) {
12+
parent::expectException($exceptionName);
13+
}
14+
else {
15+
$this->setExpectedException($exceptionName);
16+
}
17+
}
918
}

tests/Unit/Types/GeometryCollectionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testJsonSerialize()
4141
}
4242

4343
public function testInvalidArgumentExceptionNotArrayGeometries() {
44-
$this->expectException(InvalidArgumentException::class);
44+
$this->assertException(InvalidArgumentException::class);
4545
$geometrycollection = new GeometryCollection([
4646
$this->getPoint(),
4747
1

tests/Unit/Types/GeometryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testGetWKTClass()
7474
GeometryCollection::class,
7575
Geometry::getWKTClass('GEOMETRYCOLLECTION(POINT(2 3),LINESTRING(2 3,3 4))')
7676
);
77-
$this->expectException(UnknownWKTTypeException::class);
77+
$this->assertException(UnknownWKTTypeException::class);
7878
Geometry::getWKTClass('TRIANGLE((0 0, 0 9, 9 0, 0 0))');
7979
}
8080

tests/Unit/Types/MultiLineStringTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public function testJsonSerialize()
4343
}
4444

4545
public function testInvalidArgumentExceptionAtLeastOneEntry() {
46-
$this->expectException(InvalidArgumentException::class);
46+
$this->assertException(InvalidArgumentException::class);
4747
$multilinestring = new MultiLineString([]);
4848
}
4949

5050
public function testInvalidArgumentExceptionNotArrayOfLineString() {
51-
$this->expectException(InvalidArgumentException::class);
51+
$this->assertException(InvalidArgumentException::class);
5252
$multilinestring = new MultiLineString([
5353
new LineString([new Point(0, 0), new Point(1, 1)]),
5454
new Point(0,1)

tests/Unit/Types/MultiPointTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testArrayAccess() {
6565
$multipoint[100] = $point100;
6666
$this->assertEquals($point100, $multipoint[100]);
6767

68-
$this->expectException(InvalidArgumentException::class);
68+
$this->assertException(InvalidArgumentException::class);
6969
$multipoint[] = 1;
7070

7171
}
@@ -108,7 +108,7 @@ public function testInsertPoint() {
108108
$this->assertEquals($point2, $multipoint->getPoints()[1]);
109109
$this->assertEquals($point3, $multipoint->getPoints()[2]);
110110

111-
$this->expectException(InvalidArgumentException::class);
111+
$this->assertException(InvalidArgumentException::class);
112112
$multipoint->insertPoint(100, new Point(100,100));
113113
}
114114

@@ -123,12 +123,12 @@ public function testJsonSerialize()
123123
}
124124

125125
public function testInvalidArgumentExceptionAtLeastOneEntry() {
126-
$this->expectException(InvalidArgumentException::class);
126+
$this->assertException(InvalidArgumentException::class);
127127
$multipoint = new MultiPoint([]);
128128
}
129129

130130
public function testInvalidArgumentExceptionNotArrayOfLineString() {
131-
$this->expectException(InvalidArgumentException::class);
131+
$this->assertException(InvalidArgumentException::class);
132132
$multipoint = new MultiPoint([
133133
new Point(0, 0),
134134
1

tests/Unit/Types/MultiPolygonTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testJsonSerialize()
5353
}
5454

5555
public function testInvalidArgumentExceptionNotArrayOfLineString() {
56-
$this->expectException(InvalidArgumentException::class);
56+
$this->assertException(InvalidArgumentException::class);
5757
$multipolygon = new MultiPolygon([
5858
$this->getPolygon1(),
5959
$this->getLineString1()

0 commit comments

Comments
 (0)