diff --git a/src/Manager.php b/src/Manager.php index 4dd4f40c..c0a49d93 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -178,7 +178,8 @@ public function parseIncludes($includes) foreach ($includes as $include) { list($includeName, $allModifiersStr) = array_pad(explode(':', $include, 2), 2, ''); - list($allModifiersStr, $subRelations) = array_pad(explode('.', $allModifiersStr, 2), 2, null); + $a = $allModifiersStr ? explode('.', $allModifiersStr, 2) : ['']; + list($allModifiersStr, $subRelations) = array_pad($a, 2, null); // Trim it down to a cool level of recursion $includeName = $this->trimToAcceptableRecursionLevel($includeName); diff --git a/src/ParamBag.php b/src/ParamBag.php index 1810ac3d..a482f931 100644 --- a/src/ParamBag.php +++ b/src/ParamBag.php @@ -105,8 +105,7 @@ public function __unset($key) * * @return bool */ - #[\ReturnTypeWillChange] - public function offsetExists($key) + public function offsetExists($key): bool { return $this->__isset($key); } @@ -134,8 +133,7 @@ public function offsetGet($key) * * @return void */ - #[\ReturnTypeWillChange] - public function offsetSet($key, $value) + public function offsetSet($key, $value): void { throw new \LogicException('Modifying parameters is not permitted'); } @@ -149,8 +147,7 @@ public function offsetSet($key, $value) * * @return void */ - #[\ReturnTypeWillChange] - public function offsetUnset($key) + public function offsetUnset($key): void { throw new \LogicException('Modifying parameters is not permitted'); } @@ -160,8 +157,7 @@ public function offsetUnset($key) * * @return \ArrayIterator */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): \ArrayIterator { return new \ArrayIterator($this->params); } diff --git a/src/Scope.php b/src/Scope.php index f79d9f39..9340dffb 100644 --- a/src/Scope.php +++ b/src/Scope.php @@ -295,8 +295,7 @@ public function toArray() /** * @return mixed */ - #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): array { return $this->toArray(); } diff --git a/test/ManagerTest.php b/test/ManagerTest.php index 5f30b913..5cd99d60 100755 --- a/test/ManagerTest.php +++ b/test/ManagerTest.php @@ -1,5 +1,6 @@ assertInstanceOf(get_class($manager), $manager->parseIncludes(['foo'])); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The parseIncludes() method expects a string or an array. NULL given - */ public function testInvalidParseInclude() { + $this->expectExceptionObject(new InvalidArgumentException('The parseIncludes() method expects a string or an array. NULL given')); + $manager = new Manager(); $manager->parseIncludes(null); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The parseIncludes() method expects a string or an array. integer given - */ public function testIceTParseInclude() { + $this->expectExceptionObject(new InvalidArgumentException('The parseIncludes() method expects a string or an array. integer given')); + $manager = new Manager(); $manager->parseIncludes(99); @@ -99,23 +96,19 @@ public function testParseExcludeSelfie() $this->assertInstanceOf(get_class($manager), $manager->parseExcludes(['foo'])); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The parseExcludes() method expects a string or an array. NULL given - */ public function testInvalidParseExclude() { + $this->expectExceptionObject(new InvalidArgumentException('The parseExcludes() method expects a string or an array. NULL given')); + $manager = new Manager(); $manager->parseExcludes(null); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The parseExcludes() method expects a string or an array. integer given - */ public function testIceTParseExclude() { + $this->expectExceptionObject(new InvalidArgumentException('The parseExcludes() method expects a string or an array. integer given')); + $manager = new Manager(); $manager->parseExcludes(99); diff --git a/test/ParamBagTest.php b/test/ParamBagTest.php index d63f1fdd..a27c75a4 100644 --- a/test/ParamBagTest.php +++ b/test/ParamBagTest.php @@ -1,6 +1,7 @@ assertNull($params['totallymadeup']); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Modifying parameters is not permitted - */ public function testArrayAccessSetFails() { + $this->expectExceptionObject(new LogicException('Modifying parameters is not permitted')); + $params = new ParamBag(['foo' => 'bar']); $params['foo'] = 'someothervalue'; } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Modifying parameters is not permitted - */ public function testArrayAccessUnsetFails() { + $this->expectExceptionObject(new LogicException('Modifying parameters is not permitted')); + $params = new ParamBag(['foo' => 'bar']); unset($params['foo']); @@ -64,23 +61,19 @@ public function testObjectAccess() $this->assertTrue(isset($params->foo)); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Modifying parameters is not permitted - */ public function testObjectAccessSetFails() { + $this->expectExceptionObject(new LogicException('Modifying parameters is not permitted')); + $params = new ParamBag(['foo' => 'bar']); $params->foo = 'someothervalue'; } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Modifying parameters is not permitted - */ public function testObjectAccessUnsetFails() { + $this->expectExceptionObject(new LogicException('Modifying parameters is not permitted')); + $params = new ParamBag(['foo' => 'bar']); unset($params->foo); diff --git a/test/ScopeTest.php b/test/ScopeTest.php index a1e812c8..7282094e 100755 --- a/test/ScopeTest.php +++ b/test/ScopeTest.php @@ -1,5 +1,6 @@ assertTrue($scope->isExcluded('baz.bart')); } - /** - * @expectedException \InvalidArgumentException - */ public function testScopeRequiresConcreteImplementation() { - $manager = new Manager(); + $this->expectException(InvalidArgumentException::class); + + $manager = new Manager(); $manager->parseIncludes('book'); $resource = Mockery::mock('League\Fractal\Resource\ResourceAbstract', [ @@ -382,11 +382,11 @@ public function testRunAppropriateTransformerWithCollection() /** * @covers \League\Fractal\Scope::executeResourceTransformers - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage Argument $resource should be an instance of League\Fractal\Resource\Item or League\Fractal\Resource\Collection */ public function testCreateDataWithClassFuckKnows() { + $this->expectExceptionObject(new InvalidArgumentException('Argument $resource should be an instance of League\Fractal\Resource\Item or League\Fractal\Resource\Collection')); + $manager = new Manager(); $transformer = Mockery::mock('League\Fractal\TransformerAbstract')->makePartial(); diff --git a/test/Serializer/JsonApiSerializerTest.php b/test/Serializer/JsonApiSerializerTest.php index f656be11..b3663ff3 100644 --- a/test/Serializer/JsonApiSerializerTest.php +++ b/test/Serializer/JsonApiSerializerTest.php @@ -1,5 +1,6 @@ assertSame($expectedJson, $scope->toJson()); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage JSON API resource objects MUST have a valid id - */ public function testExceptionThrownIfResourceHasNoId() { - $bookData = [ + $this->expectExceptionObject(new InvalidArgumentException('JSON API resource objects MUST have a valid id')); + + $bookData = [ 'title' => 'Foo', 'year' => '1991', ]; diff --git a/test/TransformerAbstractTest.php b/test/TransformerAbstractTest.php index bf211fec..cfe8f6aa 100755 --- a/test/TransformerAbstractTest.php +++ b/test/TransformerAbstractTest.php @@ -1,5 +1,7 @@ expectException(BadMethodCallException::class); + $transformer = m::mock('League\Fractal\TransformerAbstract')->makePartial(); $manager = new Manager(); @@ -116,10 +119,11 @@ public function testProcessEmbeddedResourcesInvalidAvailableEmbed() /** * @covers \League\Fractal\TransformerAbstract::processIncludedResources * @covers \League\Fractal\TransformerAbstract::callIncludeMethod - * @expectedException \BadMethodCallException */ public function testProcessEmbeddedResourcesInvalidDefaultEmbed() { + $this->expectException(BadMethodCallException::class); + $transformer = m::mock('League\Fractal\TransformerAbstract')->makePartial(); $manager = new Manager(); @@ -228,11 +232,11 @@ public function testProcessIncludedAvailableResourcesEmptyEmbed() /** * @covers \League\Fractal\TransformerAbstract::callIncludeMethod - * @expectedException \Exception - * @expectedExceptionMessage Invalid return value from League\Fractal\TransformerAbstract::includeBook(). */ public function testCallEmbedMethodReturnsCrap() { + $this->expectExceptionObject(new Exception('Invalid return value from League\Fractal\TransformerAbstract::includeBook().')); + $manager = new Manager(); $manager->parseIncludes('book'); $transformer = m::mock('League\Fractal\TransformerAbstract[transform]');